<?php
$startTime = microtime(true);
$pid = getmypid();
echo "ID процесса : ", $pid, "\n";
$file = fopen('pid.txt', 'w+');
$message = "pid: [$pid] time: " . date("d.m.Y H:i:s");
fwrite($file, $message);
fclose($file);
$DBHost = "localhost";
$DBLogin = "test";
$DBPassword = "test";
$DBName = "test";
mysql_connect($DBHost, $DBLogin, $DBPassword);
mysql_select_db($DBName);
mysql_set_charset('utf8');
$limit = 20000;
/** Удаляем b_iblock_element_property */
/**
* проперти
* @var [type]
*/
$temp = mysql_query("SELECT prop.IBLOCK_ELEMENT_ID FROM `b_iblock_element_property` as `prop`
LEFT JOIN `b_iblock_element` AS `element`
ON prop.IBLOCK_ELEMENT_ID = element.ID
WHERE element.ID IS NULL
GROUP BY IBLOCK_ELEMENT_ID
limit $limit
");
$count_prop = 0;
for ($i = 0; $i < $limit; $i++) {
$id_prop = mysql_fetch_object($temp)->IBLOCK_ELEMENT_ID;
if ($id_prop) {
mysql_query("DELETE FROM `b_iblock_element_property` WHERE `IBLOCK_ELEMENT_ID` = $id_prop");
$count_prop++;
}
}
/** Удаляем b_search_content */
/**
* content
* @var [type]
*/
$temp2 = mysql_query("SELECT s.ID FROM `b_search_content` as s
LEFT JOIN `b_iblock_element` as `e`
ON s.ITEM_ID = e.ID
WHERE e.ID IS NULL
AND s.PARAM1 IN ('catalog','offers')
limit $limit
");
$count_search_content = 0;
for ($i = 0; $i < $limit; $i++) {
$id_search = mysql_fetch_object($temp2)->ID;
if ($id_search) {
mysql_query("DELETE FROM `b_search_content` WHERE `ID` = $id_search");
$count_search_content++;
}
}
/** Удаляем b_catalog_price */
/**
* b_catalog_price
* @var [type]
*/
$temp3 = mysql_query("SELECT cp.ID FROM `b_catalog_price` as cp
LEFT JOIN `b_iblock_element` as `e`
ON cp.PRODUCT_ID = e.ID
WHERE e.ID IS NULL
limit $limit
");
$count_catalog_price = 0;
for ($i = 0; $i < $limit; $i++) {
$id_cp = mysql_fetch_object($temp3)->ID;
if ($id_cp) {
mysql_query("DELETE FROM `b_catalog_price` WHERE `ID` = $id_cp");
$count_catalog_price++;
}
}
/** Удаляем b_catalog_product */
/**
* b_catalog_product
* @var [type]
*/
$temp4 = mysql_query("SELECT cp.ID FROM `b_catalog_product` as cp
LEFT JOIN `b_iblock_element` as `e`
ON cp.ID = e.ID
WHERE e.ID IS NULL
limit $limit
");
$count_catalog_product = 0;
for ($i = 0; $i < $limit; $i++) {
$id_cpp = mysql_fetch_object($temp4)->ID;
if ($id_cpp) {
mysql_query("DELETE FROM `b_catalog_product` WHERE `ID` = $id_cpp");
$count_catalog_product++;
}
}
/** Удаляем b_search_content_title */
/**
* b_search_content_title
* @var [type]
*/
$temp5 = mysql_query("SELECT b.SEARCH_CONTENT_ID FROM `b_search_content_title` as b
LEFT JOIN `b_iblock_element` as `e`
ON b.SEARCH_CONTENT_ID = e.ID
WHERE e.ID IS NULL
limit $limit
");
$count_catalog_content_title = 0;
for ($i = 0; $i < $limit; $i++) {
$id_ct = mysql_fetch_object($temp5)->SEARCH_CONTENT_ID;
if ($id_ct) {
mysql_query("DELETE FROM `b_search_content_title` WHERE `SEARCH_CONTENT_ID` = $id_ct");
$count_catalog_content_title++;
}
}
/** Удаляем b_iblock_5_index */
/**
* b_iblock_5_index
* @var [type]
*/
$temp6 = mysql_query("SELECT b.ELEMENT_ID FROM `b_iblock_5_index` as b
LEFT JOIN `b_iblock_element` as `e`
ON b.ELEMENT_ID = e.ID
WHERE e.ID IS NULL
limit $limit
");
$count_5_index = 0;
for ($i = 0; $i < $limit; $i++) {
$id_5_index = mysql_fetch_object($temp6)->ELEMENT_ID;
if ($id_5_index) {
mysql_query("DELETE FROM `b_iblock_5_index` WHERE `ELEMENT_ID` = $id_5_index");
$count_5_index++;
}
}
/** Удаляем b_search_content_site */
/**
* b_search_content_site
* @var [type]
*/
$temp7 = mysql_query("SELECT b.SEARCH_CONTENT_ID FROM `b_search_content_site` as b
LEFT JOIN `b_iblock_element` as `e`
ON b.SEARCH_CONTENT_ID = e.ID
WHERE e.ID IS NULL
limit $limit
");
$count_content_site = 0;
for ($i = 0; $i < $limit; $i++) {
$id_content_s = mysql_fetch_object($temp7)->SEARCH_CONTENT_ID;
if ($id_content_s) {
mysql_query("DELETE FROM `b_search_content_site` WHERE `SEARCH_CONTENT_ID` = $id_content_s");
$count_content_site++;
}
}
/** Удаляем b_search_content_text */
/**
* b_search_content_text
* @var [type]
*/
$temp8 = mysql_query("SELECT b.SEARCH_CONTENT_ID FROM `b_search_content_text` as b
LEFT JOIN `b_iblock_element` as `e`
ON b.SEARCH_CONTENT_ID = e.ID
WHERE e.ID IS NULL
limit $limit
");
$count_content_text = 0;
for ($i = 0; $i < $limit; $i++) {
$id_content_text = mysql_fetch_object($temp8)->SEARCH_CONTENT_ID;
if ($id_content_text) {
mysql_query("DELETE FROM `b_search_content_text` WHERE `SEARCH_CONTENT_ID` = $id_content_text");
$count_content_text++;
}
}
echo "Удалено $count_prop property\n";
echo "Удалено $count_search_content content\n";
echo "Удалено $count_catalog_price price\n";
echo "Удалено $count_catalog_product product\n";
echo "Удалено $count_catalog_content_title title\n";
echo "Удалено $count_5_index iblock 5\n";
echo "Удалено $count_content_site content_site\n";
echo "Удалено $count_content_text content_text\n";
$endTime = microtime(true);
echo "Время выполнения скрипта: " . ($endTime - $startTime) . " Сек.\n"; //вывод результата