pass ILSA update data to elasticsearch

This commit is contained in:
merelendor 2024-07-31 21:22:58 +03:00
parent d1e32d3076
commit 8c4feda814
2 changed files with 2814 additions and 51 deletions

View File

@ -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(["&quot;", " ", "+"], ['"', "-", "-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;

2595
local/ilsa_update_dev.php Normal file

File diff suppressed because it is too large Load Diff