diff --git a/backend/controllers/ParserController.php b/backend/controllers/ParserController.php index 3a386b8..7ae4546 100644 --- a/backend/controllers/ParserController.php +++ b/backend/controllers/ParserController.php @@ -52,8 +52,6 @@ class ParserController extends BaseController public function actionIndex($mode = 0) { -// $path = 'common\components\parsers\CustomConverter'; -// CustomVarDamp::dumpAndDie(new $path()); $model = new UploadFileParsingForm(); // установим режим, 0 - ручная загрузка, 1 - автозагрузка $model->mode = $mode; diff --git a/backend/models/UploadFileParsingForm.php b/backend/models/UploadFileParsingForm.php index aeac2d0..3832072 100644 --- a/backend/models/UploadFileParsingForm.php +++ b/backend/models/UploadFileParsingForm.php @@ -48,7 +48,7 @@ class UploadFileParsingForm extends Model return [ ['importer_id', 'required', 'message' => 'Не указан поставщик!' ], ['file', 'required', 'message' => 'Не выбран файл!' ], - [['file'], 'file', 'extensions' => ['csv', 'xml'], 'checkExtensionByMimeType'=>false ], + [['file'], 'file', 'extensions' => ['csv', 'xlsx'], 'checkExtensionByMimeType'=>false ], ['importer_id', 'integer','max' => 999999, 'min' => 0 ], [['action','delete_prefix', 'delete_price', 'success'], 'boolean', 'except' => 'auto' ], // только для ручной загрузки ['delimiter', 'string', 'max' => 1], @@ -71,7 +71,6 @@ class UploadFileParsingForm extends Model public function readFile( $options = [] ){ $data = Yii::$app->multiparser->parse( $this->file_path, $options ); - CustomVarDamp::dumpAndDie($data); if( !is_array( $data ) || count($data) == 0 ){ throw new ErrorException("Ошибка чтения из файла прайса {$this->file_path}"); } diff --git a/common/components/PriceWriter.php b/common/components/PriceWriter.php index d6b27a5..cb6ab17 100644 --- a/common/components/PriceWriter.php +++ b/common/components/PriceWriter.php @@ -91,7 +91,7 @@ class PriceWriter try { //@todo add transaction - if ((int)$this->configuration['delete_price']) { + if ( isset($this->configuration['delete_price']) && (int)$this->configuration['delete_price'] ) { $details_model->delete_price = true; } //2. попытаемся вставить данные в БД с апдейтом по ключам diff --git a/common/components/parsers/config.php b/common/components/parsers/config.php index 704b901..7e25bdf 100644 --- a/common/components/parsers/config.php +++ b/common/components/parsers/config.php @@ -68,25 +68,15 @@ 'configuration' => ["details" => [] ],], ], - 'web' => - ['class' => 'yii\multiparser\XmlParser', - 'node' => 'Товар', - 'hasHeaderRow' => true, - 'keys' => [ - "BRAND" => 'Производитель', - "ARTICLE"=> 'Код', - "PRICE" => 'Розница', - "DESCR" => 'Наименование', - "BOX" => 'Колво', - "ADD_BOX"=> 'Ожидаемое', - "GROUP" => 'Группа' - ], - 'converter_conf' => [ - 'class' => 'common\components\parsers\CustomConverter', - 'configuration' => ["details" => [] - ],], - ], ], - + 'xlsx' => + ['web' => + ['class' => 'yii\multiparser\XlsxParser', + 'path_for_extract_files' => \Yii::getAlias('@temp_upload') . '/', + 'converter_conf' => [ + 'class' => 'common\components\parsers\CustomConverter', + 'configuration' => ["encode" => 'DESCR'],] + ], + ] ]; diff --git a/console/.gitignore b/console/.gitignore index 16203a8..bb46adf 100644 --- a/console/.gitignore +++ b/console/.gitignore @@ -1 +1,2 @@ -/old_migrations \ No newline at end of file +/old_migrations +/runtime \ No newline at end of file diff --git a/console/controllers/ParserController.php b/console/controllers/ParserController.php index cd04973..4ec57f5 100644 --- a/console/controllers/ParserController.php +++ b/console/controllers/ParserController.php @@ -59,8 +59,7 @@ class ParserController extends Controller } $data = \Yii::$app->multiparser->parse( $file_path, $parser_config ); if ( ! $data ) { - // @todo переделать, что бы ошибка автоматически останавливала сценарий - return false; + throw new ErrorException("Ошибка обработки файла прайса!"); } $writer = new PriceWriter(); @@ -105,7 +104,7 @@ class ParserController extends Controller ]; if ($this->parseFileConsole($file_path, $config)) { - unlink(\Yii::getAlias('@auto_upload') . '/' . $file_name . '.xml'); + //unlink(\Yii::getAlias('@auto_upload') . '/' . $file_name . '.xml'); \Yii::info("Загрузка файла - $file_path успешно завершена", 'parser'); } else { \Yii::error("Загрузка файла - $file_path завершена с ошибкой", 'parser'); diff --git a/console/runtime/.gitignore b/console/runtime/.gitignore index c96a04f..96b05bb 100644 --- a/console/runtime/.gitignore +++ b/console/runtime/.gitignore @@ -1,2 +1,2 @@ -* +/logs !.gitignore \ No newline at end of file -- libgit2 0.21.4