Commit 7aaeda8eaf1a007f756e931e3107c90a24fd0302

Authored by Mihail
1 parent 93e39994

add getKeys from Importer for parsing settings

backend/controllers/ParserController.php
... ... @@ -278,13 +278,18 @@ class ParserController extends BaseController
278 278 {
279 279 // $comand = "/usr/bin/php -f ".Yii::getAlias('@console') ."/Controllers/ParserController.php";
280 280 // exec($comand);
  281 +
281 282 if( $arr_id_files = Yii::$app->cache->get( 'files_to_parse' ) ) {
282 283 $arr_id_files = json_decode( $arr_id_files );
283 284 foreach ( $arr_id_files as $file_name ) {
  285 +
  286 + $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id;
  287 + $keys = Importers::findOne( ['id' => $importer_id] )->keys;
  288 +
284 289 $file_path = Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv';
285 290 $config = ['record_id' => $file_name,
286   - 'importer_id' => ImportersFiles::findOne(['id' => $file_name])->id,
287   - 'parser_config' => ['keys' => ['DESCR', 'ARTICLE', 'BRAND', 'PRICE', 'BOX'],
  291 + 'importer_id' => $importer_id,
  292 + 'parser_config' => ['keys' => $keys,
288 293 'mode' => 'console']
289 294 ];
290 295 if( $this->parseFileConsole( $file_path, $config ) ){
... ...
backend/models/Importers.php
... ... @@ -82,5 +82,35 @@ class Importers extends BaseActiveRecord
82 82 }
83 83  
84 84  
  85 + public function getKeys ()
  86 + {
  87 + // возьмем только поля описанные в fields() - там как раз наши настройки парсера
  88 + $arr = $this->toArray();
  89 + // отсортируем по ключам с учетом преобразования в число
  90 + asort($arr, SORT_NUMERIC);
  91 + // уберем нулевые колонки
  92 + $arr = array_filter($arr, function($val){
  93 + return $val <> '0';
  94 + });
  95 + // нам нужны именно ключи
  96 + $arr = array_keys($arr);
  97 + return $arr;
  98 +
  99 + }
  100 +
  101 + public function fields()
  102 + {
  103 + return [
  104 + 'BRAND' => 'PARSER_FIELD_BRAND',
  105 + 'ARTICLE' => 'PARSER_FIELD_ARTICLE',
  106 + 'PRICE' => 'PARSER_FIELD_PRICE',
  107 + 'DESCR' => 'PARSER_FIELD_DESCR',
  108 + 'BOX' => 'PARSER_FIELD_BOX',
  109 + 'ADD_BOX' => 'PARSER_FIELD_ADD_BOX',
  110 + 'GROUP_RG' => 'PARSER_FIELD_GROUP_RG'
  111 + ];
  112 +
  113 + }
  114 +
85 115  
86 116 }
... ...