diff --git a/local/ilsa_update.php b/local/ilsa_update.php
index f69a52a..995200b 100644
--- a/local/ilsa_update.php
+++ b/local/ilsa_update.php
@@ -51,6 +51,11 @@ $bitrix_enabled_modifications = [];
$bitrix_existed_cars = [];
$bitrix_enabled_cars = [];
+$bitrix_hidden_brands = [];
+$bitrix_hidden_models = [];
+$bitrix_hidden_modifications = [];
+$bitrix_hidden_cars = [];
+
$bitrix_existed_bodies = [];
$bitrix_enabled_bodies = [];
@@ -68,6 +73,10 @@ while($all_brands_search_ob = $all_brands_search_res->GetNextElement())
{
array_push( $bitrix_enabled_brands, $brand_search['PROPERTIES']['UID']['VALUE'] );
}
+ else
+ {
+ array_push( $bitrix_hidden_brands, $brand_search['PROPERTIES']['UID']['VALUE'] );
+ }
}
$all_models_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, "ACTIVE" => "Y" ], false, false, [] );
@@ -81,6 +90,10 @@ while($all_models_search_ob = $all_models_search_res->GetNextElement())
{
array_push( $bitrix_enabled_models, $model_search['PROPERTIES']['UID']['VALUE'] );
}
+ else
+ {
+ array_push( $bitrix_hidden_models, $model_search['PROPERTIES']['UID']['VALUE'] );
+ }
}
$all_modifications_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODIFICATIONS, "ACTIVE" => "Y" ], false, false, [] );
@@ -93,6 +106,10 @@ while($all_modifications_search_ob = $all_modifications_search_res->GetNextEleme
{
array_push( $bitrix_existed_modifications, $modification_search['CODE'] );
}
+ else
+ {
+ array_push( $bitrix_hidden_modifications, $modification_search['CODE'] );
+ }
}
$all_cars_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, ], false, false, [] );
@@ -106,6 +123,11 @@ while($all_cars_search_ob = $all_cars_search_res->GetNextElement())
{
array_push( $bitrix_enabled_cars, $car_search['PROPERTIES']['UID']['VALUE'] );
}
+ else
+ {
+ array_push( $bitrix_hidden_cars, $car_search['PROPERTIES']['UID']['VALUE'] );
+ }
+
}
//наполняем массивы имеющихся и активных типов кузова
@@ -162,6 +184,21 @@ $api_models = [];
$api_modifications = [];
$api_cars = [];
+$new_brands = [];
+$new_models = [];
+$new_modifications = [];
+$new_cars = [];
+
+$hide_brands = [];
+$hide_models = [];
+$hide_modifications = [];
+$hide_cars = [];
+
+$repost_brands = [];
+$repost_models = [];
+$repost_modifications = [];
+$repost_cars = [];
+
//prepare brands list from API
foreach($json AS $entry)
{
@@ -331,6 +368,10 @@ $bitrix_modifications_codes = [];
foreach($brands_and_models AS $brand_uid => $brand)
{
//print $uid." - ".$brand['name']."\n";
+ if(in_array($brand_uid, $bitrix_hidden_brands))
+ {
+ array_push($repost_brands, $brand['name']);
+ }
//if($c < 2)
//{
@@ -378,6 +419,8 @@ foreach($brands_and_models AS $brand_uid => $brand)
"ACTIVE" => "Y",
];
+ array_push($new_brands, $brand['name']);
+
if($new_brand_id = $brand_element->Add($brand_payload))
{
$bitrix_brands[$brand_uid] = $new_brand_id;
@@ -402,6 +445,8 @@ foreach($brands_and_models AS $brand_uid => $brand)
function set_brand_activity($brand_uid, $active = "N")
{
+ global $hide_brands;
+
$brand_id = null;
$brand_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_BRANDS, "PROPERTY_UID" => $brand_uid ], false, false, [] );
@@ -415,11 +460,14 @@ function set_brand_activity($brand_uid, $active = "N")
{
$update_element = new CIBlockElement;
$update_result = $update_element->Update($brand_id, [ "ACTIVE" => $active, ]);
+ array_push($hide_brands, $brand_search['NAME']);
}
}
function set_model_activity($model_uid, $active = "N")
{
+ global $hide_models;
+
$model_id = null;
$model_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, "PROPERTY_UID" => $model_uid ], false, false, [] );
@@ -433,11 +481,14 @@ function set_model_activity($model_uid, $active = "N")
{
$update_element = new CIBlockElement;
$update_result = $update_element->Update($model_id, [ "ACTIVE" => $active, ]);
+ array_push($hide_models, $model_search['NAME']);
}
}
function set_modification_activity($modification_code, $active = "N")
{
+ global $hide_modifications;
+
$modification_id = null;
$modification_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODIFICATIONS, "CODE" => $modification_code ], false, false, [] );
@@ -451,11 +502,14 @@ function set_modification_activity($modification_code, $active = "N")
{
$update_element = new CIBlockElement;
$update_result = $update_element->Update($modification_id, [ "ACTIVE" => $active, ]);
+ array_push($hide_modifications, $modification_search['NAME']);
}
}
function set_car_activity($car_uid, $active = "N")
{
+ global $hide_cars;
+
//print "SET ACTIVE ".$car_uid." | ".$active."\n";
$car_id = null;
$car_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, "PROPERTY_UID" => $car_uid ], false, false, [] );
@@ -470,6 +524,11 @@ function set_car_activity($car_uid, $active = "N")
{
$update_element = new CIBlockElement;
$update_result = $update_element->Update($car_id, [ "ACTIVE" => $active, ]);
+
+ if($active == "N")
+ {
+ array_push($hide_cars, $car_search['NAME']);
+ }
}
}
@@ -511,10 +570,22 @@ function set_engine_fuel_activity($engine_fuel_name, $active = "N")
function models_check($bitrix_models, $bitrix_modifications, $bitrix_modifications_codes, $brand_uid, $brand)
{
+ global $new_models;
+ global $new_modifications;
+ global $bitrix_hidden_models;
+ global $bitrix_hidden_modifications;
+ global $repost_models;
+ global $repost_modifications;
+
foreach($brand['models'] AS $model_uid => $model)
{
$model_name = $model['name'];
+ if(in_array($model_uid, $bitrix_hidden_models))
+ {
+ array_push($repost_models, $model_name);
+ }
+
$model_existed = null;
$model_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, "PROPERTY_UID" => $model_uid ], false, ["nPageSize" => 1], [] );
while($model_search_ob = $model_search_res->GetNextElement())
@@ -555,6 +626,8 @@ function models_check($bitrix_models, $bitrix_modifications, $bitrix_modificatio
"ACTIVE" => "Y",
];
+ array_push($new_models, $model['name']);
+
if($new_model_id = $model_element->Add($model_payload))
{
$bitrix_models[$model_uid] = $new_model_id;
@@ -571,6 +644,11 @@ function models_check($bitrix_models, $bitrix_modifications, $bitrix_modificatio
print "MOD ".$modification."\n";
$modification_existed = null;
+ if(in_array($modification, $bitrix_hidden_modifications))
+ {
+ array_push($repost_modifications, $modification);
+ }
+
$NAME = $brand['name']." ".$model_name." ".$modification;
$CODE = CUtil::translit( $NAME, "ru", [ "max_len" => 255, "change_case" => "L", "replace_space" => "-", "replace_other" => "-", ] );
@@ -592,10 +670,12 @@ function models_check($bitrix_models, $bitrix_modifications, $bitrix_modificatio
$modification_element = new CIBlockElement;
$modification_payload = [ "IBLOCK_SECTION_ID" => false, "IBLOCK_ID" => IBLOCK_ID_MODIFICATIONS, "PROPERTY_VALUES" => [ "MODEL_UID" => $model_uid, "TITLE" => $modification ], "NAME" => $NAME, "CODE" => $CODE, "ACTIVE" => "Y", ];
+
if($new_modification_id = $modification_element->Add($modification_payload))
{
$bitrix_modifications[md5($brand_uid.$model_uid.$modification)] = $new_modification_id;
array_push($bitrix_modifications_codes, $CODE);
+ array_push($new_modifications, $NAME);
}
else
{
@@ -633,17 +713,25 @@ $car_codes = [];
$c = 0;
foreach($json AS $car)
{
- if(!in_array($car['uid'], $bitrix_existed_cars))
+ $name = "".$car['brand']['name']." ".$car['model']['name']." ".$car['modification']."";
+
+ if(in_array($car['uid'], $bitrix_hidden_cars))
{
- $c++;
+ array_push($repost_cars, $name);
+ }
+ else
+ {
+ if(!in_array($car['uid'], $bitrix_existed_cars))
+ {
+ $c++;
+ array_push($new_cars, $name);
+ }
}
//обновляем список ТС в битриксе
$modification_content = file_get_contents(API_HOST."/site/Vehicle/GetCatalog?id=". $car['uid'] ."", false, stream_context_create($arrContextOptions));
$modification_json = json_decode($modification_content, true);
- $name = "".$car['brand']['name']." ".$car['model']['name']." ".$car['modification']."";
-
$title = $name." ".$car['modificationYear']."";
$code = CUtil::translit( str_replace([""", " ", "+"], ['"', "-", "-plus-"], $title), "ru", [ "max_len" => 255, "change_case" => "L", "replace_space" => "-", "replace_other" => "-", "safe_chars" => "-" ] );
@@ -755,27 +843,6 @@ foreach($car_codes AS $cc => $count)
$traceback_message = "Отчет:\n\n";
-$trace = "Новых ТС: ".$c;
-$traceback_message .= $trace."\n";
-print "\n\n".$trace."\n\n";
-
-//print "bitrix_existed_cars = ".count($bitrix_existed_cars)."\n";
-//print "json_new_cars = ".count($json_new_cars)."\n";
-
-$h = 0;
-foreach($bitrix_enabled_cars AS $enabled_car_uid)
-{
- if(!in_array($enabled_car_uid, $json_new_cars))
- {
- $h++;
- set_car_activity($enabled_car_uid, "N");
- }
-}
-
-$trace = "Снято с публикации ТС: ".$h;
-$traceback_message .= $trace."\n";
-print "\n\n".$trace."\n\n";
-
//print "bitrix_existed_brands\n";
$c = 0;
foreach($bitrix_existed_brands AS $k => $b)
@@ -798,19 +865,61 @@ foreach($bitrix_brands AS $k => $b)
}
}
-$md = 0;
-foreach($bitrix_enabled_modifications AS $enabled_modifications_code)
+
+//BRANDS
+
+$trace = "Новых марок: ".count($new_brands)."\n";
+foreach($new_brands AS $v)
{
- if(!in_array($enabled_modifications_code, $bitrix_modifications_codes))
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+
+$trace = "Переопубликовано марок: ".count($repost_brands)."\n";
+foreach($repost_brands AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace;
+
+$b = 0;
+foreach($bitrix_enabled_brands AS $enabled_brand_uid)
+{
+ if($bitrix_brands[$enabled_brand_uid] !== null)
+ {}
+ else
{
- set_modification_activity($enabled_modifications_code, "N");
- $md++;
+ if(!in_array($enabled_brand_uid, $api_brands))
+ {
+ set_brand_activity($enabled_brand_uid, "N");
+ $b++;
+ }
}
}
-$trace = "Снято с публикации модификаций: ".$md;
+$trace = "Снято с публикации марок: ".count($hide_brands)."\n";
+foreach($hide_brands AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n\n";
+
+
+//MODELS
+
+$trace = "Новых моделей: ".count($new_models)."\n";
+foreach($new_models AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+
+$trace = "Переопубликовано моделей: ".count($repost_models)."\n";
+foreach($repost_models AS $v)
+{
+ $trace .= $v."\n";
+}
$traceback_message .= $trace."\n";
-print "\n\n".$trace."\n\n";
$m = 0;
foreach($bitrix_enabled_models AS $enabled_model_uid)
@@ -827,25 +936,88 @@ foreach($bitrix_enabled_models AS $enabled_model_uid)
}
}
-$trace = "Снято с публикации моделей: ".$m;
-$traceback_message .= $trace."\n";
-print "\n\n".$trace."\n\n";
-
-$b = 0;
-foreach($bitrix_enabled_brands AS $enabled_brand_uid)
+$trace = "Снято с публикации моделей: ".count($hide_models)."\n";
+foreach($hide_models AS $v)
{
- if($bitrix_brands[$enabled_brand_uid] !== null)
- {}
- else
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n\n";
+
+
+//MODIFICATIONS
+
+$trace = "Новых модификаций: ".count($new_modifications)."\n";
+foreach($new_modifications AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace;
+
+$trace = "Переопубликовано модификаций: ".count($repost_modifications)."\n";
+foreach($repost_modifications AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace;
+
+$md = 0;
+foreach($bitrix_enabled_modifications AS $enabled_modifications_code)
+{
+ if(!in_array($enabled_modifications_code, $bitrix_modifications_codes))
{
- if(!in_array($enabled_brand_uid, $api_brands))
- {
- set_brand_activity($enabled_brand_uid, "N");
- $b++;
- }
+ set_modification_activity($enabled_modifications_code, "N");
+ $md++;
}
}
+$trace = "Снято с публикации модификаций: ".count($hide_modifications);
+foreach($hide_modifications AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n\n";
+
+
+//CARS
+
+$trace = "Новых ТС: ".count($new_cars)."\n";
+foreach($new_cars AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+
+$trace = "Переопубликовано ТС: ".count($repost_cars)."\n";
+foreach($repost_cars AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+
+//print "bitrix_existed_cars = ".count($bitrix_existed_cars)."\n";
+//print "json_new_cars = ".count($json_new_cars)."\n";
+
+$h = 0;
+foreach($bitrix_enabled_cars AS $enabled_car_uid)
+{
+ if(!in_array($enabled_car_uid, $json_new_cars))
+ {
+ $h++;
+ set_car_activity($enabled_car_uid, "N");
+ }
+}
+
+$trace = "Снято с публикации ТС: ".count($hide_cars)."\n";
+foreach($hide_cars AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+//print "\n\n".$trace."\n\n";
+
+print $traceback_message;
+
+
//кузов
foreach($api_bodies AS $api_body)
{
@@ -890,6 +1062,7 @@ foreach($bitrix_existed_bodies AS $bitrix_body)
}
}
+
//топливо
foreach($api_engine_fuels AS $api_engine_fuel)
{
@@ -933,11 +1106,6 @@ foreach($bitrix_existed_engine_fuels AS $bitrix_engine_fuel)
}
}
-$trace = "Снято с публикации марок: ".$b;
-$traceback_message .= $trace."\n";
-print "\n\n".$trace."\n\n";
-
-
/* search reindex start -------------------------------------------------------------*/
$reindex_handler = false;
diff --git a/local/ilsa_update_dev.php b/local/ilsa_update_dev.php
new file mode 100644
index 0000000..e193125
--- /dev/null
+++ b/local/ilsa_update_dev.php
@@ -0,0 +1,2595 @@
+
+//$_SERVER["DOCUMENT_ROOT"] = __DIR__;
+define('STOP_STATISTICS', true);
+define('NO_KEEP_STATISTIC', 'Y');
+define('NO_AGENT_STATISTIC', 'Y');
+define('DisableEventsCheck', true);
+define('BX_SECURITY_SHOW_MESSAGE', true);
+define('NOT_CHECK_PERMISSIONS', true);
+
+$_SERVER['DOCUMENT_ROOT'] = dirname(__DIR__, 1);
+require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');
+CModule::IncludeModule('iblock');
+CModule::IncludeModule('search');
+use Bitrix\Main;
+use Bitrix\Main\IO;
+use Bitrix\Main\SiteTable;
+use Bitrix\Main\Localization\Loc;
+use Bitrix\Seo\RobotsFile;
+use Bitrix\Seo\SitemapIblock;
+use Bitrix\Seo\SitemapTable;
+use Bitrix\Seo\SitemapIndex;
+use Bitrix\Seo\SitemapRuntime;
+use Bitrix\Seo\SitemapRuntimeTable;
+
+Main\Loader::includeModule('seo');
+
+$arrContextOptions = [
+ "ssl" => [
+ "verify_peer"=>false,
+ "verify_peer_name"=>false,
+ ],
+];
+
+ob_get_clean();
+error_reporting(E_ERROR);
+
+$current_representation = [];
+
+$bitrix_existed_brands = [];
+$bitrix_enabled_brands = [];
+$bitrix_hidden_brands = [];
+
+$bitrix_existed_models = [];
+$bitrix_enabled_models = [];
+$bitrix_hidden_models = [];
+
+$bitrix_existed_modifications = [];
+$bitrix_enabled_modifications = [];
+$bitrix_hidden_modifications = [];
+
+$api_data_titles = [];
+$api_data = [];
+
+$api_brands = [];
+$api_models = [];
+$api_modifications = [];
+$api_cars = [];
+
+$api_bodies = [];
+$api_engine_fuels = [];
+
+$bitrix_existed_cars = [];
+$bitrix_enabled_cars = [];
+$bitrix_hidden_cars = [];
+
+$bitrix_existed_bodies = [];
+$bitrix_enabled_bodies = [];
+
+$bitrix_existed_engine_fuels = [];
+$bitrix_enabled_engine_fuels = [];
+
+$new_brands = [];
+$new_models = [];
+$new_modifications = [];
+$new_cars = [];
+
+$hide_brands = [];
+$hide_models = [];
+$hide_modifications = [];
+$hide_cars = [];
+
+$repost_brands = [];
+$repost_models = [];
+$repost_modifications = [];
+$repost_cars = [];
+
+function elasticIndex($index, $payload)
+{
+ define("ELASTIC_USERNAME", "elastic");
+ define("ELASTIC_PASSWORD", "DFbC769Ln0weJL33mtMXGbpJOK4RCJfx");
+
+ $uid = implode("_", array_merge([ "date" => date("Ymd") ], array_intersect_key($payload, array_flip(['brand', 'model', 'modification']))));
+ print "uid = ".$uid." | ".$payload['status']."\n";
+ $id = md5($uid);
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, "https://els.quickcode.ru/".$index."/_doc/".$id."/");
+ curl_setopt($ch, CURLOPT_USERPWD, ELASTIC_USERNAME . ":" . ELASTIC_PASSWORD);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 2000);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ //curl_setopt($ch, CURLOPT_FORBID_REUSE, 0);
+ //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
+
+ $response = curl_exec($ch);
+ curl_close($ch);
+ print $response."\n\n";
+}
+
+$all_brands_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_BRANDS, ], false, false, [] );
+while($all_brands_search_ob = $all_brands_search_res->GetNextElement())
+{
+ $brand_search = $all_brands_search_ob->GetFields();
+ $brand_search['PROPERTIES'] = $all_brands_search_ob->GetProperties();
+
+ array_push( $bitrix_existed_brands, $brand_search['PROPERTIES']['UID']['VALUE'] );
+ $current_representation[ $brand_search['PROPERTIES']['UID']['VALUE'] ] = [
+ "NAME" => $brand_search['NAME'],
+ "STATUS" => "exists",
+ "MODELS" => [],
+ ];
+
+ if($brand_search['ACTIVE'] == "Y")
+ {
+ array_push( $bitrix_enabled_brands, $brand_search['PROPERTIES']['UID']['VALUE'] );
+ }
+ else
+ {
+ array_push( $bitrix_hidden_brands, $brand_search['PROPERTIES']['UID']['VALUE'] );
+ }
+}
+
+$all_models_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, ], false, false, [] );
+while($all_models_search_ob = $all_models_search_res->GetNextElement())
+{
+ $model_search = $all_models_search_ob->GetFields();
+ $model_search['PROPERTIES'] = $all_models_search_ob->GetProperties();
+
+ $current_representation[ $model_search['PROPERTIES']['BRAND_UID']['VALUE'] ][ 'MODELS' ][ $model_search['PROPERTIES']['UID']['VALUE'] ] = [
+ "NAME" => $model_search['NAME'],
+ "STATUS" => "exists",
+ "MODIFICATIONS" => [],
+ ];
+
+ array_push( $bitrix_existed_models, $model_search['PROPERTIES']['UID']['VALUE'] );
+ if($model_search['ACTIVE'] == "Y")
+ {
+ array_push( $bitrix_enabled_models, $model_search['PROPERTIES']['UID']['VALUE'] );
+ }
+ else
+ {
+ array_push( $bitrix_hidden_models, $model_search['PROPERTIES']['UID']['VALUE'] );
+ }
+}
+
+function get_brand_by_model_uid($model_uid)
+{
+ global $current_representation;
+
+ foreach($current_representation AS $brand_entry_uid => $brand_entry)
+ {
+ foreach($brand_entry['MODELS'] AS $model_entry_uid => $model_entry)
+ {
+ if($model_uid === $model_entry_uid)
+ {
+ return $brand_entry_uid;
+ }
+ }
+ }
+
+// print "NULL - ".$model_uid."\n";
+
+ return null;
+}
+
+function get_brand_model_by_modification_uid($modification_code)
+{
+ global $current_representation;
+ print "get_brand_model_by_modification_uid [ ".$modification_code." ]\n";
+
+ foreach($current_representation AS $brand_entry_uid => $brand_entry)
+ {
+ foreach($brand_entry['MODELS'] AS $model_entry_uid => $model_entry)
+ {
+ foreach($model_entry['MODIFICATIONS'] AS $modification_entry_code => $modification_entry)
+ {
+ if($modification_code === $modification_entry_code)
+ {
+ return [ "BRAND_UID" => $brand_entry_uid, "MODEL_UID" => $model_entry_uid, ];
+ }
+ }
+ }
+ }
+
+ return null;
+}
+
+$all_modifications_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODIFICATIONS, ], false, false, [] );
+while($all_modifications_search_ob = $all_modifications_search_res->GetNextElement())
+{
+ $modification_search = $all_modifications_search_ob->GetFields();
+ $modification_search['PROPERTIES'] = $all_modifications_search_ob->GetProperties();
+
+ $brand_uid = get_brand_by_model_uid($modification_search['PROPERTIES']['MODEL_UID']['VALUE']);
+
+ $current_representation[ $brand_uid ][ 'MODELS' ][ $modification_search['PROPERTIES']['MODEL_UID']['VALUE'] ][ 'MODIFICATIONS' ][ $modification_search['CODE'] ] = [
+ "NAME" => $modification_search['NAME'],
+ "STATUS" => "exists",
+ ];
+
+ array_push( $bitrix_existed_modifications, $modification_search['CODE'] );
+ if($modification_search['ACTIVE'] == "Y")
+ {
+ array_push( $bitrix_enabled_modifications, $modification_search['CODE'] );
+ }
+ else
+ {
+ array_push( $bitrix_hidden_modifications, $modification_search['CODE'] );
+ }
+}
+
+$all_cars_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, ], false, false, [] );
+while($all_cars_search_ob = $all_cars_search_res->GetNextElement())
+{
+ $car_search = $all_cars_search_ob->GetFields();
+ $car_search['PROPERTIES'] = $all_cars_search_ob->GetProperties();
+
+ array_push( $bitrix_existed_cars, $car_search['PROPERTIES']['UID']['VALUE'] );
+ if($car_search['ACTIVE'] == "Y")
+ {
+ array_push( $bitrix_enabled_cars, $car_search['PROPERTIES']['UID']['VALUE'] );
+ }
+ else
+ {
+ array_push( $bitrix_hidden_cars, $car_search['PROPERTIES']['UID']['VALUE'] );
+ }
+
+}
+
+//наполняем массивы имеющихся и активных типов кузова
+$all_bodies_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_BODIES, ], false, false, [] );
+while($all_bodies_search_ob = $all_bodies_search_res->GetNextElement())
+{
+ $body_search = $all_bodies_search_ob->GetFields();
+
+ array_push( $bitrix_existed_bodies, $body_search['NAME'] );
+ if($body_search['ACTIVE'] == "Y")
+ {
+ array_push( $bitrix_enabled_bodies, $body_search['NAME'] );
+ }
+}
+
+//наполняем массивы имеющихся и активных типов двигателя
+$all_engine_fuels_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_ENGINE_FUELS, ], false, false, [] );
+while($all_engine_fuels_search_ob = $all_engine_fuels_search_res->GetNextElement())
+{
+ $engine_fuel_search = $all_engine_fuels_search_ob->GetFields();
+
+ array_push( $bitrix_existed_engine_fuels, $engine_fuel_search['NAME'] );
+ if($engine_fuel_search['ACTIVE'] == "Y")
+ {
+ array_push( $bitrix_enabled_engine_fuels, $engine_fuel_search['NAME'] );
+ }
+}
+
+print "bitrix_existed_brands = ".count($bitrix_existed_brands)."\n";
+print "bitrix_existed_models = ".count($bitrix_existed_models)."\n";
+print "bitrix_existed_modifications = ".count($bitrix_existed_modifications)."\n";
+print "bitrix_existed_cars = ".count($bitrix_existed_cars)."\n";
+
+$api_modifications_url = API_HOST."/site/Vehicle/GetModifications";
+$content = file_get_contents($api_modifications_url, false, stream_context_create($arrContextOptions));
+print $api_modifications_url."\n\n";
+
+file_put_contents("./api_modifications.json", $content);
+
+print "downloaded JSON in api_modifications.json\n";
+
+$json = json_decode($content, true);
+$brands_and_models = [];
+
+//print "---------------\n\n";
+//print_r();
+//print "---------------\n\n";
+
+$c = 0;
+
+print "processing JSON\n";
+//prepare brands list from API
+foreach($json AS $entry)
+{
+ if(!isset($api_data[ $entry['brand']['id'] ]))
+ {
+ $api_data[ $entry['brand']['id'] ] = [
+ "models" => []
+ ];
+ }
+
+ if(!isset($api_data_titles[ $entry['brand']['name'] ]))
+ {
+ $api_data_titles[ $entry['brand']['name'] ] = [
+ "models" => []
+ ];
+ }
+
+ if(!in_array($entry['brand']['id'], $api_brands))
+ {
+ array_push($api_brands, $entry['brand']['id']);
+ }
+}
+
+//prepare models list from API
+foreach($json AS $entry)
+{
+ if(!isset($api_data[ $entry['brand']['id'] ]['models'][ $entry['model']['id'] ]))
+ {
+ $api_data[ $entry['brand']['id'] ]['models'][ $entry['model']['id'] ] = [
+ "modifications" => []
+ ];
+ }
+
+ if(!isset($api_data_titles[ $entry['brand']['name'] ]['models'][ $entry['model']['name'] ]))
+ {
+ $api_data_titles[ $entry['brand']['name'] ]['models'][ $entry['model']['name'] ] = [
+ "modifications" => []
+ ];
+ }
+
+ if(!in_array($entry['model']['id'], $api_models))
+ {
+ array_push($api_models, $entry['model']['id']);
+ }
+}
+
+//prepare modifications list from API
+foreach($json AS $entry)
+{
+ if(!isset($api_data[ $entry['brand']['id'] ]['models'][ $entry['model']['id'] ]['modifications'][ $entry['modification'] ]))
+ {
+ $api_data[ $entry['brand']['id'] ]['models'][ $entry['model']['id'] ]['modifications'][ $entry['modification'] ] = [
+ "cars" => []
+ ];
+ }
+
+ if(!isset($api_data_titles[ $entry['brand']['name'] ]['models'][ $entry['model']['name'] ]['modifications'][ $entry['modification'] ]))
+ {
+ $api_data_titles[ $entry['brand']['name'] ]['models'][ $entry['model']['name'] ]['modifications'][ $entry['modification'] ] = [
+ "cars" => []
+ ];
+ }
+
+ if(!in_array($entry['modification'], $api_modifications))
+ {
+ array_push($api_modifications, $entry['modification']);
+ }
+}
+
+//prepare cars list from API
+foreach($json AS $entry)
+{
+ if(!isset($api_data[ $entry['brand']['id'] ]['models'][ $entry['model']['id'] ]['modifications'][ $entry['modification'] ]['cars'][ $entry['uid'] ]))
+ {
+ array_push($api_data[ $entry['brand']['id'] ]['models'][ $entry['model']['id'] ]['modifications'][ $entry['modification'] ]['cars'], $entry['uid']);
+ }
+
+ if(!isset($api_data_titles[ $entry['brand']['name'] ]['models'][ $entry['model']['name'] ]['modifications'][ $entry['modification'] ]['cars'][ $entry['uid'] ]))
+ {
+ array_push($api_data_titles[ $entry['brand']['name'] ]['models'][ $entry['model']['name'] ]['modifications'][ $entry['modification'] ]['cars'], $entry['uid']);
+ }
+
+ if(!in_array($entry['uid'], $api_cars))
+ {
+ array_push($api_cars, $entry['uid']);
+ }
+}
+
+ksort($api_data_titles);
+
+foreach($api_data_titles AS $k => $v)
+{
+ $models = $v['models'];
+ ksort($models);
+
+ foreach($models AS $kk => $vv)
+ {
+ $modifications = $vv['modifications'];
+ ksort($modifications);
+ $models[$kk]['modifications'] = $modifications;
+ }
+
+ $api_data_titles[$k]['models'] = $models;
+}
+
+file_put_contents("./api_data_titles.json", json_encode($api_data_titles));
+
+//print_r($bitrix_existed_models);
+foreach($bitrix_existed_models AS $existed_model)
+{
+ //print $existed_model." ?\n";
+ if(!in_array($existed_model, $api_models))
+ {
+ print "HIDE MODEL ".$existed_model."\n";
+ }
+}
+
+////print_r($api_data);
+////die();
+
+foreach($json AS $entry)
+{
+ if(!isset($brands_and_models[ $entry['brand']['id'] ]))
+ {
+ $brands_and_models[ $entry['brand']['id'] ] = [
+ "name" => $entry['brand']['name'],
+ "models" => [
+ $entry['model']['id'] => [
+ "name" => $entry['model']['name'],
+ "modifications" => [ $entry['modification'] ],
+ ]
+ ],
+ ];
+ }
+ else
+ {
+ if(!isset($brands_and_models[ $entry['brand']['id'] ][ 'models' ][ $entry['model']['id'] ]))
+ {
+ $brands_and_models[ $entry['brand']['id'] ][ 'models' ][ $entry['model']['id'] ] = [
+ "name" => $entry['model']['name'],
+ "modifications" => [ $entry['modification'] ],
+ ];
+ }
+
+ if(!in_array($entry['modification'], $brands_and_models[ $entry['brand']['id'] ][ 'models' ][ $entry['model']['id'] ][ 'modifications' ]))
+ {
+ array_push($brands_and_models[ $entry['brand']['id'] ][ 'models' ][ $entry['model']['id'] ][ 'modifications' ], $entry['modification']);
+ }
+ }
+
+ if($c === 0)
+ {
+ print_r($entry);
+ }
+ $c++;
+}
+
+//print_r($brands_and_models);
+//die();
+$c = 0;
+
+$bitrix_brands = [];
+$bitrix_models = [];
+$bitrix_modifications = [];
+$bitrix_modifications_codes = [];
+
+foreach($brands_and_models AS $brand_uid => $brand)
+{
+ //print $uid." - ".$brand['name']."\n";
+ if(in_array($brand_uid, $bitrix_hidden_brands))
+ {
+ array_push($repost_brands, $brand['name']);
+ }
+
+ //if($c < 2)
+ //{
+ //добавляем новую марку
+ $brand_existed = null;
+ $brand_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_BRANDS, "PROPERTY_UID" => $brand_uid ], false, ["nPageSize" => 1], [] );
+ while($brand_search_ob = $brand_search_res->GetNextElement())
+ {
+ $brand_existed = $brand_search_ob->GetFields();
+ $brand_existed['PROPERTIES'] = $brand_search_ob->GetProperties();
+
+ $bitrix_brands[ $brand_uid ] = $brand_existed['ID'];
+ }
+
+ $code = CUtil::translit( $brand['name'], "ru", [ "max_len" => 255, "change_case" => "L", "replace_space" => "-", "replace_other" => "-", ] );
+ if($brand_existed !== null)
+ {
+ $brand_update_payload = [
+ "ACTIVE" => "Y",
+ "CODE" => $code,
+ "NAME" => $brand['name'],
+ ];
+
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $update_element = new CIBlockElement;
+ $update_result = $update_element->Update($brand_existed['ID'], $brand_update_payload);
+ }
+
+ $result = models_check($bitrix_models, $bitrix_modifications, $bitrix_modifications_codes, $brand_uid, $brand);
+
+ $bitrix_models = $result['bitrix_models'];
+ $bitrix_modifications = $result['bitrix_modifications'];
+ $bitrix_modifications_codes = $result['bitrix_modifications_codes'];
+
+ array_push( $bitrix_enabled_brands, $brand_uid );
+ }
+ else
+ {
+ $brand_element = new CIBlockElement;
+ $brand_payload = [
+ "IBLOCK_SECTION_ID" => false,
+ "IBLOCK_ID" => IBLOCK_ID_BRANDS,
+ "PROPERTY_VALUES" => [
+ "UID" => $brand_uid,
+ "TRANSCRIPTION" => $brand['name'],
+ ],
+ "NAME" => $brand['name'],
+ "CODE" => $code,
+ "ACTIVE" => "Y",
+ ];
+
+ array_push($new_brands, $brand['name']);
+
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ if($new_brand_id = $brand_element->Add($brand_payload))
+ {
+ $bitrix_brands[$brand_uid] = $new_brand_id;
+ }
+ else
+ {
+ echo "brand error: ".$brand_element->LAST_ERROR;
+ }
+ }
+// elasticIndex("events_cars", [
+// "type" => "add"
+// ]);
+
+ $result = models_check($bitrix_models, $bitrix_modifications, $bitrix_modifications_codes, $brand_uid, $brand);
+
+ $bitrix_models = $result['bitrix_models'];
+ $bitrix_modifications = $result['bitrix_modifications'];
+ $bitrix_modifications_codes = $result['bitrix_modifications_codes'];
+
+ array_push( $bitrix_enabled_brands, $brand_uid );
+ }
+
+ //print "\n------------------------------\n";
+ //}
+
+ $c++;
+}
+
+function set_brand_activity($brand_uid, $active = "N")
+{
+ print "set_brand_activity [ ".$brand_uid.", ".$active." ]\n";
+
+ global $hide_brands;
+ global $current_representation;
+
+ $brand_id = null;
+ $brand_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_BRANDS, "PROPERTY_UID" => $brand_uid ], false, false, [] );
+
+ while($brand_search_ob = $brand_search_res->GetNextElement())
+ {
+ $brand_search = $brand_search_ob->GetFields();
+ $brand_id = $brand_search['ID'];
+ }
+
+ if($brand_id !== null)
+ {
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $update_element = new CIBlockElement;
+ $update_result = $update_element->Update($brand_id, [ "ACTIVE" => $active, ]);
+ }
+
+ if($brand_search['ACTIVE'] == "Y" && $active == "N")
+ {
+ $current_representation[ $brand_uid ]['STATUS'] = "disabled";
+ }
+
+ if($brand_search['ACTIVE'] == "N" && $active == "Y")
+ {
+ $current_representation[ $brand_uid ]['STATUS'] = "enabled";
+ }
+
+ if($active == "N")
+ {
+ array_push($hide_brands, $brand_search['NAME']);
+ }
+ }
+}
+
+function set_model_activity($model_uid, $active = "N")
+{
+ print "set_model_activity [ ".$model_uid.", ".$active." ]\n";
+
+ global $hide_models;
+ global $current_representation;
+
+ //print "set_model_activity - [ ".$model_uid." ]\n";
+
+ $model_id = null;
+ $model_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, "PROPERTY_UID" => $model_uid ], false, false, [] );
+
+ while($model_search_ob = $model_search_res->GetNextElement())
+ {
+ $model_search = $model_search_ob->GetFields();
+ $model_id = $model_search['ID'];
+ }
+
+ if($model_id !== null)
+ {
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $update_element = new CIBlockElement;
+ $update_result = $update_element->Update($model_id, [ "ACTIVE" => $active, ]);
+ }
+
+ $brand_uid = get_brand_by_model_uid($model_uid);
+
+ if($model_search['ACTIVE'] == "Y" && $active == "N")
+ {
+ $current_representation[ $brand_uid ][ 'MODELS' ][ $model_uid ][ 'STATUS' ] = "disabled";
+ }
+
+ if($model_search['ACTIVE'] == "N" && $active == "Y")
+ {
+ $current_representation[ $brand_uid ][ 'MODELS' ][ $model_uid ][ 'STATUS' ] = "enabled";
+ }
+
+ if($active == "N")
+ {
+ array_push($hide_models, $model_search['NAME']);
+ }
+ }
+}
+
+function set_modification_activity($modification_code, $active = "N")
+{
+ print "set_modification_activity [ ".$modification_code.", ".$active." ]\n";
+
+ global $hide_modifications;
+ global $current_representation;
+
+ $modification_id = null;
+ $modification_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODIFICATIONS, "CODE" => $modification_code ], false, false, [] );
+
+ while($modification_search_ob = $modification_search_res->GetNextElement())
+ {
+ $modification_search = $modification_search_ob->GetFields();
+ $modification_id = $modification_search['ID'];
+ }
+
+ if($modification_id !== null)
+ {
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $update_element = new CIBlockElement;
+ $update_result = $update_element->Update($modification_id, [ "ACTIVE" => $active, ]);
+ }
+
+ $brand_model_uids = get_brand_model_by_modification_uid($modification_code);
+ //print "----------get_brand_model_by_modification_uid [ ".$modification_code." ]\n";
+ //print_r($brand_model_uids);
+ //print "\n";
+
+ if($brand_model_uids !== null)
+ {
+ //print "set_modification_activity [ ".$modification_code.", ".$active." ][ brand_model_uids ] [ ".$brand_model_uids['BRAND_UID']." ] [ ".$brand_model_uids['MODEL_UID']." ] [ ".$modification_search['ACTIVE']." ][ ".$active." ] NOT NULL \n";
+
+ if($modification_search['ACTIVE'] == "Y" && $active == "N")
+ {
+ //print "set_modification_activity [ ".$modification_code.", ".$active." ][ brand_model_uids ] [ ".$brand_model_uids['BRAND_UID']." ] [ ".$brand_model_uids['MODEL_UID']." ] [ ".$modification_search['ACTIVE']." ][ ".$active." ] NOT NULL DISABLE \n";
+
+ $current_representation[ $brand_model_uids['BRAND_UID'] ][ 'MODELS' ][ $brand_model_uids['MODEL_UID'] ][ 'MODIFICATIONS' ][ $modification_code ][ 'STATUS' ] = "disabled";
+ }
+
+ if($modification_search['ACTIVE'] == "N" && $active == "Y")
+ {
+ //print "set_modification_activity [ ".$modification_code.", ".$active." ][ brand_model_uids ] [ ".$brand_model_uids['BRAND_UID']." ] [ ".$brand_model_uids['MODEL_UID']." ] [ ".$modification_search['ACTIVE']." ][ ".$active." ] NOT NULL ENABLE \n";
+
+ $current_representation[ $brand_model_uids['BRAND_UID'] ][ 'MODELS' ][ $brand_model_uids['MODEL_UID'] ][ 'MODIFICATIONS' ][ $modification_code ][ 'STATUS' ] = "enabled";
+ }
+ }
+
+ //print "\n\n";
+
+ if($active == "N")
+ {
+ array_push($hide_modifications, $modification_search['NAME']);
+ }
+ }
+}
+
+function set_car_activity($car_uid, $active = "N")
+{
+ global $hide_cars;
+
+ //print "SET ACTIVE ".$car_uid." | ".$active."\n";
+ $car_id = null;
+ $car_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, "PROPERTY_UID" => $car_uid ], false, false, [] );
+
+ while($car_search_ob = $car_search_res->GetNextElement())
+ {
+ $car_search = $car_search_ob->GetFields();
+ $car_id = $car_search['ID'];
+ }
+
+ if($car_id !== null)
+ {
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $update_element = new CIBlockElement;
+ $update_result = $update_element->Update($car_id, [ "ACTIVE" => $active, ]);
+
+ if($active == "N")
+ {
+ array_push($hide_cars, $car_search['NAME']);
+ }
+ }
+ }
+}
+
+function set_body_activity($body_name, $active = "N")
+{
+ $body_id = null;
+ $body_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_BODIES, "NAME" => $body_name ], false, false, [] );
+
+ while($body_search_ob = $body_search_res->GetNextElement())
+ {
+ $body_search = $body_search_ob->GetFields();
+ $body_id = $body_search['ID'];
+ }
+
+ if($body_id !== null)
+ {
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $update_element = new CIBlockElement;
+ $update_result = $update_element->Update($body_id, [ "ACTIVE" => $active, ]);
+ }
+ }
+}
+
+function set_engine_fuel_activity($engine_fuel_name, $active = "N")
+{
+ $engine_fuel_id = null;
+ $engine_fuel_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_ENGINE_FUELS, "NAME" => $engine_fuel_name ], false, false, [] );
+
+ while($engine_fuel_search_ob = $engine_fuel_search_res->GetNextElement())
+ {
+ $engine_fuel_search = $engine_fuel_search_ob->GetFields();
+ $engine_fuel_id = $engine_fuel_search['ID'];
+ }
+
+ if($engine_fuel_id !== null)
+ {
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $update_element = new CIBlockElement;
+ $update_result = $update_element->Update($engine_fuel_id, [ "ACTIVE" => $active, ]);
+ }
+ }
+}
+
+function models_check($bitrix_models, $bitrix_modifications, $bitrix_modifications_codes, $brand_uid, $brand)
+{
+ global $new_models;
+ global $new_modifications;
+ global $bitrix_hidden_models;
+ global $bitrix_hidden_modifications;
+ global $repost_models;
+ global $repost_modifications;
+ global $bitrix_enabled_models;
+ global $bitrix_enabled_modifications;
+
+ foreach($brand['models'] AS $model_uid => $model)
+ {
+ $model_name = $model['name'];
+
+ if(in_array($model_uid, $bitrix_hidden_models))
+ {
+ array_push($repost_models, $model_name);
+ }
+
+ $model_existed = null;
+ $model_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, "PROPERTY_UID" => $model_uid ], false, ["nPageSize" => 1], [] );
+ while($model_search_ob = $model_search_res->GetNextElement())
+ {
+ $model_existed = $model_search_ob->GetFields();
+ $model_existed['PROPERTIES'] = $model_search_ob->GetProperties();
+
+ $bitrix_models[$model_uid] = $model_existed['ID'];
+ }
+
+ $code = CUtil::translit( $model_name, "ru", [ "max_len" => 255, "change_case" => "L", "replace_space" => "-", "replace_other" => "-", ] );
+
+ if($model_existed !== null)
+ {
+ //print "MODEL ".$model_uid." EXISTED";
+
+ $model_update_payload = [
+ "ACTIVE" => "Y",
+ "NAME" => $model_name,
+ "CODE" => $code,
+ ];
+
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $update_element = new CIBlockElement;
+ $update_result = $update_element->Update($model_existed['ID'], $model_update_payload);
+ }
+
+ array_push( $bitrix_enabled_models, $model_uid );
+ }
+ else
+ {
+ $model_element = new CIBlockElement;
+ $model_payload = [
+ "IBLOCK_SECTION_ID" => false,
+ "IBLOCK_ID" => IBLOCK_ID_MODELS,
+ "PROPERTY_VALUES" => [
+ "BRAND_UID" => $brand_uid,
+ "UID" => $model_uid,
+ ],
+ "NAME" => $model_name,
+ "CODE" => $code,
+ "ACTIVE" => "Y",
+ ];
+
+ array_push($new_models, $model['name']);
+
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ if($new_model_id = $model_element->Add($model_payload))
+ {
+ $bitrix_models[$model_uid] = $new_model_id;
+ //echo "new_model_id: ".$new_model_id;
+ }
+ else
+ {
+ echo "model error: ".$model_element->LAST_ERROR;
+ }
+ }
+
+ array_push( $bitrix_enabled_models, $model_uid );
+ }
+
+ foreach($model['modifications'] AS $modification)
+ {
+ print "MOD ".$modification."\n";
+ $modification_existed = null;
+
+ if(in_array($modification, $bitrix_hidden_modifications))
+ {
+ array_push($repost_modifications, $modification);
+ }
+
+ $NAME = $brand['name']." ".$model_name." ".$modification;
+ $CODE = CUtil::translit( $NAME, "ru", [ "max_len" => 255, "change_case" => "L", "replace_space" => "-", "replace_other" => "-", ] );
+
+ //"ID"
+ $modification_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODIFICATIONS, "CODE" => $CODE ], false, ["nPageSize" => 1], [] );
+ while($modification_search_ob = $modification_search_res->GetNextElement())
+ {
+ $m_res = $modification_search_ob->GetFields();
+ if(isset($m_res['ID']))
+ {
+ $modification_existed = $m_res['ID'];
+ $bitrix_modifications[md5($brand_uid.$model_uid.$modification)] = $m_res['ID'];
+ array_push($bitrix_modifications_codes, $CODE);
+
+ array_push( $bitrix_enabled_modifications, $CODE );
+ }
+ }
+
+ if($modification_existed === null)
+ {
+ $modification_element = new CIBlockElement;
+ $modification_payload = [ "IBLOCK_SECTION_ID" => false, "IBLOCK_ID" => IBLOCK_ID_MODIFICATIONS, "PROPERTY_VALUES" => [ "MODEL_UID" => $model_uid, "TITLE" => $modification ], "NAME" => $NAME, "CODE" => $CODE, "ACTIVE" => "Y", ];
+
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ if($new_modification_id = $modification_element->Add($modification_payload))
+ {
+ $bitrix_modifications[md5($brand_uid.$model_uid.$modification)] = $new_modification_id;
+ array_push($bitrix_modifications_codes, $CODE);
+ array_push($new_modifications, $NAME);
+
+ array_push( $bitrix_enabled_modifications, $CODE );
+ }
+ else
+ {
+ echo "modification error: ".$modification_element->LAST_ERROR;
+ }
+ }
+ }
+ }
+ }
+
+ return [
+ "bitrix_models" => $bitrix_models,
+ "bitrix_modifications" => $bitrix_modifications,
+ "bitrix_modifications_codes" => $bitrix_modifications_codes
+ ];
+}
+
+print "bitrix brands count: ".count($bitrix_brands)."\n";
+//print_r($bitrix_brands);
+
+print "bitrix models count: ".count($bitrix_models)."\n";
+//print_r($bitrix_models);
+
+print "bitrix modifications count: ".count($bitrix_modifications)."\n";
+//print_r($bitrix_modifications);
+
+//кешируем новые UID ТС
+$json_new_cars = [];
+foreach($json AS $car)
+{
+ array_push($json_new_cars, $car['uid']);
+}
+
+$car_codes = [];
+
+$c = 0;
+foreach($json AS $car)
+{
+ $name = "".$car['brand']['name']." ".$car['model']['name']." ".$car['modification']."";
+
+ if(in_array($car['uid'], $bitrix_hidden_cars))
+ {
+ array_push($repost_cars, $name);
+ }
+ else
+ {
+ if(!in_array($car['uid'], $bitrix_existed_cars))
+ {
+ $c++;
+ array_push($new_cars, $name);
+ }
+ }
+
+ //обновляем список ТС в битриксе
+ $modification_content = file_get_contents(API_HOST."/site/Vehicle/GetCatalog?id=". $car['uid'] ."", false, stream_context_create($arrContextOptions));
+ $modification_json = json_decode($modification_content, true);
+
+// print "downloaded modification_content [ modification_json ][ ".$car['uid']." ]\n";
+
+ $title = $name." ".$car['modificationYear']."";
+ $code = CUtil::translit( str_replace([""", " ", "+"], ['"', "-", "-plus-"], $title), "ru", [ "max_len" => 255, "change_case" => "L", "replace_space" => "-", "replace_other" => "-", "safe_chars" => "-" ] );
+
+ //print "new car --- uid ".$car['uid']." | code ".$code."\n";
+
+ $PROPERTY_VALUES = [
+ "UID" => $car['uid'],
+ "BRAND" => $bitrix_brands[ $car['brand']['id'] ],
+ "MODEL" => $bitrix_models[ $car['model']['id'] ],
+ "MODIFICATION" => $bitrix_modifications[ md5($car['brand']['id'].$car['model']['id'].$car['modification']) ],
+ "MODIFICATION_YEAR" => $car['modificationYear'],
+ "GEAR" => $car['gear'],
+ "DRIVE" => $car['drive'],
+ "BODY" => $car['body'],
+ "ENGINE_POWER" => $car['engine']['power'],
+ "ENGINE_VOLUME" => $car['engine']['volume'],
+ "ENGINE_FUEL" => $car['engine']['fuel'],
+ "PRICE" => $car['price'],
+ "IMAGE_URL" => $car['url'],
+ "COMPLECTATION_BODY" => json_encode($modification_json['body']),
+ "COMPLECTATION_INTERIOR" => json_encode($modification_json['interior']),
+ "COMPLECTATION_SECURITY" => json_encode($modification_json['security']),
+ "COMPLECTATION_GUARANTEE" => json_encode($modification_json['guarantee']),
+ "COMPLECTATION_TECHNICAL_DESCRIPTION" => json_encode($modification_json['technicalDescription']),
+ "COMPLECTATION_FUNCTIONAL_EQUIPMENT" => json_encode($modification_json['functionalEquipment']),
+ "COMPLECTATION_TOTAL_INFORMATION" => json_encode($modification_json['totalInformation']),
+ "LEASING_PROGRAMS" => $car['programms'],
+ ];
+
+ if(!in_array($car['body'], $api_bodies))
+ {
+ array_push($api_bodies, $car['body']);
+ }
+
+ if(!in_array($car['engine']['fuel'], $api_engine_fuels))
+ {
+ array_push($api_engine_fuels, $car['engine']['fuel']);
+ }
+
+ //"ID"
+ $car_existed = null;
+ $car_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, "PROPERTY_UID" => $car['uid'] ], false, ["nPageSize" => 1], [] );
+
+ while($car_search_ob = $car_search_res->GetNextElement())
+ {
+ $car_existed = $car_search_ob->GetFields();
+ //print "CAR FOUND\n\n";
+ //print_r($car_existed);
+ }
+
+ $car_update_payload = [ "IBLOCK_SECTION" => false, "NAME" => $name, "CODE" => $code, "ACTIVE" => "Y", ];
+ if($car_existed !== null)
+ {
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $car_update_element = new CIBlockElement;
+ $car_update_result = $car_update_element->Update($car_existed['ID'], $car_update_payload);
+ }
+
+ CIBlockElement::SetPropertyValuesEx($car_existed['ID'], IBLOCK_ID_CATALOG_CARS_NEW, $PROPERTY_VALUES, []);
+ }
+ else
+ {
+ //if($c === 0)
+ //{
+ $car_element = new CIBlockElement;
+ $car_payload = [ "IBLOCK_SECTION_ID" => false, "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, "NAME" => $name, "CODE" => $code, "PROPERTY_VALUES" => $PROPERTY_VALUES, "ACTIVE" => "Y", ];
+
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ if($new_car_id = $car_element->Add($car_payload))
+ {
+ //$bitrix_brands[$brand_uid] = $new_brand_id;
+ //echo "new car id: ".$new_car_id;
+ }
+ else
+ {
+ print "CAR ERROR: ".$car_element->LAST_ERROR." | ".$car['uid']." | ".$code."\n";
+
+ if($car_element->LAST_ERROR == "Элемент с таким символьным кодом уже существует.
")
+ {
+ $car_with_problem = null;
+ $car_with_problem_res = CIBlockElement::GetList( [ "ID" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, "CODE" => $code ], false, ["nPageSize" => 1], [] );
+
+ while($car_with_problem_ob = $car_with_problem_res->GetNextElement())
+ {
+ $car_with_problem = $car_with_problem_ob->GetFields();
+ $car_with_problem['PROPERTIES'] = $car_with_problem_ob->GetProperties();
+ }
+
+ if($car_with_problem !== null)
+ {
+ print "REPLACE FOR ".$car_with_problem['ID']." uid => ".$car['uid']."\n\n";
+ print_r([ "ID" => $car_with_problem['ID'], "NAME" => $car_with_problem['NAME'], "CODE" => $car_with_problem['CODE'], "UID" => $car_with_problem['CODE'], ]);
+ print "\n\n\n";
+ CIBlockElement::SetPropertyValuesEx($car_with_problem['ID'], IBLOCK_ID_CATALOG_CARS_NEW, $PROPERTY_VALUES, []);
+ }
+ }
+ }
+ }
+ //}
+ }
+}
+
+//print "car_codes?\n";
+/*
+foreach($car_codes AS $cc => $count)
+{
+ if($count > 1)
+ {
+ print "cc ".$cc." - ".$count."\n";
+ }
+}
+*/
+
+$traceback_message = "Отчет:\n\n";
+
+//print "bitrix_existed_brands\n";
+$c = 0;
+foreach($bitrix_existed_brands AS $k => $b)
+{
+ if($c < 10)
+ {
+ //print $k." => ".$b."\n";
+ $c++;
+ }
+}
+
+//print "bitrix_brands\n";
+$c = 0;
+foreach($bitrix_brands AS $k => $b)
+{
+ if($c < 10)
+ {
+ //print $k." => ".$b."\n";
+ $c++;
+ }
+}
+
+
+//BRANDS
+
+$trace = "Новых марок: ".count($new_brands)."\n";
+foreach($new_brands AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+
+$trace = "Переопубликовано марок: ".count($repost_brands)."\n";
+foreach($repost_brands AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace;
+
+$b = 0;
+foreach($bitrix_enabled_brands AS $enabled_brand_uid)
+{
+ //print "bitrix_enabled_brands - enabled_brand_uid [ ".$enabled_brand_uid." ]\n";
+
+ //if($bitrix_brands[$enabled_brand_uid] !== null)
+ //{}
+ //else
+ //{
+ if(!in_array($enabled_brand_uid, $api_brands))
+ {
+ set_brand_activity($enabled_brand_uid, "N");
+ $b++;
+ }
+ else
+ {
+ set_brand_activity($enabled_brand_uid, "Y");
+ }
+ //}
+}
+
+$trace = "Снято с публикации марок: ".count($hide_brands)."\n";
+foreach($hide_brands AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n\n";
+
+
+//MODELS
+
+$trace = "Новых моделей: ".count($new_models)."\n";
+foreach($new_models AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+
+$trace = "Переопубликовано моделей: ".count($repost_models)."\n";
+foreach($repost_models AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+
+//print "----------bitrix_enabled_models----------\n";
+//print_r($bitrix_enabled_models);
+//print "--------------------\n";
+
+$m = 0;
+foreach($bitrix_enabled_models AS $enabled_model_uid)
+{
+ //print "bitrix_enabled_models - enabled_model_uid [ ".$enabled_model_uid." ]\n";
+
+// if($bitrix_models[$enabled_model_uid] !== null)
+// {}
+// else
+// {
+ if(!in_array($enabled_model_uid, $api_models))
+ {
+ set_model_activity($enabled_model_uid, "N");
+ $m++;
+ }
+ else
+ {
+ set_model_activity($enabled_model_uid, "Y");
+ }
+// }
+}
+
+$trace = "Снято с публикации моделей: ".count($hide_models)."\n";
+foreach($hide_models AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n\n";
+
+
+//MODIFICATIONS
+
+$trace = "Новых модификаций: ".count($new_modifications)."\n";
+foreach($new_modifications AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace;
+
+$trace = "Переопубликовано модификаций: ".count($repost_modifications)."\n";
+foreach($repost_modifications AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace;
+
+$md = 0;
+
+$bitrix_enabled_modifications = array_unique($bitrix_enabled_modifications);
+foreach($bitrix_enabled_modifications AS $enabled_modifications_code)
+{
+ if(!in_array($enabled_modifications_code, $bitrix_modifications_codes))
+ {
+ set_modification_activity($enabled_modifications_code, "N");
+ $md++;
+ }
+ else
+ {
+ set_modification_activity($enabled_modifications_code, "Y");
+ }
+}
+
+$trace = "Снято с публикации модификаций: ".count($hide_modifications);
+foreach($hide_modifications AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n\n";
+
+
+//CARS
+
+$trace = "Новых ТС: ".count($new_cars)."\n";
+foreach($new_cars AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+
+$trace = "Переопубликовано ТС: ".count($repost_cars)."\n";
+foreach($repost_cars AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+
+//print "bitrix_existed_cars = ".count($bitrix_existed_cars)."\n";
+//print "json_new_cars = ".count($json_new_cars)."\n";
+
+$h = 0;
+foreach($bitrix_enabled_cars AS $enabled_car_uid)
+{
+ if(!in_array($enabled_car_uid, $json_new_cars))
+ {
+ $h++;
+ set_car_activity($enabled_car_uid, "N");
+ }
+}
+
+$trace = "Снято с публикации ТС: ".count($hide_cars)."\n";
+foreach($hide_cars AS $v)
+{
+ $trace .= $v."\n";
+}
+$traceback_message .= $trace."\n";
+//print "\n\n".$trace."\n\n";
+
+print $traceback_message;
+
+
+//кузов
+foreach($api_bodies AS $api_body)
+{
+ if(!in_array($api_body, $bitrix_enabled_bodies))
+ {
+ //выключено
+ if(!in_array($api_body, $bitrix_existed_bodies))
+ {
+ //не существует, создаем
+
+ $code = CUtil::translit( $api_body, "ru", [ "max_len" => 255, "change_case" => "L", "replace_space" => "-", "replace_other" => "-", ] );
+ $body_element = new CIBlockElement;
+ $body_payload = [
+ "IBLOCK_ID" => IBLOCK_ID_BODIES,
+ "PROPERTY_VALUES" => [
+ "SINGULAR_NAME" => $api_body,
+ "PLURAL_NAME" => $api_body,
+ "GENITIVE_NAME" => $api_body,
+ ],
+ "NAME" => $api_body,
+ "CODE" => $code,
+ "ACTIVE" => "Y",
+ ];
+
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $body_element->Add($body_payload);
+ array_push($bitrix_existed_bodies, $api_body);
+ }
+ }
+ else
+ {
+ //существует, включаем
+ set_body_activity($api_body, "Y");
+ }
+ }
+}
+
+foreach($bitrix_existed_bodies AS $bitrix_body)
+{
+ if(!in_array($bitrix_body, $api_bodies))
+ {
+ //выключаем
+ set_body_activity($bitrix_body, "N");
+ }
+}
+
+
+//топливо
+foreach($api_engine_fuels AS $api_engine_fuel)
+{
+ if(!in_array($api_engine_fuel, $bitrix_enabled_engine_fuels))
+ {
+ //выключено
+ if(!in_array($api_engine_fuel, $bitrix_existed_engine_fuels))
+ {
+ //не существует, создаем
+ $code = CUtil::translit( $api_engine_fuel, "ru", [ "max_len" => 255, "change_case" => "L", "replace_space" => "-", "replace_other" => "-", ] );
+ $engine_fuel_element = new CIBlockElement;
+ $engine_fuel_payload = [
+ "IBLOCK_ID" => IBLOCK_ID_ENGINE_FUELS,
+ "PROPERTY_VALUES" => [
+ "SINGULAR_NAME" => "автомобиль с двигателем ".$api_engine_fuel,
+ "PLURAL_NAME" => "автомобили с двигателем ".$api_engine_fuel,
+ "GENITIVE_NAME" => "автомобилей с двигателем ".$api_engine_fuel,
+ ],
+ "NAME" => $api_engine_fuel,
+ "CODE" => $code,
+ "ACTIVE" => "Y",
+ ];
+
+ if(!in_array("simulate", $GLOBALS['argv']))
+ {
+ $engine_fuel_element->Add($engine_fuel_payload);
+ array_push($bitrix_existed_engine_fuels, $api_engine_fuel);
+ }
+ }
+ else
+ {
+ //существует, включаем
+ set_engine_fuel_activity($api_engine_fuel, "Y");
+ }
+ }
+}
+
+foreach($bitrix_existed_engine_fuels AS $bitrix_engine_fuel)
+{
+ if(!in_array($bitrix_engine_fuel, $api_engine_fuels))
+ {
+ //выключаем
+ set_engine_fuel_activity($bitrix_engine_fuel, "N");
+ }
+}
+
+
+
+/* search reindex start -------------------------------------------------------------*/
+
+if(!in_array("simulate", $GLOBALS['argv']))
+{
+ $reindex_handler = false;
+ $reindex_handler = CSearch::ReIndexAll(false, 60, $reindex_handler);
+ while(is_array($reindex_handler))
+ {
+ $reindex_handler = CSearch::ReIndexAll(false, 60, $reindex_handler);
+ }
+}
+
+/* search reindex end -------------------------------------------------------------*/
+
+
+
+/* sitemap regen start -------------------------------------------------------------*/
+
+$ID = 1;
+$NS = [];
+$SESSION = [];
+$arSitemap = null;
+
+if($ID > 0)
+{
+ $dbSitemap = SitemapTable::getById($ID);
+ $arSitemap = $dbSitemap->fetch();
+
+ $dbSite = SiteTable::getByPrimary($arSitemap['SITE_ID']);
+ $arSitemap['SITE'] = $dbSite->fetch();
+}
+
+$arSitemap['SETTINGS'] = unserialize($arSitemap['SETTINGS'], ['allowed_classes' => false]);
+
+$arSitemapSettings = array(
+ 'SITE_ID' => $arSitemap['SITE_ID'],
+ 'PROTOCOL' => $arSitemap['SETTINGS']['PROTO'] == 1 ? 'https' : 'http',
+ 'DOMAIN' => $arSitemap['SETTINGS']['DOMAIN'],
+);
+
+function seoSitemapGetFilesData($PID, $arSitemap, $arCurrentDir, $sitemapFile)
+{
+ global $ID;
+ global $NS;
+ global $SESSION;
+ global $arSitemap;
+ global $arSitemapSettings;
+
+ //global $NS;
+
+ $arDirList = array();
+
+ if($arCurrentDir['ACTIVE'] == SitemapRuntimeTable::ACTIVE)
+ {
+ $list = \CSeoUtils::getDirStructure(
+ $arSitemap['SETTINGS']['logical'] == 'Y',
+ $arSitemap['SITE_ID'],
+ $arCurrentDir['ITEM_PATH']
+ );
+
+ foreach($list as $dir)
+ {
+ $dirKey = "/".ltrim($dir['DATA']['ABS_PATH'], "/");
+
+ if($dir['TYPE'] == 'F')
+ {
+ if(!isset($arSitemap['SETTINGS']['FILE'][$dirKey])
+ || $arSitemap['SETTINGS']['FILE'][$dirKey] == 'Y')
+ {
+ if(preg_match($arSitemap['SETTINGS']['FILE_MASK_REGEXP'], $dir['FILE']))
+ {
+ $f = new IO\File($dir['DATA']['PATH'], $arSitemap['SITE_ID']);
+ $sitemapFile->addFileEntry($f);
+ $NS['files_count']++;
+ }
+ }
+ }
+ else
+ {
+ if(!isset($arSitemap['SETTINGS']['DIR'][$dirKey])
+ || $arSitemap['SETTINGS']['DIR'][$dirKey] == 'Y')
+ {
+ $arDirList[] = $dirKey;
+ }
+ }
+ }
+ }
+ else
+ {
+ $len = mb_strlen($arCurrentDir['ITEM_PATH']);
+ if(!empty($arSitemap['SETTINGS']['DIR']))
+ {
+ foreach($arSitemap['SETTINGS']['DIR'] as $dirKey => $checked)
+ {
+ if($checked == 'Y')
+ {
+ if(strncmp($arCurrentDir['ITEM_PATH'], $dirKey, $len) === 0)
+ {
+ $arDirList[] = $dirKey;
+ }
+ }
+ }
+ }
+
+ if(!empty($arSitemap['SETTINGS']['FILE']))
+ {
+ foreach($arSitemap['SETTINGS']['FILE'] as $dirKey => $checked)
+ {
+ if($checked == 'Y')
+ {
+ if(strncmp($arCurrentDir['ITEM_PATH'], $dirKey, $len) === 0)
+ {
+ $fileName = IO\Path::combine(
+ SiteTable::getDocumentRoot($arSitemap['SITE_ID']),
+ $dirKey
+ );
+
+ if(!is_dir($fileName))
+ {
+ $f = new IO\File($fileName, $arSitemap['SITE_ID']);
+ if($f->isExists()
+ && !$f->isSystem()
+ && preg_match($arSitemap['SETTINGS']['FILE_MASK_REGEXP'], $f->getName())
+ )
+ {
+ $sitemapFile->addFileEntry($f);
+ $NS['files_count']++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(count($arDirList) > 0)
+ {
+ foreach($arDirList as $dirKey)
+ {
+ $arRuntimeData = array(
+ 'PID' => $PID,
+ 'ITEM_PATH' => $dirKey,
+ 'PROCESSED' => SitemapRuntimeTable::UNPROCESSED,
+ 'ACTIVE' => SitemapRuntimeTable::ACTIVE,
+ 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_DIR,
+ );
+ SitemapRuntimeTable::add($arRuntimeData);
+ }
+ }
+
+ SitemapRuntimeTable::update($arCurrentDir['ID'], array(
+ 'PROCESSED' => SitemapRuntimeTable::PROCESSED
+ ));
+}
+
+function generate($v)
+{
+ global $ID;
+ global $NS;
+ global $SESSION;
+ global $arSitemap;
+ global $arSitemapSettings;
+
+ $arValueSteps = array(
+ 'init' => 0,
+ 'files' => 40,
+ 'iblock_index' => 50,
+ 'iblock' => 60,
+ 'forum_index' => 70,
+ 'forum' => 80,
+ 'index' => 100,
+ );
+
+ $PID = $ID;
+
+ if($v == $arValueSteps['init'])
+ {
+ SitemapRuntimeTable::clearByPid($PID);
+
+ $NS['time_start'] = microtime(true);
+ $NS['files_count'] = 0;
+ $NS['steps_count'] = 0;
+
+ $bRootChecked = isset($arSitemap['SETTINGS']['DIR']['/'])
+ && $arSitemap['SETTINGS']['DIR']['/'] == 'Y';
+
+ $arRuntimeData = array(
+ 'PID' => $PID,
+ 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_DIR,
+ 'ITEM_PATH' => '/',
+ 'PROCESSED' => SitemapRuntimeTable::UNPROCESSED,
+ 'ACTIVE' => $bRootChecked ? SitemapRuntimeTable::ACTIVE : SitemapRuntimeTable::INACTIVE,
+ );
+
+ SitemapRuntimeTable::add($arRuntimeData);
+
+ $msg = 'SITEMAP_RUN_FILES' . ' ' . '/'."\n";
+
+ $sitemapFile = new SitemapRuntime($PID, $arSitemap['SETTINGS']['FILENAME_FILES'], $arSitemapSettings);
+
+ $v++;
+ }
+ elseif($v < $arValueSteps['files'])
+ {
+ $NS['steps_count']++;
+
+ $sitemapFile = new SitemapRuntime($PID, $arSitemap['SETTINGS']['FILENAME_FILES'], $arSitemapSettings);
+
+ $stepDuration = 15;
+ $ts_finish = microtime(true) + $stepDuration * 0.95;
+
+ $bFinished = false;
+ $bCheckFinished = false;
+
+ $dbRes = null;
+
+ while(!$bFinished && microtime(true) <= $ts_finish)
+ {
+ if(!$dbRes)
+ {
+ $dbRes = SitemapRuntimeTable::getList(array(
+ 'order' => array('ITEM_PATH' => 'ASC'),
+ 'filter' => array(
+ 'PID' => $PID,
+ 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_DIR,
+ 'PROCESSED' => SitemapRuntimeTable::UNPROCESSED,
+ ),
+ 'limit' => 1000
+ ));
+ }
+
+ if($arRes = $dbRes->Fetch())
+ {
+ seoSitemapGetFilesData($PID, $arSitemap, $arRes, $sitemapFile);
+ $bCheckFinished = false;
+ }
+ elseif(!$bCheckFinished)
+ {
+ $dbRes = null;
+ $bCheckFinished = true;
+ }
+ else
+ {
+ $bFinished = true;
+ }
+ }
+
+ if(!$bFinished)
+ {
+ if($v < $arValueSteps['files']-1)
+ $v++;
+
+ $msg = 'SITEMAP_RUN_FILES'.' '.'ITEM_PATH'."\n";
+ }
+ else
+ {
+ if(!is_array($NS['XML_FILES']))
+ $NS['XML_FILES'] = array();
+
+ if($sitemapFile->isNotEmpty())
+ {
+ if($sitemapFile->isCurrentPartNotEmpty())
+ {
+ $sitemapFile->finish();
+ }
+ else
+ {
+ $sitemapFile->delete();
+ }
+
+ $xmlFiles = $sitemapFile->getNameList();
+ $directory = $sitemapFile->getPathDirectory();
+ foreach($xmlFiles as &$xmlFile)
+ $xmlFile = $directory.$xmlFile;
+ $NS['XML_FILES'] = array_unique(array_merge($NS['XML_FILES'], $xmlFiles));
+ }
+ else
+ {
+ $sitemapFile->delete();
+ }
+
+ $v = $arValueSteps['files'];
+ $msg = 'SITEMAP_RUN_FILE_COMPLETE'.' '.$arSitemap['SETTINGS']['FILENAME_FILES']."\n";
+ }
+
+ }
+ elseif($v < $arValueSteps['iblock_index'])
+ {
+ $NS['time_start'] = microtime(true);
+
+ $arIBlockList = array();
+ if(Main\Loader::includeModule('iblock'))
+ {
+ $arIBlockList = $arSitemap['SETTINGS']['IBLOCK_ACTIVE'];
+ if(count($arIBlockList) > 0)
+ {
+ $arIBlocks = array();
+ $dbIBlock = CIBlock::GetList(array(), array('ID' => array_keys($arIBlockList)));
+ while ($arIBlock = $dbIBlock->Fetch())
+ {
+ $arIBlocks[$arIBlock['ID']] = $arIBlock;
+ }
+
+ foreach($arIBlockList as $iblockId => $iblockActive)
+ {
+ if($iblockActive !== 'Y' || !array_key_exists($iblockId, $arIBlocks))
+ {
+ unset($arIBlockList[$iblockId]);
+ }
+ else
+ {
+ SitemapRuntimeTable::add(array(
+ 'PID' => $PID,
+ 'PROCESSED' => SitemapRuntimeTable::UNPROCESSED,
+ 'ITEM_ID' => $iblockId,
+ 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_IBLOCK,
+ ));
+
+ $fileName = str_replace(
+ array('#IBLOCK_ID#', '#IBLOCK_CODE#', '#IBLOCK_XML_ID#'),
+ array($iblockId, $arIBlocks[$iblockId]['CODE'], $arIBlocks[$iblockId]['XML_ID']),
+ $arSitemap['SETTINGS']['FILENAME_IBLOCK']
+ );
+
+ $sitemapFile = new SitemapRuntime($PID, $fileName, $arSitemapSettings);
+ if($sitemapFile->isExists())
+ {
+ //$sitemapFile->delete();
+ }
+ }
+ }
+ }
+ }
+
+ $NS['LEFT_MARGIN'] = 0;
+ $NS['IBLOCK_LASTMOD'] = 0;
+
+ $NS['IBLOCK'] = array();
+ $NS['IBLOCK_MAP'] = array();
+
+ if(count($arIBlockList) <= 0)
+ {
+ $v = $arValueSteps['iblock'];
+ $msg = 'SITEMAP_RUN_IBLOCK_EMPTY'."\n";
+ }
+ else
+ {
+ $v = $arValueSteps['iblock_index'];
+ $msg = 'SITEMAP_RUN_IBLOCK'."\n";
+ }
+ }
+ else if($v < $arValueSteps['iblock'])
+ {
+ $stepDuration = 10;
+ $ts_finish = microtime(true) + $stepDuration * 0.95;
+
+ $bFinished = false;
+ $bCheckFinished = false;
+
+ $currentIblock = false;
+ $iblockId = 0;
+
+ $dbOldIblockResult = null;
+ $dbIblockResult = null;
+
+ if(isset($SESSION["SEO_SITEMAP_".$PID]))
+ {
+ $NS['IBLOCK_MAP'] = $SESSION["SEO_SITEMAP_".$PID];
+ unset($SESSION["SEO_SITEMAP_".$PID]);
+ }
+
+ while(!$bFinished && microtime(true) <= $ts_finish)
+ {
+ if(!$currentIblock)
+ {
+ $arCurrentIBlock = false;
+ $dbRes = SitemapRuntimeTable::getList(array(
+ 'order' => array('ID' => 'ASC'),
+ 'filter' => array(
+ 'PID' => $PID,
+ 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_IBLOCK,
+ 'PROCESSED' => SitemapRuntimeTable::UNPROCESSED,
+ ),
+ 'limit' => 1
+ ));
+
+ $currentIblock = $dbRes->fetch();
+
+ if($currentIblock)
+ {
+ $iblockId = intval($currentIblock['ITEM_ID']);
+
+ $dbIBlock = CIBlock::GetByID($iblockId);
+ $arCurrentIBlock = $dbIBlock->Fetch();
+
+ if(!$arCurrentIBlock)
+ {
+ SitemapRuntimeTable::update($currentIblock['ID'], array(
+ 'PROCESSED' => SitemapRuntimeTable::PROCESSED
+ ));
+
+ $NS['LEFT_MARGIN'] = 0;
+ $NS['IBLOCK_LASTMOD'] = 0;
+ $NS['LAST_ELEMENT_ID'] = 0;
+ unset($NS['CURRENT_SECTION']);
+ }
+ else
+ {
+ if($arCurrentIBlock['LIST_PAGE_URL'] == '')
+ $arSitemap['SETTINGS']['IBLOCK_LIST'][$iblockId] = 'N';
+ if($arCurrentIBlock['SECTION_PAGE_URL'] == '')
+ $arSitemap['SETTINGS']['IBLOCK_SECTION'][$iblockId] = 'N';
+ if($arCurrentIBlock['DETAIL_PAGE_URL'] == '')
+ $arSitemap['SETTINGS']['IBLOCK_ELEMENT'][$iblockId] = 'N';
+
+ $NS['IBLOCK_LASTMOD'] = max($NS['IBLOCK_LASTMOD'], MakeTimeStamp($arCurrentIBlock['TIMESTAMP_X']));
+
+ if($NS['LEFT_MARGIN'] <= 0 && $arSitemap['SETTINGS']['IBLOCK_ELEMENT'][$iblockId] != 'N')
+ {
+ $NS['CURRENT_SECTION'] = 0;
+ }
+
+ $fileName = str_replace(
+ array('#IBLOCK_ID#', '#IBLOCK_CODE#', '#IBLOCK_XML_ID#'),
+ array($iblockId, $arCurrentIBlock['CODE'], $arCurrentIBlock['XML_ID']),
+ $arSitemap['SETTINGS']['FILENAME_IBLOCK']
+ );
+ $sitemapFile = new SitemapRuntime($PID, $fileName, $arSitemapSettings);
+ }
+ }
+ }
+
+ if(!$currentIblock)
+ {
+ $bFinished = true;
+ }
+ elseif(is_array($arCurrentIBlock))
+ {
+ if($dbIblockResult == null)
+ {
+ if(isset($NS['CURRENT_SECTION']))
+ {
+ $dbIblockResult = CIBlockElement::GetList(
+ array('ID' => 'ASC'),
+ array(
+ 'IBLOCK_ID' => $iblockId,
+ 'ACTIVE' => 'Y',
+ 'SECTION_ID' => intval($NS['CURRENT_SECTION']),
+ '>ID' => intval($NS['LAST_ELEMENT_ID']),
+ 'SITE_ID' => $arSitemap['SITE_ID'],
+ "ACTIVE_DATE" => "Y"
+ ),
+ false,
+ array('nTopCount' => 1000),
+ array('ID','TIMESTAMP_X','DETAIL_PAGE_URL')
+ );
+ }
+ else
+ {
+ $NS['LAST_ELEMENT_ID'] = 0;
+ $dbIblockResult = CIBlockSection::GetList(
+ array('LEFT_MARGIN' => 'ASC'),
+ array(
+ 'IBLOCK_ID' => $iblockId,
+ 'GLOBAL_ACTIVE' => 'Y',
+ '>LEFT_BORDER' => intval($NS['LEFT_MARGIN']),
+ ),
+ false,
+ array(
+ 'ID', 'TIMESTAMP_X', 'SECTION_PAGE_URL', 'LEFT_MARGIN', 'IBLOCK_SECTION_ID'
+ ),
+ array('nTopCount' => 100)
+ );
+ }
+ }
+
+ if(isset($NS['CURRENT_SECTION']))
+ {
+ $arElement = $dbIblockResult->fetch();
+
+ if($arElement)
+ {
+ if(!is_array($NS['IBLOCK_MAP'][$iblockId]))
+ {
+ $NS['IBLOCK_MAP'][$iblockId] = array();
+ }
+
+ if(!array_key_exists($arElement['ID'], $NS['IBLOCK_MAP'][$iblockId]))
+ {
+ $arElement['LANG_DIR'] = $arSitemap['SITE']['DIR'];
+
+ $bCheckFinished = false;
+ $elementLastmod = MakeTimeStamp($arElement['TIMESTAMP_X']);
+ $NS['IBLOCK_LASTMOD'] = max($NS['IBLOCK_LASTMOD'], $elementLastmod);
+ $NS['LAST_ELEMENT_ID'] = $arElement['ID'];
+
+ $NS['IBLOCK'][$iblockId]['E']++;
+ $NS['IBLOCK_MAP'][$iblockId][$arElement["ID"]] = 1;
+
+ $url = SitemapIblock::prepareUrlToReplace($arElement['DETAIL_PAGE_URL'], $arSitemap['SITE_ID']);
+ $url = \CIBlock::ReplaceDetailUrl($url, $arElement, false, "E");
+
+ $sitemapFile->addIBlockEntry($url, $elementLastmod);
+ }
+ }
+ elseif(!$bCheckFinished)
+ {
+ $bCheckFinished = true;
+ $dbIblockResult = null;
+ }
+ else
+ {
+ $bCheckFinished = false;
+ unset($NS['CURRENT_SECTION']);
+ $NS['LAST_ELEMENT_ID'] = 0;
+
+ $dbIblockResult = null;
+ if($dbOldIblockResult)
+ {
+ $dbIblockResult = $dbOldIblockResult;
+ $dbOldIblockResult = null;
+ }
+ }
+ }
+ else
+ {
+ $arSection = $dbIblockResult->fetch();
+
+ if($arSection)
+ {
+ $bCheckFinished = false;
+ $sectionLastmod = MakeTimeStamp($arSection['TIMESTAMP_X']);
+ $NS['LEFT_MARGIN'] = $arSection['LEFT_MARGIN'];
+ $NS['IBLOCK_LASTMOD'] = max($NS['IBLOCK_LASTMOD'], $sectionLastmod);
+
+ $bActive = false;
+ $bActiveElement = false;
+
+ if(isset($arSitemap['SETTINGS']['IBLOCK_SECTION_SECTION'][$iblockId][$arSection['ID']]))
+ {
+ $bActive = $arSitemap['SETTINGS']['IBLOCK_SECTION_SECTION'][$iblockId][$arSection['ID']] == 'Y';
+ $bActiveElement = $arSitemap['SETTINGS']['IBLOCK_SECTION_ELEMENT'][$iblockId][$arSection['ID']] == 'Y';
+ }
+ elseif ($arSection['IBLOCK_SECTION_ID'] > 0)
+ {
+ $dbRes = SitemapRuntimeTable::getList(array(
+ 'filter' => array(
+ 'PID' => $PID,
+ 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_SECTION,
+ 'ITEM_ID' => $arSection['IBLOCK_SECTION_ID'],
+ 'PROCESSED' => SitemapRuntimeTable::PROCESSED,
+ ),
+ 'select' => array('ACTIVE', 'ACTIVE_ELEMENT'),
+ 'limit' => 1
+ ));
+
+ $parentSection = $dbRes->fetch();
+ if($parentSection)
+ {
+ $bActive = $parentSection['ACTIVE'] == SitemapRuntimeTable::ACTIVE;
+ $bActiveElement = $parentSection['ACTIVE_ELEMENT'] == SitemapRuntimeTable::ACTIVE;
+ }
+ }
+ else
+ {
+ $bActive = $arSitemap['SETTINGS']['IBLOCK_SECTION'][$iblockId] == 'Y';
+ $bActiveElement = $arSitemap['SETTINGS']['IBLOCK_ELEMENT'][$iblockId] == 'Y';
+ }
+
+ $arRuntimeData = array(
+ 'PID' => $PID,
+ 'ITEM_ID' => $arSection['ID'],
+ 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_SECTION,
+ 'ACTIVE' => $bActive ? SitemapRuntimeTable::ACTIVE : SitemapRuntimeTable::INACTIVE,
+ 'ACTIVE_ELEMENT' => $bActiveElement ? SitemapRuntimeTable::ACTIVE : SitemapRuntimeTable::INACTIVE,
+ 'PROCESSED' => SitemapRuntimeTable::PROCESSED,
+ );
+
+ if($bActive)
+ {
+ $NS['IBLOCK'][$iblockId]['S']++;
+
+ $arSection['LANG_DIR'] = $arSitemap['SITE']['DIR'];
+
+ $url = SitemapIblock::prepareUrlToReplace($arSection['SECTION_PAGE_URL'], $arSitemap['SITE_ID']);
+ $url = \CIBlock::ReplaceDetailUrl($url, $arSection, false, "S");
+
+ $sitemapFile->addIBlockEntry($url, $sectionLastmod);
+ }
+
+ SitemapRuntimeTable::add($arRuntimeData);
+
+ if($bActiveElement)
+ {
+ $NS['CURRENT_SECTION'] = $arSection['ID'];
+ $NS['LAST_ELEMENT_ID'] = 0;
+
+ $dbOldIblockResult = $dbIblockResult;
+ $dbIblockResult = null;
+ }
+
+ }
+ elseif(!$bCheckFinished)
+ {
+ unset($NS['CURRENT_SECTION']);
+ $bCheckFinished = true;
+ $dbIblockResult = null;
+ }
+ else
+ {
+ $bCheckFinished = false;
+
+ SitemapRuntimeTable::update($currentIblock['ID'], array(
+ 'PROCESSED' => SitemapRuntimeTable::PROCESSED,
+ ));
+
+ if($arSitemap['SETTINGS']['IBLOCK_LIST'][$iblockId] == 'Y' && $arCurrentIBlock['LIST_PAGE_URL'] <> '')
+ {
+ $NS['IBLOCK'][$iblockId]['I']++;
+
+ $arCurrentIBlock['IBLOCK_ID'] = $arCurrentIBlock['ID'];
+ $arCurrentIBlock['LANG_DIR'] = $arSitemap['SITE']['DIR'];
+
+ $url = SitemapIblock::prepareUrlToReplace($arCurrentIBlock['LIST_PAGE_URL'], $arSitemap['SITE_ID']);
+ $url = \CIBlock::ReplaceDetailUrl($url, $arCurrentIBlock, false, "");
+
+ $sitemapFile->addIBlockEntry($url, $NS['IBLOCK_LASTMOD']);
+ }
+
+ if($sitemapFile->isNotEmpty())
+ {
+ if($sitemapFile->isCurrentPartNotEmpty())
+ {
+ $sitemapFile->finish();
+ }
+ else
+ {
+ $sitemapFile->delete();
+ }
+
+ if(!is_array($NS['XML_FILES']))
+ $NS['XML_FILES'] = array();
+
+ $xmlFiles = $sitemapFile->getNameList();
+ $directory = $sitemapFile->getPathDirectory();
+ foreach($xmlFiles as &$xmlFile)
+ $xmlFile = $directory.$xmlFile;
+ $NS['XML_FILES'] = array_unique(array_merge($NS['XML_FILES'], $xmlFiles));
+ }
+ else
+ {
+ $sitemapFile->delete();
+ }
+
+ $currentIblock = false;
+ $NS['LEFT_MARGIN'] = 0;
+ $NS['IBLOCK_LASTMOD'] = 0;
+ unset($NS['CURRENT_SECTION']);
+ $NS['LAST_ELEMENT_ID'] = 0;
+ }
+ }
+ }
+ }
+ if($v < $arValueSteps['iblock']-1)
+ {
+ $msg = 'SITEMAP_RUN_IBLOCK_NAME'.' '.$arCurrentIBlock['NAME']."\n";
+ $v++;
+ }
+
+ if($bFinished)
+ {
+ $v = $arValueSteps['iblock'];
+ $msg = 'SITEMAP_RUN_FINALIZE'."\n";
+ }
+ }
+ elseif($v < $arValueSteps['forum_index'])
+ {
+ $NS['time_start'] = microtime(true);
+
+ $arForumList = array();
+ if(!empty($arSitemap['SETTINGS']['FORUM_ACTIVE']))
+ {
+ foreach ($arSitemap['SETTINGS']['FORUM_ACTIVE'] as $forumId => $active)
+ {
+ if ($active == "Y")
+ {
+ $arForumList[$forumId] = "Y";
+ }
+ }
+ }
+ if(count($arForumList) > 0 && Main\Loader::includeModule('forum'))
+ {
+ $arForums = array();
+ $db_res = CForumNew::GetListEx(
+ array(),
+ array(
+ '@ID' => array_keys($arForumList),
+ "ACTIVE" => "Y",
+ "SITE_ID" => $arSitemap['SITE_ID'],
+ "!TOPICS" => 0
+ )
+ );
+ while ($res = $db_res->Fetch())
+ {
+ $arForums[$res['ID']] = $res;
+ }
+ $arForumList = array_intersect_key($arForums, $arForumList);
+
+ foreach($arForumList as $id => $forum)
+ {
+ SitemapRuntimeTable::add(array(
+ 'PID' => $PID,
+ 'PROCESSED' => SitemapRuntimeTable::UNPROCESSED,
+ 'ITEM_ID' => $id,
+ 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_FORUM)
+ );
+
+ $fileName = str_replace('#FORUM_ID#', $forumId, $arSitemap['SETTINGS']['FILENAME_FORUM']);
+ $sitemapFile = new SitemapRuntime($PID, $fileName, $arSitemapSettings);
+ }
+ }
+
+ $NS['FORUM_CURRENT_TOPIC'] = 0;
+
+ if(count($arForumList) <= 0)
+ {
+ $v = $arValueSteps['forum'];
+ $msg = 'SITEMAP_RUN_FORUM_EMPTY'."\n";
+ }
+ else
+ {
+ $v = $arValueSteps['forum_index'];
+ $msg = 'SITEMAP_RUN_FORUM'."\n";
+ }
+ }
+ else if($v < $arValueSteps['forum'])
+ {
+ $stepDuration = 10;
+ $ts_finish = microtime(true) + $stepDuration * 0.95;
+
+ $bFinished = false;
+ $bCheckFinished = false;
+
+ $currentForum = false;
+ $forumId = 0;
+
+ $dbTopicResult = null;
+ $arTopic = null;
+
+ while(!$bFinished && microtime(true) <= $ts_finish && CModule::IncludeModule("forum"))
+ {
+ if(!$currentForum)
+ {
+ $arCurrentForum = false;
+ $dbRes = SitemapRuntimeTable::getList(array(
+ 'order' => array('ID' => 'ASC'),
+ 'filter' => array(
+ 'PID' => $PID,
+ 'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_FORUM,
+ 'PROCESSED' => SitemapRuntimeTable::UNPROCESSED,
+ ),
+ 'limit' => 1
+ ));
+
+ $currentForum = $dbRes->fetch();
+
+ if($currentForum)
+ {
+ $forumId = intval($currentForum['ITEM_ID']);
+
+ $db_res = CForumNew::GetListEx(
+ array(),
+ array(
+ 'ID' => $forumId,
+ "ACTIVE" => "Y",
+ "SITE_ID" => $arSitemap['SITE_ID'],
+ "!TOPICS" => 0
+ )
+ );
+ $arCurrentForum = $db_res->Fetch();
+ if(!$arCurrentForum)
+ {
+ SitemapRuntimeTable::update($currentForum['ID'], array(
+ 'PROCESSED' => SitemapRuntimeTable::PROCESSED
+ ));
+ }
+ else
+ {
+ $fileName = str_replace('#FORUM_ID#', $forumId, $arSitemap['SETTINGS']['FILENAME_FORUM']);
+ $sitemapFile = new SitemapRuntime($PID, $fileName, $arSitemapSettings);
+ }
+ }
+ }
+
+ if(!$currentForum)
+ {
+ $bFinished = true;
+ }
+ elseif(is_array($arCurrentForum))
+ {
+ $bActive = (array_key_exists($forumId, $arSitemap['SETTINGS']['FORUM_TOPIC']) && $arSitemap['SETTINGS']['FORUM_TOPIC'][$forumId] == "Y");
+ if($bActive)
+ {
+ if($dbTopicResult == null)
+ {
+ $dbTopicResult = CForumTopic::GetList(
+ array("LAST_POST_DATE" => "DESC"),
+ array_merge(
+ array(
+ "FORUM_ID" => $forumId,
+ "APPROVED" => "Y"),
+ ($NS['FORUM_CURRENT_TOPIC'] > 0 ? array(
+ ">ID" => $NS["FORUM_CURRENT_TOPIC"]
+ ) : array()
+ )
+ ),
+ false,
+ 0,
+ array('nTopCount' => 100)
+ );
+ }
+ if(($arTopic = $dbTopicResult->fetch()) && $arTopic)
+ {
+ $NS["FORUM_CURRENT_TOPIC"] = $arTopic["ID"];
+ $url = CForumNew::PreparePath2Message(
+ $arCurrentForum["PATH2FORUM_MESSAGE"],
+ array(
+ "FORUM_ID" => $arCurrentForum["ID"],
+ "TOPIC_ID" => $arTopic["ID"],
+ "TITLE_SEO" => $arTopic["TITLE_SEO"],
+ "MESSAGE_ID" => "s",
+ "SOCNET_GROUP_ID" => $arTopic["SOCNET_GROUP_ID"],
+ "OWNER_ID" => $arTopic["OWNER_ID"],
+ "PARAM1" => $arTopic["PARAM1"],
+ "PARAM2" => $arTopic["PARAM2"]
+ )
+ );
+ $sitemapFile->addIBlockEntry($url, MakeTimeStamp($arTopic['LAST_POST_DATE']));
+ }
+ }
+ else
+ {
+ $url = CForumNew::PreparePath2Message(
+ $arCurrentForum["PATH2FORUM_MESSAGE"],
+ array(
+ "FORUM_ID" => $arCurrentForum["ID"],
+ "TOPIC_ID" => $arCurrentForum["TID"],
+ "TITLE_SEO" => $arCurrentForum["TITLE_SEO"],
+ "MESSAGE_ID" => "s",
+ "SOCNET_GROUP_ID" => $arCurrentForum["SOCNET_GROUP_ID"],
+ "OWNER_ID" => $arCurrentForum["OWNER_ID"],
+ "PARAM1" => $arCurrentForum["PARAM1"],
+ "PARAM2" => $arCurrentForum["PARAM2"]
+ )
+ );
+ $sitemapFile->addIBlockEntry($url, MakeTimeStamp($arCurrentForum['LAST_POST_DATE']));
+ }
+ if (empty($arTopic))
+ {
+ $bCheckFinished = false;
+
+ SitemapRuntimeTable::update($currentForum['ID'], array(
+ 'PROCESSED' => SitemapRuntimeTable::PROCESSED,
+ ));
+
+ if($sitemapFile->isNotEmpty())
+ {
+ if($sitemapFile->isCurrentPartNotEmpty())
+ {
+ $sitemapFile->finish();
+ }
+ else
+ {
+ $sitemapFile->delete();
+ }
+
+ if(!is_array($NS['XML_FILES']))
+ $NS['XML_FILES'] = array();
+
+ $xmlFiles = $sitemapFile->getNameList();
+ $directory = $sitemapFile->getPathDirectory();
+ foreach($xmlFiles as &$xmlFile)
+ $xmlFile = $directory.$xmlFile;
+ $NS['XML_FILES'] = array_unique(array_merge($NS['XML_FILES'], $xmlFiles));
+ }
+ else
+ {
+ $sitemapFile->delete();
+ }
+
+ $currentForum = false;
+ $dbTopicResult = null;
+ $NS['FORUM_CURRENT_TOPIC'] = 0;
+ }
+ }
+ }
+ if($v < $arValueSteps['forum']-1)
+ {
+ $msg = 'SITEMAP_RUN_FORUM_NAME'.' '.$arCurrentForum['NAME']."\n";
+ $v++;
+ }
+
+ if($bFinished)
+ {
+ $v = $arValueSteps['forum'];
+ $msg = 'SITEMAP_RUN_FINALIZE'."\n";
+ }
+ }
+ else
+ {
+ SitemapRuntimeTable::clearByPid($PID);
+
+ $arFiles = array();
+
+ $sitemapFile = new SitemapIndex($arSitemap['SETTINGS']['FILENAME_INDEX'], $arSitemapSettings);
+
+ if(count($NS['XML_FILES']) > 0)
+ {
+ foreach ($NS['XML_FILES'] as $xmlFile)
+ {
+ $arFiles[] = new IO\File(IO\Path::combine(
+ $sitemapFile->getSiteRoot(),
+ $xmlFile
+ ), $arSitemap['SITE_ID']);
+ }
+ }
+
+ $sitemapFile->createIndex($arFiles);
+
+ $arExistedSitemaps = array();
+
+ if($arSitemap['SETTINGS']['ROBOTS'] == 'Y')
+ {
+ $sitemapUrl = $sitemapFile->getUrl();
+
+ $robotsFile = new RobotsFile($arSitemap['SITE_ID']);
+ $robotsFile->addRule(
+ array(RobotsFile::SITEMAP_RULE, $sitemapUrl)
+ );
+
+ $arSitemapLinks = $robotsFile->getRules(RobotsFile::SITEMAP_RULE);
+ if(count($arSitemapLinks) > 1) // 1 - just added rule
+ {
+ foreach($arSitemapLinks as $rule)
+ {
+ if($rule[1] != $sitemapUrl)
+ {
+ $arExistedSitemaps[] = $rule[1];
+ }
+ }
+ }
+ }
+
+ $v = $arValueSteps['index'];
+ }
+
+ if($v == $arValueSteps['index'])
+ {
+ SitemapTable::update($ID, array('DATE_RUN' => new Bitrix\Main\Type\DateTime()));
+ }
+
+ print $msg.' '.'SEO_SITEMAP_RUN_TITLE'.' '.$v."\n";
+
+ if($v < $arValueSteps['index'])
+ {
+ if(isset($NS['IBLOCK_MAP']))
+ {
+ $SESSION["SEO_SITEMAP_".$PID] = $NS['IBLOCK_MAP'];
+ unset($NS['IBLOCK_MAP']);
+ }
+ }
+
+ return $v;
+}
+
+if(!in_array("simulate", $GLOBALS['argv']))
+{
+ $v = 0;
+ while($v < 100)
+ {
+ $v = generate($v);
+ }
+}
+
+/* sitemap regen end -------------------------------------------------------------*/
+
+
+
+/* sitemap catalog file start -------------------------------------------------------------*/
+
+if(!in_array("simulate", $GLOBALS['argv']))
+{
+ $sitemap_catalog = [];
+
+ $sitemap_all_brands_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_BRANDS, ], false, false, [ "CODE", "PROPERTY_UID" ] );
+ while($sitemap_all_brands_search_ob = $sitemap_all_brands_search_res->GetNextElement())
+ {
+ $brand = $sitemap_all_brands_search_ob->GetFields();
+ $brand['MODELS'] = [];
+
+ $sitemap_catalog[$brand['PROPERTY_UID_VALUE']] = $brand;
+ }
+
+ $sitemap_all_models_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, ], false, false, [ "CODE", "PROPERTY_BRAND_UID"] );
+ while($sitemap_all_models_search_ob = $sitemap_all_models_search_res->GetNextElement())
+ {
+ $model = $sitemap_all_models_search_ob->GetFields();
+ $model['PROPERTIES'] = $sitemap_all_models_search_ob->GetProperties();
+
+ array_push($sitemap_catalog[$model['PROPERTY_BRAND_UID_VALUE']]['MODELS'], $model);
+ }
+
+ $url = "https://".SITE_SERVER_NAME."/catalog";
+ $lastmod = date(DATE_W3C);
+
+ $sitemap_catalog_string = "\n\n";
+
+ foreach($sitemap_catalog AS $brand)
+ {
+ $sitemap_catalog_string .= "".$url."/".$brand['CODE']."/"."".$lastmod.""."\n";
+
+ foreach($brand['MODELS'] AS $model)
+ {
+ $sitemap_catalog_string .= "".$url."/".$brand['CODE']."/".$model['CODE']."/"."".$lastmod.""."\n";
+ }
+ }
+
+ //страницы ЛКТ
+ $sitemap_car_search_res = CIBlockElement::GetList( [ "NAME" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, ], false, [], [] );
+ while($sitemap_car_search_ob = $sitemap_car_search_res->GetNextElement())
+ {
+ $car_existed = $sitemap_car_search_ob->GetFields();
+ $sitemap_catalog_string .= "https://".SITE_SERVER_NAME.$car_existed['DETAIL_PAGE_URL']."".$lastmod.""."\n";
+ }
+
+ $BODIES = [];
+ $ENGINE_FUELS = [];
+
+ //страницы кузов
+ $sitemap_bodies_search_res = CIBlockElement::GetList( [ "NAME" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_BODIES, ], false, [], [] );
+ while($sitemap_bodies_search_ob = $sitemap_bodies_search_res->GetNextElement())
+ {
+ $body = $sitemap_bodies_search_ob->GetFields();
+ $body['PROPERTIES'] = $sitemap_bodies_search_ob->GetProperties();
+
+ $sitemap_catalog_string .= "https://".SITE_SERVER_NAME."/catalog/".$body['DETAIL_PAGE_URL']."".$lastmod.""."\n";
+ if($body['PROPERTIES']['META_SEO_INDEXED_REGIONS']['VALUE_XML_ID'] === "YES")
+ {
+ array_push($BODIES, $body['DETAIL_PAGE_URL']);
+ }
+ }
+
+ //страницы двигатель
+ $sitemap_engine_fuels_search_res = CIBlockElement::GetList( [ "NAME" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_ENGINE_FUELS, ], false, [], [] );
+ while($sitemap_engine_fuels_search_ob = $sitemap_engine_fuels_search_res->GetNextElement())
+ {
+ $engine = $sitemap_engine_fuels_search_ob->GetFields();
+ $engine['PROPERTIES'] = $sitemap_engine_fuels_search_ob->GetProperties();
+
+ $sitemap_catalog_string .= "https://".SITE_SERVER_NAME."/catalog/".$engine['DETAIL_PAGE_URL']."".$lastmod.""."\n";
+ if($engine['PROPERTIES']['META_SEO_INDEXED_REGIONS']['VALUE_XML_ID'] === "YES")
+ {
+ array_push($ENGINE_FUELS, $engine['DETAIL_PAGE_URL']);
+ }
+ }
+
+
+ $sitemap_catalog_string .= ""."\n";
+
+ file_put_contents("/home/bitrix/www/sitemap-catalog.xml", $sitemap_catalog_string);
+
+ $chunk = "https://www.evoleasing.ru/sitemap-catalog.xml".date(DATE_W3C)."";
+
+ $sitemap_index = file_get_contents("/home/bitrix/www/sitemap.xml");
+ $sitemap_index = str_replace(">", ">\n", $sitemap_index);
+ $sitemap_index = str_replace("", $chunk, $sitemap_index);
+ $sitemap_index = str_replace("\n", "", $sitemap_index);
+ file_put_contents("/home/bitrix/www/sitemap.xml", $sitemap_index);
+
+ /* sitemap catalog file end -------------------------------------------------------------*/
+
+ /* sitemap regions file start -------------------------------------------------------------*/
+
+ $sitemap_regions = [];
+ $sitemap_brands = [];
+
+ //IBLOCK_ID_CITIES
+ $sitemap_all_cities_search_res = CIBlockElement::GetList( [ "NAME" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_CITIES, ], false, false, [ "CODE", ] );
+ while($sitemap_all_cities_search_ob = $sitemap_all_cities_search_res->GetNextElement())
+ {
+ $city = $sitemap_all_cities_search_ob->GetFields();
+ $sitemap_regions[] = $city['CODE'];
+ }
+
+ $sitemap_all_brands_search_res = CIBlockElement::GetList( [ "NAME" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_BRANDS, ], false, false, [ "CODE", "PROPERTY_UID" ] );
+ while($sitemap_all_brands_search_ob = $sitemap_all_brands_search_res->GetNextElement())
+ {
+ $brand = $sitemap_all_brands_search_ob->GetFields();
+ $brand['MODELS'] = [];
+
+ $sitemap_brands[$brand['PROPERTY_UID_VALUE']] = $brand;
+ }
+
+ $sitemap_all_models_search_res = CIBlockElement::GetList( [], [ "IBLOCK_ID" => IBLOCK_ID_MODELS, "PROPERTY_PROMO_VALUE" => "Да" ], false, false, [ "CODE", "PROPERTY_BRAND_UID"] );
+ while($sitemap_all_models_search_ob = $sitemap_all_models_search_res->GetNextElement())
+ {
+ $model = $sitemap_all_models_search_ob->GetFields();
+ $model['PROPERTIES'] = $sitemap_all_models_search_ob->GetProperties();
+
+ array_push($sitemap_brands[$model['PROPERTY_BRAND_UID_VALUE']]['MODELS'], $model);
+ }
+
+ $url = "https://".SITE_SERVER_NAME."/regions";
+ $lastmod = date(DATE_W3C);
+
+ $sitemap_regions_string = "\n\n";
+ $sitemap_regions_string .= "".$url."/"."".$lastmod.""."\n";
+
+ foreach($sitemap_regions AS $city)
+ {
+ $sitemap_regions_string .= "".$url."/".$city."/"."".$lastmod.""."\n";
+
+ foreach($sitemap_brands AS $brand)
+ {
+ $sitemap_regions_string .= "".$url."/".$city."/".$brand['CODE']."/"."".$lastmod.""."\n";
+
+ foreach($brand['MODELS'] AS $model)
+ {
+ $sitemap_regions_string .= "".$url."/".$city."/".$brand['CODE']."/".$model['CODE']."/"."".$lastmod.""."\n";
+ }
+ }
+
+ foreach($BODIES AS $body_slug)
+ {
+ $sitemap_regions_string .= "".$url."/".$city."/".$body_slug."".$lastmod.""."\n";
+ }
+
+ foreach($ENGINE_FUELS AS $engine_slug)
+ {
+ $sitemap_regions_string .= "".$url."/".$city."/".$engine_slug."".$lastmod.""."\n";
+ }
+ }
+
+ $sitemap_regions_string .= ""."\n";
+
+ file_put_contents("/home/bitrix/www/sitemap-regions.xml", $sitemap_regions_string);
+
+ $chunk = "https://www.evoleasing.ru/sitemap-regions.xml".date(DATE_W3C)."";
+
+ $sitemap_index = file_get_contents("/home/bitrix/www/sitemap.xml");
+ $sitemap_index = str_replace(">", ">\n", $sitemap_index);
+ $sitemap_index = str_replace("", $chunk, $sitemap_index);
+ $sitemap_index = str_replace("\n", "", $sitemap_index);
+ file_put_contents("/home/bitrix/www/sitemap.xml", $sitemap_index);
+}
+
+/* sitemap regions file end -------------------------------------------------------------*/
+
+if(!in_array("simulate", $GLOBALS['argv']))
+{
+ \Bitrix\Main\Mail\Event::send([
+ "EVENT_NAME" => "ILSA_UPDATE",
+ "LID" => "s1",
+ "C_FIELDS" => Array(
+ "MESSAGE" => $traceback_message,
+ )
+ ]);
+}
+
+//print "----------bitrix_enabled_modifications----------\n";
+//print_r($bitrix_enabled_modifications);
+//print "--------------------\n";
+
+print "-----current_representation-----\n\n";
+print_r($current_representation);
+
+foreach($current_representation AS $brand_uid => $brand)
+{
+ $brand_update = false;
+
+ foreach($brand['MODELS'] AS $model_uid => $model)
+ {
+ $model_update = false;
+
+ foreach($model['MODIFICATIONS'] AS $modification_code => $modification)
+ {
+ if($modification['STATUS'] !== "exists")
+ {
+ $model_update = true;
+
+ elasticIndex("events_cars_test", [
+ "brand" => $brand['NAME'],
+ "model" => $model['NAME'],
+ "modification" => $modification['NAME'],
+ "status" => $modification['STATUS'],
+ ]);
+ }
+ }
+
+ if($model_update)
+ {
+ $brand_update = true;
+
+ elasticIndex("events_cars_test", [
+ "brand" => $brand['NAME'],
+ "model" => $model['NAME'],
+ "status" => $model['STATUS'],
+ ]);
+ }
+ }
+
+ if($brand_update)
+ {
+ elasticIndex("events_cars_test", [
+ "brand" => $brand['NAME'],
+ "status" => $brand['STATUS'],
+ ]);
+ }
+}
+
+//print "-----current_representation-----\n\n";
+//foreach($current_representation AS $k => $v)
+//{
+// print "[ ".$k." ]\n";
+//}
+
+/*
+print "-----bitrix_existed_brands\n\n";
+print_r($bitrix_existed_brands);
+
+print "-----bitrix_enabled_brands\n\n";
+print_r($bitrix_enabled_brands);
+
+print "-----bitrix_hidden_brands\n\n";
+print_r($bitrix_hidden_brands);
+*/
+
+die();
+
+?>
\ No newline at end of file