From 9009e1b58a0140db1613d51531e86e98af09a688 Mon Sep 17 00:00:00 2001 From: Mihail Date: Wed, 21 Oct 2015 14:11:22 +0300 Subject: [PATCH] fixed issue with xml parser - redid in universul manner --- backend/controllers/ParserController.php | 3 ++- backend/models/UploadFileParsingForm.php | 8 +++++--- common/components/parsers/config.php | 42 ++++++++++++++++++++++++++++++------------ 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/backend/controllers/ParserController.php b/backend/controllers/ParserController.php index 7854d4f..3a386b8 100644 --- a/backend/controllers/ParserController.php +++ b/backend/controllers/ParserController.php @@ -52,6 +52,8 @@ 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; @@ -81,7 +83,6 @@ class ParserController extends BaseController try { $files_model->save(); } catch (ErrorException $e) { - // CustomVarDamp::dump($e->getMessage()); throw $e; } // получим id только что записанной записи - его запишем в название файла diff --git a/backend/models/UploadFileParsingForm.php b/backend/models/UploadFileParsingForm.php index 165d7a1..aeac2d0 100644 --- a/backend/models/UploadFileParsingForm.php +++ b/backend/models/UploadFileParsingForm.php @@ -71,12 +71,14 @@ class UploadFileParsingForm extends Model public function readFile( $options = [] ){ $data = Yii::$app->multiparser->parse( $this->file_path, $options ); - if( !is_array( $data ) ){ + CustomVarDamp::dumpAndDie($data); + if( !is_array( $data ) || count($data) == 0 ){ throw new ErrorException("Ошибка чтения из файла прайса {$this->file_path}"); } // файл больше не нужен - данные прочитаны и сохранены в кеш -// if( file_exists($this->file_path) ) -// unlink($this->file_path); + if( file_exists($this->file_path) ) + //@ todo - перестало работать - нет доступа на удалениев этом сеансе, в следующем - файл удаляется - разобраться + //unlink( $this->file_path ); return $data; } diff --git a/common/components/parsers/config.php b/common/components/parsers/config.php index 8f2382f..704b901 100644 --- a/common/components/parsers/config.php +++ b/common/components/parsers/config.php @@ -14,7 +14,6 @@ 'hasHeaderRow' => true, 'converter_conf' => [ 'class' => ' common\components\parsers\CustomConverter', - 'hasKey' => 1, 'configuration' => ["string" => 'DESCR', "float" => 'PRICE', "brand" => 'BRAND', @@ -54,21 +53,40 @@ ['console' => ['class' => 'yii\multiparser\XmlParser', 'node' => 'Товар', + 'hasHeaderRow' => true, + 'keys' => [ + "BRAND" => 'Производитель', + "ARTICLE"=> 'Код', + "PRICE" => 'Розница', + "DESCR" => 'Наименование', + "BOX" => 'Колво', + "ADD_BOX"=> 'Ожидаемое', + "GROUP" => 'Группа' + ], 'converter_conf' => [ - 'class' => ' common\components\parsers\CustomConverter', - 'hasKey' => 1, + 'class' => 'common\components\parsers\CustomConverter', 'configuration' => ["details" => [] ],], ], - 'basic_column' => [ - "BRAND" => 'Производитель', - "ARTICLE"=> 'Код', - "PRICE" => 'Розница', - "DESCR" => 'Наименование', - "BOX" => 'Колво', - "ADD_BOX"=> 'Ожидаемое', - "GROUP" => 'Группа' - ], + '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" => [] + ],], + ], ], + ]; -- libgit2 0.21.4