Commit df6292284e7f8e3742187db08a5f3063d24592cd

Authored by Mihail
1 parent 02d3b386

console csv parsing

backend/components/base/BaseController.php
@@ -45,11 +45,9 @@ class BaseController extends Controller { @@ -45,11 +45,9 @@ class BaseController extends Controller {
45 45
46 46
47 } 47 }
48 - 48 +//
49 // private function resizeImg($w, $h, $filepath,$newfilepath){ 49 // private function resizeImg($w, $h, $filepath,$newfilepath){
50 -// list($orig_width, $orig_height) = getimagesize($filepath);  
51 -// $width = $orig_width;  
52 -// $height = $orig_height; 50 +// list($width, $height) = getimagesize($filepath);
53 // if($width > $height) { 51 // if($width > $height) {
54 // $y = 0; 52 // $y = 0;
55 // $x = ($width - $height) / 2; 53 // $x = ($width - $height) / 2;
@@ -76,7 +74,7 @@ class BaseController extends Controller { @@ -76,7 +74,7 @@ class BaseController extends Controller {
76 { 74 {
77 75
78 $model = new ImageSizerForm(); 76 $model = new ImageSizerForm();
79 - //die(print_r(Yii::$app->request->post())); 77 +
80 if ($model->load(Yii::$app->request->post())) { 78 if ($model->load(Yii::$app->request->post())) {
81 79
82 $model->file = UploadedFile::getInstance($model, 'file'); 80 $model->file = UploadedFile::getInstance($model, 'file');
@@ -85,6 +83,7 @@ class BaseController extends Controller { @@ -85,6 +83,7 @@ class BaseController extends Controller {
85 $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); 83 $imgDir = Yii::getAlias('@storage/'.$md5_file.'/');
86 $imageAlias = Yii::getAlias($imgDir.$model->width.'x'.$model->height.'.'.$model->file->extension); 84 $imageAlias = Yii::getAlias($imgDir.$model->width.'x'.$model->height.'.'.$model->file->extension);
87 $imageLink = '/storage/'.$md5_file.$model->width.'x'.$model->height.'.'.$model->file->extension; 85 $imageLink = '/storage/'.$md5_file.$model->width.'x'.$model->height.'.'.$model->file->extension;
  86 +
88 if(!is_dir($imgDir)) { 87 if(!is_dir($imgDir)) {
89 mkdir($imgDir, 0755, true); 88 mkdir($imgDir, 0755, true);
90 } 89 }
backend/components/views/image_sizer.php
@@ -12,7 +12,7 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl @@ -12,7 +12,7 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl
12 12
13 ?> 13 ?>
14 14
15 -<?= $form->field($model, 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo"]); ?> 15 +<?= $form->field( new \backend\models\ImageSizerForm(), 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo"]); ?>
16 16
17 <?= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?> 17 <?= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?>
18 18
@@ -25,7 +25,7 @@ $this-&gt;registerJsFile(&#39;@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl @@ -25,7 +25,7 @@ $this-&gt;registerJsFile(&#39;@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl
25 25
26 $("#<?= $field?>").fileupload({ 26 $("#<?= $field?>").fileupload({
27 dataType: 'json', 27 dataType: 'json',
28 - formData: { 28 + ImageSizerForm: {
29 height: <?=$height?>, 29 height: <?=$height?>,
30 width: <?= $width?> 30 width: <?= $width?>
31 }, 31 },
backend/config/main.php
@@ -5,7 +5,6 @@ $params = array_merge( @@ -5,7 +5,6 @@ $params = array_merge(
5 require(__DIR__ . '/params.php'), 5 require(__DIR__ . '/params.php'),
6 require(__DIR__ . '/params-local.php') 6 require(__DIR__ . '/params-local.php')
7 ); 7 );
8 -$mp_configuration = require( __DIR__ . '/../components/parsers/config.php');  
9 8
10 return [ 9 return [
11 'id' => 'app-backend', 10 'id' => 'app-backend',
@@ -39,15 +38,7 @@ return [ @@ -39,15 +38,7 @@ return [
39 'adminUrl' => '/admin' 38 'adminUrl' => '/admin'
40 39
41 ], 40 ],
42 - 'multiparser'=>[  
43 41
44 - 'class' => 'yii\multiparser\YiiMultiparser',  
45 - 'configuration' => $mp_configuration,  
46 - 'as behavior' => [  
47 - 'class' => 'backend\components\parsers\CustomConverter',  
48 - ],  
49 -  
50 - ],  
51 ], 42 ],
52 'params' => $params, 43 'params' => $params,
53 ]; 44 ];
backend/controllers/ParserController.php
@@ -117,7 +117,6 @@ class ParserController extends BaseController @@ -117,7 +117,6 @@ class ParserController extends BaseController
117 // сохраняем в кеш модель - в ней настройки для дальнейшей обработки данных 117 // сохраняем в кеш модель - в ней настройки для дальнейшей обработки данных
118 Yii::$app->getCache()->set('parser_configuration', serialize($model)); 118 Yii::$app->getCache()->set('parser_configuration', serialize($model));
119 119
120 -  
121 } else { 120 } else {
122 // не прошла валидация форма загрузки файлов 121 // не прошла валидация форма загрузки файлов
123 //@todo - отправка на страницу ошибок 122 //@todo - отправка на страницу ошибок
@@ -219,11 +218,10 @@ class ParserController extends BaseController @@ -219,11 +218,10 @@ class ParserController extends BaseController
219 218
220 public function actionServerFiles () 219 public function actionServerFiles ()
221 { 220 {
222 -  
223 $arr_id_files = []; 221 $arr_id_files = [];
224 222
225 // получим список файлов которые ожидают к загрузке 223 // получим список файлов которые ожидают к загрузке
226 - foreach ( glob(Yii::getAlias('@temp_upload') . '/*.csv') as $server_file ) { 224 + foreach ( glob(Yii::getAlias('@temp_upload') . '/*.csv' ) as $server_file ) {
227 $file_id = basename($server_file,".csv"); 225 $file_id = basename($server_file,".csv");
228 $arr_id_files[] = (int) $file_id; 226 $arr_id_files[] = (int) $file_id;
229 } 227 }
@@ -265,74 +263,17 @@ class ParserController extends BaseController @@ -265,74 +263,17 @@ class ParserController extends BaseController
265 263
266 public function actionLaunchCroneUploads () 264 public function actionLaunchCroneUploads ()
267 { 265 {
268 -  
269 -  
270 foreach (glob(Yii::getAlias('@temp_upload') . '/*.csv') as $server_file) { 266 foreach (glob(Yii::getAlias('@temp_upload') . '/*.csv') as $server_file) {
271 267
272 $file_name = basename($server_file,".csv"); 268 $file_name = basename($server_file,".csv");
273 - rename( $server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv'); 269 + // rename( $server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv');
  270 + copy( $server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv' );
274 271
275 } 272 }
276 -  
277 - //$this->redirect('server-files');  
278 - $this->actionParseCsv(); 273 + Yii::$app->session->setFlash( 'server-files', 'Файл успешно загружен' );
  274 + $this->redirect('server-files');
279 } 275 }
280 276
281 - public function actionParseCsv ()  
282 - {  
283 - // Console::output('1');  
284 - foreach (glob( \Yii::getAlias('@auto_upload') . '/*.csv' ) as $file_path) {  
285 - $file_name = basename( $file_path,".csv" );  
286 - // Console::output('2');  
287 - $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id;  
288 - $keys = Importers::findOne( ['id' => $importer_id] )->keys;  
289 -  
290 - $config = ['record_id' => $file_name,  
291 - 'importer_id' => $importer_id,  
292 - 'parser_config' => ['keys' => $keys,  
293 - 'mode' => 'console']  
294 - ];  
295 - // Console::output('3');  
296 - if( $this->parseFileConsole( $file_path, $config ) ){  
297 - // Console::output('4');  
298 - unlink( $file_path );  
299 - if (isset( $arr_id_files[$file_path] ) ) {  
300 - unset( $arr_id_files[$file_path] );  
301 - }  
302 - }  
303 - }  
304 -  
305 -  
306 - //return $this->redirect('serverFiles');  
307 - }  
308 277
309 278
310 - protected function parseFileConsole( $file_path, $configuration ){  
311 -  
312 - if( !file_exists( $file_path ) )  
313 - throw new ErrorException("$file_path - файл не найден!");  
314 -  
315 - $parser_config = [];  
316 - if ( isset( $configuration['parser_config'] ) ) {  
317 - $parser_config = $configuration['parser_config'];  
318 - }  
319 - $data = \Yii::$app->multiparser->parse( $file_path, $parser_config );  
320 - if (! $data) {  
321 - // @todo переделать, что бы ошибка автоматически останавливала сценарий  
322 - die;  
323 - }  
324 -  
325 -  
326 - $writer = new PriceWriter();  
327 - $writer->configuration = $configuration;  
328 - $writer->data = $data;  
329 - $writer->mode = 1; //console-режим  
330 - if ( $writer->writeDataToDB() ){  
331 -  
332 - return true;  
333 - }  
334 -  
335 - return false;  
336 - }  
337 -  
338 } 279 }
backend/models/ImageSizerForm.php
@@ -13,6 +13,11 @@ class ImageSizerForm extends Model @@ -13,6 +13,11 @@ class ImageSizerForm extends Model
13 * @var UploadedFile file attribute 13 * @var UploadedFile file attribute
14 */ 14 */
15 public $file; 15 public $file;
  16 + public $width;
  17 + public $height;
  18 + public $field;
  19 + public $model;
  20 + public $form;
16 21
17 /** 22 /**
18 * @return array the validation rules. 23 * @return array the validation rules.
backend/views/parser/server-files.php
@@ -19,6 +19,7 @@ Pjax::begin([&#39;id&#39; =&gt; &#39;server_files_grid&#39;]); @@ -19,6 +19,7 @@ Pjax::begin([&#39;id&#39; =&gt; &#39;server_files_grid&#39;]);
19 19
20 ?> 20 ?>
21 <div class="catalog-index"> 21 <div class="catalog-index">
  22 + <?= Html::tag('h3', \Yii::$app->session->setFlash( 'server-files'),['class'=>'bg-success'])?>
22 23
23 <h1><?= Html::encode($this->title) ?></h1> 24 <h1><?= Html::encode($this->title) ?></h1>
24 25
common/components/PriceWriter.php
@@ -34,9 +34,8 @@ class PriceWriter { @@ -34,9 +34,8 @@ class PriceWriter {
34 34
35 // 2. запишем полученные данные в таблицу товаров (Details) 35 // 2. запишем полученные данные в таблицу товаров (Details)
36 $details_model = new Details(); 36 $details_model = new Details();
37 -  
38 // только для ручной загрузки, в авто режиме все делает конвертер при первом же проходе (в процессе парсинга) 37 // только для ручной загрузки, в авто режиме все делает конвертер при первом же проходе (в процессе парсинга)
39 - if ($this->mode = 0) { 38 + if ($this->mode == 0) {
40 // преобразуем числовые значения 39 // преобразуем числовые значения
41 foreach ($this->data as &$row) { 40 foreach ($this->data as &$row) {
42 $row['PRICE'] = \Yii::$app->multiparser->convertToFloat($row['PRICE']); 41 $row['PRICE'] = \Yii::$app->multiparser->convertToFloat($row['PRICE']);
@@ -48,7 +47,6 @@ class PriceWriter { @@ -48,7 +47,6 @@ class PriceWriter {
48 47
49 // проверим все ли обязательные колонки были указаны пользователем 48 // проверим все ли обязательные колонки были указаны пользователем
50 $details_model->load(['Details' => $row]); 49 $details_model->load(['Details' => $row]);
51 -  
52 if (!$details_model->validate()) 50 if (!$details_model->validate())
53 //@todo предоставить более детальную информацию об ошибке 51 //@todo предоставить более детальную информацию об ошибке
54 throw new \ErrorException('Ошибка записи товаров'); 52 throw new \ErrorException('Ошибка записи товаров');
@@ -85,4 +83,6 @@ class PriceWriter { @@ -85,4 +83,6 @@ class PriceWriter {
85 83
86 return true; 84 return true;
87 } 85 }
  86 +
  87 +
88 } 88 }
89 \ No newline at end of file 89 \ No newline at end of file
backend/components/parsers/CustomConverter.php renamed to common/components/parsers/CustomConverter.php
backend/components/parsers/CustomCsvParser.php renamed to common/components/parsers/CustomCsvParser.php
@@ -38,7 +38,7 @@ class CustomCsvParser extends \yii\multiparser\CsvParser { @@ -38,7 +38,7 @@ class CustomCsvParser extends \yii\multiparser\CsvParser {
38 */ 38 */
39 protected function convert($arr) 39 protected function convert($arr)
40 { 40 {
41 - $arr = \Yii::$app->multiparser->convertByConfiguration($arr, $this->converter_conf); 41 + $arr = \Yii::$app->multiparser->convertByConfiguration($arr, $this->converter_conf);
42 42
43 return $arr; 43 return $arr;
44 44
backend/components/parsers/MailParser.php renamed to common/components/parsers/MailParser.php
backend/components/parsers/config.php renamed to common/components/parsers/config.php
@@ -7,17 +7,6 @@ @@ -7,17 +7,6 @@
7 'converter_conf' => ['class' => ' backend\components\parsers\CustomConverter', 7 'converter_conf' => ['class' => ' backend\components\parsers\CustomConverter',
8 'configuration' => ["string" => 'DESCR'],] 8 'configuration' => ["string" => 'DESCR'],]
9 ], 9 ],
10 -  
11 - 'basic_column' => [  
12 - Null => 'Пусто',  
13 - "BRAND" => 'Бренд',  
14 - "ARTICLE"=> 'Артикул',  
15 - "PRICE" => 'Цена',  
16 - "DESCR" => 'Наименование',  
17 - "BOX" => 'Колво',  
18 - "ADD_BOX"=> 'В пути',  
19 - "GROUP" => 'Группа RG'  
20 - ],  
21 'console' => 10 'console' =>
22 ['class' => 'backend\components\parsers\CustomCsvParser', 11 ['class' => 'backend\components\parsers\CustomCsvParser',
23 'auto_detect_first_line' => true, 12 'auto_detect_first_line' => true,
@@ -27,13 +16,13 @@ @@ -27,13 +16,13 @@
27 'configuration' => ["string" => 'DESCR', 16 'configuration' => ["string" => 'DESCR',
28 "float" => 'PRICE', 17 "float" => 'PRICE',
29 "integer" => ['BOX','ADD_BOX'], 18 "integer" => ['BOX','ADD_BOX'],
30 - "details" => [], // @todo сделать отдельно конфигурирование валидации  
31 - "integer" => ['BOX','ADD_BOX'] 19 + "details" => [] // @todo сделать отдельно конфигурирование валидации
32 20
33 ] 21 ]
34 ],], 22 ],],
35 23
36 'basic_column' => [ 24 'basic_column' => [
  25 + Null => 'Пусто',
37 "BRAND" => 'Бренд', 26 "BRAND" => 'Бренд',
38 "ARTICLE"=> 'Артикул', 27 "ARTICLE"=> 'Артикул',
39 "PRICE" => 'Цена', 28 "PRICE" => 'Цена',
@@ -47,22 +36,15 @@ @@ -47,22 +36,15 @@
47 ['web' => 36 ['web' =>
48 ['class' => 'yii\multiparser\XmlParser', 37 ['class' => 'yii\multiparser\XmlParser',
49 'node' => 'Товар',], 38 'node' => 'Товар',],
50 -  
51 - 'basic_column' => [  
52 - "BRAND" => 'Производитель',  
53 - "ARTICLE"=> 'Код',  
54 - "PRICE" => 'Розница',  
55 - "DESCR" => 'Наименование',  
56 - "BOX" => 'Колво',  
57 - "ADD_BOX"=> 'Ожидаемое',  
58 - "GROUP" => 'Группа'  
59 - ],  
60 - ] 39 + ],
  40 + 'basic_column' => [
  41 + "BRAND" => 'Производитель',
  42 + "ARTICLE"=> 'Код',
  43 + "PRICE" => 'Розница',
  44 + "DESCR" => 'Наименование',
  45 + "BOX" => 'Колво',
  46 + "ADD_BOX"=> 'Ожидаемое',
  47 + "GROUP" => 'Группа'
  48 + ],
61 ]; 49 ];
62 50
63 -  
64 -//[  
65 -// "float" => 'PRICE',  
66 -// "integer" => ['BOX' , 'ADD_BOX' ],  
67 -// "prefix" => 'ARTICLE'  
68 -//]  
69 \ No newline at end of file 51 \ No newline at end of file
common/config/bootstrap.php
@@ -6,3 +6,4 @@ Yii::setAlias(&#39;console&#39;, dirname(dirname(__DIR__)) . &#39;/console&#39;); @@ -6,3 +6,4 @@ Yii::setAlias(&#39;console&#39;, dirname(dirname(__DIR__)) . &#39;/console&#39;);
6 Yii::setAlias('auto_upload', dirname(dirname(__DIR__)) . '/backend/uploads/auto'); 6 Yii::setAlias('auto_upload', dirname(dirname(__DIR__)) . '/backend/uploads/auto');
7 Yii::setAlias('manual_upload', dirname(dirname(__DIR__)) . '/backend/uploads/manual'); 7 Yii::setAlias('manual_upload', dirname(dirname(__DIR__)) . '/backend/uploads/manual');
8 Yii::setAlias('temp_upload', dirname(dirname(__DIR__)) . '/backend/uploads/temp'); 8 Yii::setAlias('temp_upload', dirname(dirname(__DIR__)) . '/backend/uploads/temp');
  9 +Yii::setAlias('storage', dirname(dirname(__DIR__)) . '/storage');
common/config/main.php
1 <?php 1 <?php
  2 +$mp_configuration = require( __DIR__ . '/../components/parsers/config.php');
2 return [ 3 return [
3 'language' => 'ru-RU', 4 'language' => 'ru-RU',
4 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 5 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
@@ -13,6 +14,15 @@ return [ @@ -13,6 +14,15 @@ return [
13 'module/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>', 14 'module/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
14 ] 15 ]
15 ], 16 ],
  17 + 'multiparser'=>[
  18 +
  19 + 'class' => 'yii\multiparser\YiiMultiparser',
  20 + 'configuration' => $mp_configuration,
  21 + 'as behavior' => [
  22 + 'class' => 'backend\components\parsers\CustomConverter',
  23 + ],
  24 +
  25 + ],
16 ], 26 ],
17 27
18 ]; 28 ];
console/controllers/ParserController.php
@@ -12,60 +12,64 @@ class ParserController extends Controller{ @@ -12,60 +12,64 @@ class ParserController extends Controller{
12 12
13 public function actionParseCsv () 13 public function actionParseCsv ()
14 { 14 {
15 - Console::output('1'); 15 + \Yii::info('Начало загрузки файлов прайсов csv','parser');
16 foreach (glob( \Yii::getAlias('@auto_upload') . '/*.csv' ) as $file_path) { 16 foreach (glob( \Yii::getAlias('@auto_upload') . '/*.csv' ) as $file_path) {
17 - $file_name = basename($file_path,".csv");  
18 - Console::output('2');  
19 - $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id;  
20 - $keys = Importers::findOne( ['id' => $importer_id] )->keys;  
21 -  
22 - $config = ['record_id' => $file_name,  
23 - 'importer_id' => $importer_id,  
24 - 'parser_config' => ['keys' => $keys,  
25 - 'mode' => 'console']  
26 - ];  
27 - Console::output('3');  
28 - if( $this->parseFileConsole( $file_path, $config ) ){  
29 - Console::output('4');  
30 - unlink( $file_path );  
31 - if (isset( $arr_id_files[$file_path] ) ) {  
32 - unset( $arr_id_files[$file_path] );  
33 - }  
34 - }  
35 - } 17 + $file_name = basename( $file_path,".csv" );
  18 + \Yii::info("Обработка файла - $file_path",'parser');
  19 + $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id;
  20 + $keys = Importers::findOne( ['id' => $importer_id] )->keys;
36 21
  22 + $config = ['record_id' => $file_name,
  23 + 'importer_id' => $importer_id,
  24 + 'parser_config' => ['keys' => $keys,
  25 + 'mode' => 'console']
  26 + ];
  27 + if( $this->parseFileConsole( $file_path, $config ) ){
  28 + unlink( \Yii::getAlias('@temp_upload') . '/' . $file_name . '.csv' );
  29 + \Yii::info("Загрузка файла - $file_path успешно завершена",'parser');
  30 + } else{
  31 + \Yii::error( "Загрузка файла - $file_path завершена с ошибкой", 'parser' );
  32 + }
  33 + //при любом завершении скрипта файл с очереди автозагрузки нужно удалить
  34 + unlink( \Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv' );
  35 + }
37 36
38 - //return $this->redirect('serverFiles');  
39 } 37 }
40 38
41 - public function actionParseXml ()  
42 - {  
43 39
44 - }  
45 protected function parseFileConsole( $file_path, $configuration ){ 40 protected function parseFileConsole( $file_path, $configuration ){
46 41
47 if( !file_exists( $file_path ) ) 42 if( !file_exists( $file_path ) )
48 - throw new ErrorException("$file_path does not exist!"); 43 + throw new ErrorException("$file_path - файл не найден!");
49 44
50 $parser_config = []; 45 $parser_config = [];
51 if ( isset( $configuration['parser_config'] ) ) { 46 if ( isset( $configuration['parser_config'] ) ) {
52 $parser_config = $configuration['parser_config']; 47 $parser_config = $configuration['parser_config'];
53 } 48 }
54 -  
55 $data = \Yii::$app->multiparser->parse( $file_path, $parser_config ); 49 $data = \Yii::$app->multiparser->parse( $file_path, $parser_config );
  50 + if (! $data) {
  51 + // @todo переделать, что бы ошибка автоматически останавливала сценарий
  52 + return false;
  53 + }
56 54
57 $writer = new PriceWriter(); 55 $writer = new PriceWriter();
58 $writer->configuration = $configuration; 56 $writer->configuration = $configuration;
59 $writer->data = $data; 57 $writer->data = $data;
60 $writer->mode = 1; //console-режим 58 $writer->mode = 1; //console-режим
  59 +
61 if ( $writer->writeDataToDB() ){ 60 if ( $writer->writeDataToDB() ){
62 - Console::output('It is working'); 61 +
63 return true; 62 return true;
64 } 63 }
65 64
66 return false; 65 return false;
67 } 66 }
68 67
  68 + public function actionParseXml ()
  69 + {
  70 +
  71 + }
  72 +
69 public function actionTest () 73 public function actionTest ()
70 { 74 {
71 Console::output('It is working '); 75 Console::output('It is working ');
console/migrations/m130524_201442_init.php deleted
1 -<?php  
2 -  
3 -use yii\db\Schema;  
4 -use yii\db\Migration;  
5 -  
6 -class m130524_201442_init extends Migration  
7 -{  
8 - public function up()  
9 - {  
10 - $tableOptions = null;  
11 - if ($this->db->driverName === 'mysql') {  
12 - // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci  
13 - $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';  
14 - }  
15 -  
16 - $this->createTable('{{%user}}', [  
17 - 'id' => $this->primaryKey(),  
18 - 'username' => $this->string()->notNull()->unique(),  
19 - 'auth_key' => $this->string(32)->notNull(),  
20 - 'password_hash' => $this->string()->notNull(),  
21 - 'password_reset_token' => $this->string()->unique(),  
22 - 'email' => $this->string()->notNull()->unique(),  
23 -  
24 - 'status' => $this->smallInteger()->notNull()->defaultValue(10),  
25 - 'created_at' => $this->integer()->notNull(),  
26 - 'updated_at' => $this->integer()->notNull(),  
27 - ], $tableOptions);  
28 - }  
29 -  
30 - public function down()  
31 - {  
32 - $this->dropTable('{{%user}}');  
33 - }  
34 -}  
console/migrations/m150818_125718_create_user_180815.php deleted
1 -<?php  
2 -  
3 -  
4 -use yii\db\Schema;  
5 -use yii\db\Migration;  
6 -  
7 -  
8 -class m150818_125718_create_user_180815 extends Migration  
9 -{  
10 - public function up()  
11 - {  
12 -  
13 -  
14 - $user_array = [  
15 - 'username' => 'admin',  
16 - 'auth_key' => 'admin',  
17 - 'password_hash' => Yii::$app->security->generatePasswordHash('admin'),  
18 - 'password_reset_token' => 'admin',  
19 - 'email'=> 'admin@test.com',  
20 - 'status' => '10',  
21 - 'created_at'=>'000000',  
22 - 'updated_at' => '000000'  
23 - ];  
24 - $this->insert('{{%user}}', $user_array);  
25 - }  
26 -  
27 -  
28 -  
29 - public function down()  
30 - {  
31 - $this->dropTable('{{%user}}');  
32 - }  
33 -  
34 - /*  
35 - // Use safeUp/safeDown to run migration code within a transaction  
36 - public function safeUp()  
37 - {  
38 - }  
39 -  
40 - public function safeDown()  
41 - {  
42 - }  
43 - */  
44 -}  
console/migrations/m150831_130250_addImporters.php deleted
1 -<?php  
2 -  
3 -use yii\db\Schema;  
4 -use yii\db\Migration;  
5 -  
6 -class m150831_130250_addImporters extends Migration  
7 -{  
8 - public function up()  
9 - {  
10 - $tableOptions = null;  
11 - if ($this->db->driverName === 'mysql') {  
12 - $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';  
13 - }  
14 -  
15 - $this->createTable('{{%importer}}', [  
16 - 'id' => $this->primaryKey(6)->notNull() . ' AUTO_INCREMENT',  
17 - 'code' =>'varchar(254) NOT NULL',  
18 - 'name' => 'varchar(254) NOT NULL',  
19 - 'name_price' => 'varchar(254) NOT NULL',  
20 - 'currency_id' => 'int(3) unsigned NOT NULL',  
21 - 'delivery' => 'varchar(254) NOT NULL',  
22 - 'email' => 'varchar(254) NOT NULL',  
23 - 'info' => 'text NOT NULL',  
24 - 'active' => 'tinyint(1) unsigned NOT NULL DEFAULT 1',  
25 - 'PARSER_IS_ACTIVE' => 'tinyint(1) unsigned NOT NULL DEFAULT 0',  
26 - 'PARSER_COLUMN_COUNT' => 'int(6) unsigned DEFAULT NULL',  
27 - 'PARSER_FIELD_BRAND' => 'int(3) unsigned DEFAULT NULL',  
28 - 'PARSER_FIELD_ARTICLE' => 'int(3) unsigned DEFAULT NULL',  
29 - 'PARSER_FIELD_ARTICLE_PREFIX' => 'tinyint(1) unsigned NOT NULL DEFAULT 0',  
30 - 'PARSER_FIELD_PRICE' => 'int(3) unsigned DEFAULT NULL',  
31 - 'PARSER_FIELD_DESCR' =>'int(3) unsigned DEFAULT NULL',  
32 - 'PARSER_FIELD_BOX' => 'int(3) unsigned DEFAULT NULL',  
33 - 'PARSER_FIELD_ADD_BOX' => 'int(3) unsigned DEFAULT NULL',  
34 - 'PARSER_FIELD_GROUP_RG' => 'int(3) unsigned DEFAULT NULL',  
35 - 'PARSER_FIELD_SIGN' => 'varchar(1) NOT NULL',  
36 - 'PARSER_FIELD_MULTIPLIER' => 'float(8,2) unsigned DEFAULT NULL',  
37 - 'price_date_update' => 'varchar(15) NOT NULL'  
38 -  
39 - ], $tableOptions);  
40 -  
41 - $this->createIndex('code', '{{%importer}}', 'code', true);  
42 - $this->createIndex('name', '{{%importer}}', 'name', true);  
43 - $this->createIndex('active', '{{%importer}}', 'active', false);  
44 - }  
45 -  
46 - public function down()  
47 - {  
48 - $this->dropTable('{{%importer}}');  
49 -  
50 - }  
51 -  
52 - /*  
53 - // Use safeUp/safeDown to run migration code within a transaction  
54 - public function safeUp()  
55 - {  
56 - }  
57 -  
58 - public function safeDown()  
59 - {  
60 - }  
61 - */  
62 -}  
console/migrations/m150901_135806_addImportersFiles.php deleted
1 -<?php  
2 -  
3 -use yii\db\Schema;  
4 -use yii\db\Migration;  
5 -  
6 -class m150901_135806_addImportersFiles extends Migration  
7 -{  
8 - public function up()  
9 - {  
10 - $tableOptions = null;  
11 - if ($this->db->driverName === 'mysql') {  
12 - $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';  
13 - }  
14 -  
15 - $this->createTable('{{%importer_files}}', [  
16 - 'id' => $this->primaryKey(10)->notNull() . ' AUTO_INCREMENT',  
17 - 'importer_id' => 'int(6) unsigned NOT NULL',  
18 - 'upload_time' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',  
19 - 'time_start' => 'timestamp NULL DEFAULT NULL',  
20 - 'time_end' => 'timestamp NULL DEFAULT NULL',  
21 - ], $tableOptions);  
22 -  
23 -  
24 - $this->createIndex('importer_id', '{{%importer_files}}', 'importer_id, time_start', false);  
25 - }  
26 -  
27 - public function down()  
28 - {  
29 - $this->dropTable('{{%importer_files}}');  
30 - }  
31 -  
32 - /*  
33 - // Use safeUp/safeDown to run migration code within a transaction  
34 - public function safeUp()  
35 - {  
36 - }  
37 -  
38 - public function safeDown()  
39 - {  
40 - }  
41 - */  
42 -}  
console/migrations/m150901_141850_addImportersPrefix.php deleted
1 -<?php  
2 -  
3 -use yii\db\Schema;  
4 -use yii\db\Migration;  
5 -  
6 -class m150901_141850_addImportersPrefix extends Migration  
7 -{  
8 - public function up()  
9 - {  
10 - $tableOptions = null;  
11 - if ($this->db->driverName === 'mysql') {  
12 - $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';  
13 - }  
14 -  
15 - $this->createTable('{{%importer_prefix}}', [  
16 - 'id' => $this->primaryKey(10)->notNull() . ' AUTO_INCREMENT',  
17 - 'importer_id' => 'int(6) unsigned NOT NULL',  
18 - 'brand' => 'varchar(100) NOT NULL',  
19 - 'prefix' => 'varchar(50) NOT NULL',  
20 - 'timestamp' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',  
21 - ], $tableOptions);  
22 -  
23 - $this->createIndex('importer_id', '{{%importer_prefix}}', 'importer_id, brand, prefix', true);  
24 - }  
25 -  
26 - public function down()  
27 - {  
28 - $this->dropTable('{{%importer_prefix}}');  
29 - }  
30 -  
31 - /*  
32 - // Use safeUp/safeDown to run migration code within a transaction  
33 - public function safeUp()  
34 - {  
35 - }  
36 -  
37 - public function safeDown()  
38 - {  
39 - }  
40 - */  
41 -}  
console/migrations/m150915_125129_addDetails.php deleted
1 -<?php  
2 -  
3 -use yii\db\Schema;  
4 -use yii\db\Migration;  
5 -  
6 -class m150915_125129_addDetails extends Migration  
7 -{  
8 - public function up()  
9 - {  
10 - $this->execute('CREATE TABLE `details` (  
11 - `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,  
12 - `IMPORT_ID` int(6) unsigned NOT NULL,  
13 - `BRAND` varchar(100) NOT NULL,  
14 - `ARTICLE` varchar(100) NOT NULL,  
15 - `FULL_ARTICLE` varchar(150) NOT NULL,  
16 - `PRICE` float(15,2) unsigned NOT NULL,  
17 - `DESCR` varchar(200) NOT NULL,  
18 - `BOX` int(6) unsigned NOT NULL,  
19 - `ADD_BOX` int(6) unsigned NOT NULL DEFAULT 0,  
20 - `GROUP` varchar(200) NOT NULL DEFAULT \'\',  
21 - `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,  
22 - PRIMARY KEY (`ARTICLE`,`BRAND`,`IMPORT_ID`),  
23 - UNIQUE KEY `ID_delete` (`ID`),  
24 - KEY `timestamp` (`timestamp`),  
25 - KEY `ARTICLE` (`ARTICLE`,`BRAND`,`BOX`),  
26 - KEY `BRAND` (`BRAND`,`ARTICLE`),  
27 - KEY `ARTICLE_2` (`ARTICLE`,`BRAND`,`ADD_BOX`),  
28 - KEY `IMPORT_ID` (`IMPORT_ID`,`ARTICLE`),  
29 - KEY `IMPORT_ID_2` (`IMPORT_ID`,`timestamp`)  
30 - ) ENGINE=InnoDB DEFAULT CHARSET=utf8');  
31 -  
32 - }  
33 -  
34 - public function down()  
35 - {  
36 - $this->dropTable('{{%details}}');  
37 -  
38 - }  
39 -  
40 -}  
console/migrations/m150922_094313_change_key_ImportFiles.php deleted
1 -<?php  
2 -  
3 -use yii\db\Schema;  
4 -use yii\db\Migration;  
5 -  
6 -class m150922_094313_change_key_ImportFiles extends Migration  
7 -{  
8 - //@todo вероятно что эта миграция ненужна - посмотреть ближе к концу проекта на ключи которые используются - остальные удалить.  
9 - public function up()  
10 - {  
11 - $this->dropIndex('importer_id', '{{%importer_files}}');  
12 - $this->createIndex('importer_id', '{{%importer_files}}', 'importer_id, upload_time', false);  
13 - }  
14 -  
15 - public function down()  
16 - {  
17 - $this->dropIndex('importer_id', '{{%importer_files}}');  
18 - $this->createIndex('importer_id', '{{%importer_files}}', 'importer_id, time_start', false);  
19 - }  
20 -  
21 -  
22 -}  
console/migrations/m150922_144040_change_Importer_dataPrice.php deleted
1 -<?php  
2 -  
3 -use yii\db\Schema;  
4 -use yii\db\Migration;  
5 -  
6 -class m150922_144040_change_Importer_dataPrice extends Migration  
7 -{  
8 - public function up()  
9 - {  
10 - $this->alterColumn('{{%importer}}','price_date_update','TIMESTAMP' );  
11 - $this->createIndex('price_date', '{{%importer}}', 'price_date_update', false);  
12 - }  
13 -  
14 - public function down()  
15 - {  
16 - $this->alterColumn('{{%importer}}','price_date','varchar(15)' );  
17 - $this->dropIndex('price_date', '{{%importer}}');  
18 - }  
19 -  
20 -  
21 -}  
storage/676b4e1f18a2f68d1bf59850e8cafabc/x.png 0 → 100644

31.9 KB

vendor/yiisoft/multiparser/Converter.php
@@ -51,7 +51,7 @@ class Converter extends Behavior @@ -51,7 +51,7 @@ class Converter extends Behavior
51 51
52 public static function convertToString($value) 52 public static function convertToString($value)
53 { 53 {
54 - $res = ''; 54 + $res = $value;
55 if (is_array($value)) { 55 if (is_array($value)) {
56 56
57 $res = Encoder::encodeArray($value); 57 $res = Encoder::encodeArray($value);
@@ -98,8 +98,6 @@ class Converter extends Behavior @@ -98,8 +98,6 @@ class Converter extends Behavior
98 */ 98 */
99 public static function convertByConfiguration( $arr, $configuration ) 99 public static function convertByConfiguration( $arr, $configuration )
100 { 100 {
101 - $result = $arr;  
102 - // \common\components\CustomVarDamp::dumpAndDie( $result );  
103 $hasKey = isset( $configuration['hasKey'] ); 101 $hasKey = isset( $configuration['hasKey'] );
104 foreach ( $configuration['configuration'] as $key => $value ) { 102 foreach ( $configuration['configuration'] as $key => $value ) {
105 if ( $hasKey ){ 103 if ( $hasKey ){
@@ -108,14 +106,14 @@ class Converter extends Behavior @@ -108,14 +106,14 @@ class Converter extends Behavior
108 //если пустой массив то конвертируем всю строку 106 //если пустой массив то конвертируем всю строку
109 if (count( $value ) === 0 ){ 107 if (count( $value ) === 0 ){
110 108
111 - $result = self::$key( $arr ); 109 + $arr = self::$key( $arr );
112 continue; 110 continue;
113 } 111 }
114 // иначе конвертируем каждую ячейку в отдельности 112 // иначе конвертируем каждую ячейку в отдельности
115 foreach ($value as $sub_value) { 113 foreach ($value as $sub_value) {
116 if (isset($arr[$sub_value])) { 114 if (isset($arr[$sub_value])) {
117 // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле 115 // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле
118 - $result[$sub_value] = self::$key( $arr[$sub_value] ); 116 + $arr[$sub_value] = self::$key( $arr[$sub_value] );
119 } 117 }
120 118
121 } 119 }
@@ -123,19 +121,20 @@ class Converter extends Behavior @@ -123,19 +121,20 @@ class Converter extends Behavior
123 121
124 if (isset($arr[$value])) { 122 if (isset($arr[$value])) {
125 // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле 123 // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле
126 - $result[$value] = self::$key( $arr[$value] ); 124 + $arr[$value] = self::$key( $arr[$value] );
  125 + // CustomVarDamp::dump($result);
127 } 126 }
128 127
129 } 128 }
130 129
131 } else { 130 } else {
132 // нет заголовка - мы можем конвертировать только строку в целом 131 // нет заголовка - мы можем конвертировать только строку в целом
133 - $result = self::$key( $arr ); 132 + $arr = self::$key( $arr );
134 } 133 }
135 134
136 } 135 }
137 136
138 - return $result; 137 + return $arr;
139 } 138 }
140 139
141 140