From 7aaeda8eaf1a007f756e931e3107c90a24fd0302 Mon Sep 17 00:00:00 2001 From: Mihail Date: Thu, 1 Oct 2015 13:37:38 +0300 Subject: [PATCH] add getKeys from Importer for parsing settings --- backend/controllers/ParserController.php | 9 +++++++-- backend/models/Importers.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/backend/controllers/ParserController.php b/backend/controllers/ParserController.php index e995fc6..5b3fbf5 100644 --- a/backend/controllers/ParserController.php +++ b/backend/controllers/ParserController.php @@ -278,13 +278,18 @@ class ParserController extends BaseController { // $comand = "/usr/bin/php -f ".Yii::getAlias('@console') ."/Controllers/ParserController.php"; // exec($comand); + if( $arr_id_files = Yii::$app->cache->get( 'files_to_parse' ) ) { $arr_id_files = json_decode( $arr_id_files ); foreach ( $arr_id_files as $file_name ) { + + $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id; + $keys = Importers::findOne( ['id' => $importer_id] )->keys; + $file_path = Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv'; $config = ['record_id' => $file_name, - 'importer_id' => ImportersFiles::findOne(['id' => $file_name])->id, - 'parser_config' => ['keys' => ['DESCR', 'ARTICLE', 'BRAND', 'PRICE', 'BOX'], + 'importer_id' => $importer_id, + 'parser_config' => ['keys' => $keys, 'mode' => 'console'] ]; if( $this->parseFileConsole( $file_path, $config ) ){ diff --git a/backend/models/Importers.php b/backend/models/Importers.php index 2763c0d..8c0b581 100644 --- a/backend/models/Importers.php +++ b/backend/models/Importers.php @@ -82,5 +82,35 @@ class Importers extends BaseActiveRecord } + public function getKeys () + { + // возьмем только поля описанные в fields() - там как раз наши настройки парсера + $arr = $this->toArray(); + // отсортируем по ключам с учетом преобразования в число + asort($arr, SORT_NUMERIC); + // уберем нулевые колонки + $arr = array_filter($arr, function($val){ + return $val <> '0'; + }); + // нам нужны именно ключи + $arr = array_keys($arr); + return $arr; + + } + + public function fields() + { + return [ + 'BRAND' => 'PARSER_FIELD_BRAND', + 'ARTICLE' => 'PARSER_FIELD_ARTICLE', + 'PRICE' => 'PARSER_FIELD_PRICE', + 'DESCR' => 'PARSER_FIELD_DESCR', + 'BOX' => 'PARSER_FIELD_BOX', + 'ADD_BOX' => 'PARSER_FIELD_ADD_BOX', + 'GROUP_RG' => 'PARSER_FIELD_GROUP_RG' + ]; + + } + } -- libgit2 0.21.4