Commit 3be5e21403734329ffd29659f8e918bcaf438a73

Authored by Mihail
1 parent 4d44bf04

fixed issues with details trigger and with remove prefix func

backend/controllers/ParserController.php
@@ -200,7 +200,9 @@ class ParserController extends BaseController @@ -200,7 +200,9 @@ class ParserController extends BaseController
200 Yii::$app->getCache()->delete('parser_data'); 200 Yii::$app->getCache()->delete('parser_data');
201 Yii::$app->getCache()->delete('parser_configuration'); 201 Yii::$app->getCache()->delete('parser_configuration');
202 202
203 - unlink($configuration['file_path']); 203 + if( file_exists($configuration['file_path']) )
  204 + unlink($configuration['file_path']);
  205 +
204 return $this->render('index', ['model' => $configuration]); 206 return $this->render('index', ['model' => $configuration]);
205 207
206 }; 208 };
common/components/parsers/CustomConverter.php
@@ -18,6 +18,7 @@ class CustomConverter extends Converter @@ -18,6 +18,7 @@ class CustomConverter extends Converter
18 public static $sign; 18 public static $sign;
19 public static $multiplier; 19 public static $multiplier;
20 public static $importer_id; 20 public static $importer_id;
  21 + public static $brand;
21 22
22 public static function convertToAssocArray(array $value_arr, array $key_array, $key_prefix = '') 23 public static function convertToAssocArray(array $value_arr, array $key_array, $key_prefix = '')
23 { 24 {
@@ -160,11 +161,12 @@ class CustomConverter extends Converter @@ -160,11 +161,12 @@ class CustomConverter extends Converter
160 161
161 if( isset( $row['BRAND'] ) && isset( self::$importer_id ) ){ 162 if( isset( $row['BRAND'] ) && isset( self::$importer_id ) ){
162 // 2. Уберем брендовый префикс (если он есть) 163 // 2. Уберем брендовый префикс (если он есть)
  164 + self::$brand = $row['BRAND'];
163 $prefix = ''; 165 $prefix = '';
164 // запрос закешируем 166 // запрос закешируем
165 - $prefix = ImportersPrefix::getDb()->cache( function ($db, $configuration, $row ) { 167 + $prefix = ImportersPrefix::getDb()->cache( function ($db) {
166 return ImportersPrefix::find()->where([ 'importer_id' => self::$importer_id, 168 return ImportersPrefix::find()->where([ 'importer_id' => self::$importer_id,
167 - 'brand' => $row['BRAND'] ])->one(); 169 + 'brand' => self::$brand ])->one();
168 }); 170 });
169 171
170 if ($prefix) { 172 if ($prefix) {
@@ -187,7 +189,7 @@ class CustomConverter extends Converter @@ -187,7 +189,7 @@ class CustomConverter extends Converter
187 189
188 public static function convertToBrand($value) 190 public static function convertToBrand($value)
189 { 191 {
190 - $res = $value; 192 + $res = parent::convertToEncode($value);;
191 $res = trim(strtoupper($res)); 193 $res = trim(strtoupper($res));
192 $res = str_replace("Ä", "A", str_replace("Ö", "O", str_replace("Ü", "U", str_replace("Ë", "E", str_replace("Ò", "O", $res))))); 194 $res = str_replace("Ä", "A", str_replace("Ö", "O", str_replace("Ü", "U", str_replace("Ë", "E", str_replace("Ò", "O", $res)))));
193 $res = str_replace(array('@', '#', '~', '"', "'", "?", "!"), '', $res); 195 $res = str_replace(array('@', '#', '~', '"', "'", "?", "!"), '', $res);
@@ -197,7 +199,7 @@ class CustomConverter extends Converter @@ -197,7 +199,7 @@ class CustomConverter extends Converter
197 199
198 public static function convertToString($value) 200 public static function convertToString($value)
199 { 201 {
200 - $value = parent::convertToString($value); 202 + $value = parent::convertToEncode($value);
201 203
202 return str_replace(array('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '-', '~', '`', '"', "'", ' ', '№', '%', ';', ':', '[', ']', '{', '}', '*', '?', '/', '\'', '|', '.', ',', '<', '>', '\\'), '', $value); 204 return str_replace(array('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '-', '~', '`', '"', "'", ' ', '№', '%', ';', ':', '[', ']', '{', '}', '*', '?', '/', '\'', '|', '.', ',', '<', '>', '\\'), '', $value);
203 } 205 }
common/components/parsers/config.php
@@ -5,8 +5,8 @@ @@ -5,8 +5,8 @@
5 ['class' => 'common\components\parsers\CustomCsvParser', 5 ['class' => 'common\components\parsers\CustomCsvParser',
6 'auto_detect_first_line' => true, 6 'auto_detect_first_line' => true,
7 'converter_conf' => [ 7 'converter_conf' => [
8 - //'class' => ' common\components\parsers\CustomConverter', // @todo переделать на подключаемый behavior  
9 - 'configuration' => ["string" => 'DESCR'],] 8 + //'class' => ' common\components\parsers\CustomConverter', // @todo переделать на компонент
  9 + 'configuration' => ["encode" => 'DESCR'],]
10 ], 10 ],
11 'console' => 11 'console' =>
12 ['class' => 'common\components\parsers\CustomCsvParser', 12 ['class' => 'common\components\parsers\CustomCsvParser',
console/migrations/m151016_090927_editDetailsTrigger.php
@@ -41,9 +41,9 @@ class m151016_090927_editDetailsTrigger extends Migration @@ -41,9 +41,9 @@ class m151016_090927_editDetailsTrigger extends Migration
41 41
42 SET vBrand = ''; 42 SET vBrand = '';
43 43
44 - SELECT to_name, to_brand INTO vArticle, vBrand from w_details_replace where from_name = NEW.ARTICLE AND from_brand = NEW.BRAND; 44 + SELECT to_name, to_brand INTO vArticle, vBrand from w_details_replace where from_name = NEW.ARTICLE AND from_brand = NEW.BRAND LIMIT 1;
45 45
46 - IF vArticle != '' AND vArticle != NULL then 46 + IF vArticle != '' then
47 SET NEW.BRAND = vBrand; 47 SET NEW.BRAND = vBrand;
48 SET NEW.ARTICLE = vArticle; 48 SET NEW.ARTICLE = vArticle;
49 end if; 49 end if;