From 3da8b25f470f1b7624991e13f878e72653e5a937 Mon Sep 17 00:00:00 2001 From: Mihail Date: Fri, 16 Oct 2015 14:54:45 +0300 Subject: [PATCH] fixed issues with details trigger and with remove prefix func --- backend/controllers/ParserController.php | 4 +++- common/components/parsers/CustomConverter.php | 10 ++++++---- common/components/parsers/config.php | 4 ++-- console/migrations/m151016_090927_editDetailsTrigger.php | 4 ++-- vendor/yiisoft/multiparser/Converter.php | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/controllers/ParserController.php b/backend/controllers/ParserController.php index c035606..cfcce21 100644 --- a/backend/controllers/ParserController.php +++ b/backend/controllers/ParserController.php @@ -200,7 +200,9 @@ class ParserController extends BaseController Yii::$app->getCache()->delete('parser_data'); Yii::$app->getCache()->delete('parser_configuration'); - unlink($configuration['file_path']); + if( file_exists($configuration['file_path']) ) + unlink($configuration['file_path']); + return $this->render('index', ['model' => $configuration]); }; diff --git a/common/components/parsers/CustomConverter.php b/common/components/parsers/CustomConverter.php index c865bbc..e233f87 100644 --- a/common/components/parsers/CustomConverter.php +++ b/common/components/parsers/CustomConverter.php @@ -18,6 +18,7 @@ class CustomConverter extends Converter public static $sign; public static $multiplier; public static $importer_id; + public static $brand; public static function convertToAssocArray(array $value_arr, array $key_array, $key_prefix = '') { @@ -160,11 +161,12 @@ class CustomConverter extends Converter if( isset( $row['BRAND'] ) && isset( self::$importer_id ) ){ // 2. Уберем брендовый префикс (если он есть) + self::$brand = $row['BRAND']; $prefix = ''; // запрос закешируем - $prefix = ImportersPrefix::getDb()->cache( function ($db, $configuration, $row ) { + $prefix = ImportersPrefix::getDb()->cache( function ($db) { return ImportersPrefix::find()->where([ 'importer_id' => self::$importer_id, - 'brand' => $row['BRAND'] ])->one(); + 'brand' => self::$brand ])->one(); }); if ($prefix) { @@ -187,7 +189,7 @@ class CustomConverter extends Converter public static function convertToBrand($value) { - $res = $value; + $res = parent::convertToEncode($value);; $res = trim(strtoupper($res)); $res = str_replace("Ä", "A", str_replace("Ö", "O", str_replace("Ü", "U", str_replace("Ë", "E", str_replace("Ò", "O", $res))))); $res = str_replace(array('@', '#', '~', '"', "'", "?", "!"), '', $res); @@ -197,7 +199,7 @@ class CustomConverter extends Converter public static function convertToString($value) { - $value = parent::convertToString($value); + $value = parent::convertToEncode($value); return str_replace(array('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '-', '~', '`', '"', "'", ' ', '№', '%', ';', ':', '[', ']', '{', '}', '*', '?', '/', '\'', '|', '.', ',', '<', '>', '\\'), '', $value); } diff --git a/common/components/parsers/config.php b/common/components/parsers/config.php index 66ffb58..0d74c94 100644 --- a/common/components/parsers/config.php +++ b/common/components/parsers/config.php @@ -5,8 +5,8 @@ ['class' => 'common\components\parsers\CustomCsvParser', 'auto_detect_first_line' => true, 'converter_conf' => [ - //'class' => ' common\components\parsers\CustomConverter', // @todo переделать на подключаемый behavior - 'configuration' => ["string" => 'DESCR'],] + //'class' => ' common\components\parsers\CustomConverter', // @todo переделать на компонент + 'configuration' => ["encode" => 'DESCR'],] ], 'console' => ['class' => 'common\components\parsers\CustomCsvParser', diff --git a/console/migrations/m151016_090927_editDetailsTrigger.php b/console/migrations/m151016_090927_editDetailsTrigger.php index 70abd57..2b58258 100644 --- a/console/migrations/m151016_090927_editDetailsTrigger.php +++ b/console/migrations/m151016_090927_editDetailsTrigger.php @@ -41,9 +41,9 @@ class m151016_090927_editDetailsTrigger extends Migration SET vBrand = ''; - SELECT to_name, to_brand INTO vArticle, vBrand from w_details_replace where from_name = NEW.ARTICLE AND from_brand = NEW.BRAND; + SELECT to_name, to_brand INTO vArticle, vBrand from w_details_replace where from_name = NEW.ARTICLE AND from_brand = NEW.BRAND LIMIT 1; - IF vArticle != '' AND vArticle != NULL then + IF vArticle != '' then SET NEW.BRAND = vBrand; SET NEW.ARTICLE = vArticle; end if; diff --git a/vendor/yiisoft/multiparser/Converter.php b/vendor/yiisoft/multiparser/Converter.php index c6065c3..dd5ae42 100644 --- a/vendor/yiisoft/multiparser/Converter.php +++ b/vendor/yiisoft/multiparser/Converter.php @@ -50,7 +50,7 @@ class Converter extends Behavior return $value; } - public static function convertToString($value) + public static function convertToEncode($value) { $res = $value; if (is_array($value)) { -- libgit2 0.21.4