Commit fe1397b32ad0cdd5e060936a133d65ba0f5d0d27
Merge branch 'master' of gitlab.artweb.com.ua:root/test_1
Conflicts: backend/components/parsers/CustomCsvParser.php backend/components/parsers/config.php backend/config/main.php backend/controllers/CheckPriceController.php backend/controllers/ParserController.php backend/views/layouts/column.php backend/views/parser/index.php backend/views/parser/server-files.php backend/web/css/plugins/daterangepicker/daterangepicker-bs3.css backend/web/css/plugins/daterangepicker/daterangepicker.js backend/web/css/plugins/daterangepicker/moment.js backend/web/css/plugins/daterangepicker/moment.min.js console/config/main.php console/migrations/m150925_111922_add_foreign_key_ImportFiles.php framework/core/Convert.php framework/lang/da.yml framework/lang/fr.yml framework/lang/nb.yml vendor/yiisoft/multiparser/Converter.php vendor/yiisoft/multiparser/CsvParser.php vendor/yiisoft/multiparser/YiiMultiparser.php
Showing
24 changed files
with
809 additions
and
106 deletions
Show diff stats
backend/components/parsers/CustomCsvParser.php
| @@ -9,6 +9,8 @@ | @@ -9,6 +9,8 @@ | ||
| 9 | namespace backend\components\parsers; | 9 | namespace backend\components\parsers; |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | +use common\components\CustomVarDamp; | ||
| 13 | + | ||
| 12 | class CustomCsvParser extends \yii\multiparser\CsvParser { | 14 | class CustomCsvParser extends \yii\multiparser\CsvParser { |
| 13 | 15 | ||
| 14 | public $last_line = 10; | 16 | public $last_line = 10; |
| @@ -33,9 +35,8 @@ class CustomCsvParser extends \yii\multiparser\CsvParser { | @@ -33,9 +35,8 @@ class CustomCsvParser extends \yii\multiparser\CsvParser { | ||
| 33 | */ | 35 | */ |
| 34 | protected function convert($arr) | 36 | protected function convert($arr) |
| 35 | { | 37 | { |
| 36 | - $result = \Yii::$app->multiparser->convertByConfiguration( $arr, $this->converter_conf ); | ||
| 37 | - | ||
| 38 | - return $result; | 38 | + $arr = \Yii::$app->multiparser->convertByConfiguration($arr, $this->converter_conf); |
| 39 | + return $arr; | ||
| 39 | 40 | ||
| 40 | } | 41 | } |
| 41 | 42 |
backend/components/parsers/config.php
| 1 | <?php | 1 | <?php |
| 2 | return [ | 2 | return [ |
| 3 | - 'global' => | ||
| 4 | - ['ini' => ['upload_max_filesize' => '20M', | ||
| 5 | - 'post_max_size integer' => '30M', | ||
| 6 | - ]], | ||
| 7 | 'csv' => | 3 | 'csv' => |
| 8 | ['web' => | 4 | ['web' => |
| 9 | ['class' => 'backend\components\parsers\CustomCsvParser', | 5 | ['class' => 'backend\components\parsers\CustomCsvParser', |
| @@ -22,6 +18,27 @@ | @@ -22,6 +18,27 @@ | ||
| 22 | "ADD_BOX"=> 'В пути', | 18 | "ADD_BOX"=> 'В пути', |
| 23 | "GROUP" => 'Группа RG' | 19 | "GROUP" => 'Группа RG' |
| 24 | ], | 20 | ], |
| 21 | + 'console' => | ||
| 22 | + ['class' => 'backend\components\parsers\CustomCsvParser', | ||
| 23 | + 'auto_detect_first_line' => true, | ||
| 24 | + 'hasHeaderRow' => true, | ||
| 25 | + 'converter_conf' => ['class' => ' backend\components\parsers\CustomConverter', | ||
| 26 | + 'hasKey' => 1, | ||
| 27 | + 'configuration' => ["string" => 'DESCR', | ||
| 28 | + "float" => 'PRICE', | ||
| 29 | + "integer" => ['BOX','ADD_BOX'] | ||
| 30 | + ] | ||
| 31 | + ],], | ||
| 32 | + | ||
| 33 | + 'basic_column' => [ | ||
| 34 | + "BRAND" => 'Бренд', | ||
| 35 | + "ARTICLE"=> 'Артикул', | ||
| 36 | + "PRICE" => 'Цена', | ||
| 37 | + "DESCR" => 'Наименование', | ||
| 38 | + "BOX" => 'Колво', | ||
| 39 | + "ADD_BOX"=> 'В пути', | ||
| 40 | + "GROUP" => 'Группа RG' | ||
| 41 | + ], | ||
| 25 | ], | 42 | ], |
| 26 | 'xml' => | 43 | 'xml' => |
| 27 | ['web' => | 44 | ['web' => |
backend/config/main.php
backend/controllers/CheckPriceController.php
| @@ -8,8 +8,8 @@ use yii\filters\AccessControl; | @@ -8,8 +8,8 @@ use yii\filters\AccessControl; | ||
| 8 | use backend\components\base\BaseController; | 8 | use backend\components\base\BaseController; |
| 9 | use yii\filters\VerbFilter; | 9 | use yii\filters\VerbFilter; |
| 10 | use backend\models\Details; | 10 | use backend\models\Details; |
| 11 | -use backend\models\ImporterFiles; | ||
| 12 | -use backend\models\Importer; | 11 | +use backend\models\ImportersFiles; |
| 12 | +use backend\models\Importers; | ||
| 13 | use yii\base\ErrorException; | 13 | use yii\base\ErrorException; |
| 14 | 14 | ||
| 15 | use common\components\CustomVarDamp; | 15 | use common\components\CustomVarDamp; |
| @@ -66,7 +66,11 @@ class CheckPriceController extends BaseController | @@ -66,7 +66,11 @@ class CheckPriceController extends BaseController | ||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]); | 68 | //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]); |
| 69 | +<<<<<<< HEAD | ||
| 69 | $query = Importer::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]); | 70 | $query = Importer::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]); |
| 71 | +======= | ||
| 72 | + $query = Importers::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]); | ||
| 73 | +>>>>>>> ead5cb60ac983cdb680ec70731de195b537be6cd | ||
| 70 | 74 | ||
| 71 | $provider = new ActiveDataProvider([ | 75 | $provider = new ActiveDataProvider([ |
| 72 | 'query' => $query, | 76 | 'query' => $query, |
backend/controllers/ParserController.php
| @@ -299,7 +299,7 @@ class ParserController extends BaseController | @@ -299,7 +299,7 @@ class ParserController extends BaseController | ||
| 299 | } | 299 | } |
| 300 | } else { | 300 | } else { |
| 301 | // Yii::$app->log-> | 301 | // Yii::$app->log-> |
| 302 | - // не дошли до конца по этому остаки вернем в кеш | 302 | + // не дошли до конца по этому остатки вернем в кеш |
| 303 | Yii::$app->cache->set( 'files_to_parse',json_encode( $arr_id_files ) ); | 303 | Yii::$app->cache->set( 'files_to_parse',json_encode( $arr_id_files ) ); |
| 304 | } | 304 | } |
| 305 | } | 305 | } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace backend\models; | ||
| 4 | + | ||
| 5 | +use Yii; | ||
| 6 | +use backend\components\base\BaseActiveRecord; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * This is the model class for table "{{%importer}}". | ||
| 10 | + * | ||
| 11 | + * @property integer $id | ||
| 12 | + * @property string $code | ||
| 13 | + * @property string $name | ||
| 14 | + * @property string $name_price | ||
| 15 | + * @property string $currency_id | ||
| 16 | + * @property string $delivery | ||
| 17 | + * @property string $email | ||
| 18 | + * @property string $info | ||
| 19 | + * @property integer $active | ||
| 20 | + * @property integer $PARSER_IS_ACTIVE | ||
| 21 | + * @property string $PARSER_COLUMN_COUNT | ||
| 22 | + * @property string $PARSER_FIELD_BRAND | ||
| 23 | + * @property string $PARSER_FIELD_ARTICLE | ||
| 24 | + * @property integer $PARSER_FIELD_ARTICLE_PREFIX | ||
| 25 | + * @property string $PARSER_FIELD_PRICE | ||
| 26 | + * @property string $PARSER_FIELD_DESCR | ||
| 27 | + * @property string $PARSER_FIELD_BOX | ||
| 28 | + * @property string $PARSER_FIELD_ADD_BOX | ||
| 29 | + * @property string $PARSER_FIELD_GROUP_RG | ||
| 30 | + * @property string $PARSER_FIELD_SIGN | ||
| 31 | + * @property double $PARSER_FIELD_MULTIPLIER | ||
| 32 | + * @property string $price_date_update | ||
| 33 | + */ | ||
| 34 | +class Importers extends BaseActiveRecord | ||
| 35 | +{ | ||
| 36 | + | ||
| 37 | + public function rules() | ||
| 38 | + { | ||
| 39 | + return [ | ||
| 40 | + [['code', 'name', 'currency_id', 'delivery', 'price_date_update'], 'required'], | ||
| 41 | + [['name_price', 'email', 'PARSER_FIELD_SIGN', 'info'], 'safe'], | ||
| 42 | + [['currency_id', 'active', 'PARSER_IS_ACTIVE', 'PARSER_COLUMN_COUNT', 'PARSER_FIELD_BRAND', 'PARSER_FIELD_ARTICLE', 'PARSER_FIELD_ARTICLE_PREFIX', 'PARSER_FIELD_PRICE', 'PARSER_FIELD_DESCR', 'PARSER_FIELD_BOX', 'PARSER_FIELD_ADD_BOX', 'PARSER_FIELD_GROUP_RG'], 'integer'], | ||
| 43 | + [['info'], 'string'], | ||
| 44 | + [['PARSER_FIELD_MULTIPLIER'], 'number'], | ||
| 45 | + [['code', 'name', 'name_price', 'delivery', 'email'], 'string', 'max' => 254], | ||
| 46 | + [['PARSER_FIELD_SIGN'], 'string', 'max' => 1], | ||
| 47 | + // [['price_date_update'], 'string', 'max' => 15], | ||
| 48 | + [['code'], 'unique'], | ||
| 49 | + [['name'], 'unique'] | ||
| 50 | + ]; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * @inheritdoc | ||
| 55 | + */ | ||
| 56 | + public function attributeLabels() | ||
| 57 | + { | ||
| 58 | + return [ | ||
| 59 | + 'id' => Yii::t('app', 'ID'), | ||
| 60 | + 'code' => Yii::t('app', 'Code'), | ||
| 61 | + 'name' => Yii::t('app', 'Name'), | ||
| 62 | + 'name_price' => Yii::t('app', 'Name Price'), | ||
| 63 | + 'currency_id' => Yii::t('app', 'Currency ID'), | ||
| 64 | + 'delivery' => Yii::t('app', 'Delivery'), | ||
| 65 | + 'email' => Yii::t('app', 'Email'), | ||
| 66 | + 'info' => Yii::t('app', 'Info'), | ||
| 67 | + 'active' => Yii::t('app', 'Active'), | ||
| 68 | + 'PARSER_IS_ACTIVE' => Yii::t('app', 'Parser Is Active'), | ||
| 69 | + 'PARSER_COLUMN_COUNT' => Yii::t('app', 'Parser Column Count'), | ||
| 70 | + 'PARSER_FIELD_BRAND' => Yii::t('app', 'Parser Field Brand'), | ||
| 71 | + 'PARSER_FIELD_ARTICLE' => Yii::t('app', 'Parser Field Article'), | ||
| 72 | + 'PARSER_FIELD_ARTICLE_PREFIX' => Yii::t('app', 'Parser Field Article Prefix'), | ||
| 73 | + 'PARSER_FIELD_PRICE' => Yii::t('app', 'Parser Field Price'), | ||
| 74 | + 'PARSER_FIELD_DESCR' => Yii::t('app', 'Parser Field Descr'), | ||
| 75 | + 'PARSER_FIELD_BOX' => Yii::t('app', 'Parser Field Box'), | ||
| 76 | + 'PARSER_FIELD_ADD_BOX' => Yii::t('app', 'Parser Field Add Box'), | ||
| 77 | + 'PARSER_FIELD_GROUP_RG' => Yii::t('app', 'Parser Field Group Rg'), | ||
| 78 | + 'PARSER_FIELD_SIGN' => Yii::t('app', 'Parser Field Sign'), | ||
| 79 | + 'PARSER_FIELD_MULTIPLIER' => Yii::t('app', 'Parser Field Multiplier'), | ||
| 80 | + 'price_date_update' => Yii::t('app', 'Price Date Update'), | ||
| 81 | + ]; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + | ||
| 85 | + public function getKeys () | ||
| 86 | + { | ||
| 87 | + // возьмем только поля описанные в fields() - там как раз наши настройки парсера | ||
| 88 | + $arr = $this->toArray(); | ||
| 89 | + // отсортируем по ключам с учетом преобразования в число | ||
| 90 | + asort($arr, SORT_NUMERIC); | ||
| 91 | + // уберем нулевые колонки | ||
| 92 | + $arr = array_filter($arr, function($val){ | ||
| 93 | + return $val <> '0'; | ||
| 94 | + }); | ||
| 95 | + // нам нужны именно ключи | ||
| 96 | + $arr = array_keys($arr); | ||
| 97 | + return $arr; | ||
| 98 | + | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public function fields() | ||
| 102 | + { | ||
| 103 | + return [ | ||
| 104 | + 'BRAND' => 'PARSER_FIELD_BRAND', | ||
| 105 | + 'ARTICLE' => 'PARSER_FIELD_ARTICLE', | ||
| 106 | + 'PRICE' => 'PARSER_FIELD_PRICE', | ||
| 107 | + 'DESCR' => 'PARSER_FIELD_DESCR', | ||
| 108 | + 'BOX' => 'PARSER_FIELD_BOX', | ||
| 109 | + 'ADD_BOX' => 'PARSER_FIELD_ADD_BOX', | ||
| 110 | + 'GROUP_RG' => 'PARSER_FIELD_GROUP_RG' | ||
| 111 | + ]; | ||
| 112 | + | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + | ||
| 116 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +/* @var $this yii\web\View */ | ||
| 4 | +/* @var $name string */ | ||
| 5 | +/* @var $message string */ | ||
| 6 | +/* @var $exception Exception */ | ||
| 7 | + | ||
| 8 | +use yii\helpers\Html; | ||
| 9 | + | ||
| 10 | +$this->title = $name; | ||
| 11 | +?> | ||
| 12 | +<div class="site-error"> | ||
| 13 | + | ||
| 14 | + <h1><?= Html::encode($this->title) ?></h1> | ||
| 15 | + | ||
| 16 | + <div class="alert alert-danger"> | ||
| 17 | + <?= nl2br(Html::encode($message)) ?> | ||
| 18 | + </div> | ||
| 19 | + | ||
| 20 | + <p> | ||
| 21 | + | ||
| 22 | + </p> | ||
| 23 | + <p> | ||
| 24 | + </p> | ||
| 25 | + | ||
| 26 | +</div> |
backend/views/parser/index.php
| 1 | <?php | 1 | <?php |
| 2 | use yii\widgets\ActiveForm; | 2 | use yii\widgets\ActiveForm; |
| 3 | use yii\helpers\Html; | 3 | use yii\helpers\Html; |
| 4 | -use backend\models\Importer; | 4 | +use backend\models\Importers; |
| 5 | use yii\helpers\ArrayHelper; | 5 | use yii\helpers\ArrayHelper; |
| 6 | if ( $model->mode ) { | 6 | if ( $model->mode ) { |
| 7 | // авто загрузка | 7 | // авто загрузка |
| @@ -27,7 +27,7 @@ if ( $model->mode ) { | @@ -27,7 +27,7 @@ if ( $model->mode ) { | ||
| 27 | <h3>Загрузка прайсов поставщиков</h3> | 27 | <h3>Загрузка прайсов поставщиков</h3> |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | - <?= $form->field($model, 'importer_id')->dropDownList(ArrayHelper::map( Importer::find()->all(), 'id','name' )); ?> | 30 | + <?= $form->field($model, 'importer_id')->dropDownList(ArrayHelper::map( Importers::find()->all(), 'id','name' )); ?> |
| 31 | 31 | ||
| 32 | <?php if ( !$mode ) { | 32 | <?php if ( !$mode ) { |
| 33 | echo $form->field($model, 'delete_price')->checkbox(['label' => 'Загрузить с удалением старого прайса']); | 33 | echo $form->field($model, 'delete_price')->checkbox(['label' => 'Загрузить с удалением старого прайса']); |
backend/views/parser/server-files.php
| 1 | <?php | 1 | <?php |
| 2 | use yii\helpers\Html; | 2 | use yii\helpers\Html; |
| 3 | +use yii\helpers\Url; | ||
| 3 | use yii\grid\GridView; | 4 | use yii\grid\GridView; |
| 4 | use yii\grid\SerialColumn; | 5 | use yii\grid\SerialColumn; |
| 5 | use yii\grid\ActionColumn; | 6 | use yii\grid\ActionColumn; |
| @@ -44,7 +45,7 @@ Pjax::begin(['id' => 'server_files_grid']); | @@ -44,7 +45,7 @@ Pjax::begin(['id' => 'server_files_grid']); | ||
| 44 | 45 | ||
| 45 | ]] );?> | 46 | ]] );?> |
| 46 | 47 | ||
| 47 | - | 48 | + <?= Html::a('Загрузить файлы', ['parse'],['class' => 'btn btn-success']) ?> |
| 48 | 49 | ||
| 49 | </div> | 50 | </div> |
| 50 | <?php | 51 | <?php |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: Cibermag | ||
| 5 | + * Date: 30.09.2015 | ||
| 6 | + * Time: 9:34 | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +namespace common\components; | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +use yii\base\ErrorException; | ||
| 13 | +use backend\models\ImportersFiles; | ||
| 14 | +use backend\models\Importers; | ||
| 15 | +use backend\models\Details; | ||
| 16 | + | ||
| 17 | +class PriceWriter { | ||
| 18 | + public $mode; | ||
| 19 | + public $configuration; | ||
| 20 | + public $data; | ||
| 21 | + // public $errors = []; | ||
| 22 | + | ||
| 23 | + public function writeDataToDB () | ||
| 24 | + { | ||
| 25 | + // 1. запишем дату старта в таблицу файлов поставщика (ImportersFiles) | ||
| 26 | + // id загруженного файла получим из конфигурации | ||
| 27 | + $files_model = ImportersFiles::findOne( $this->configuration['record_id'] ); | ||
| 28 | + | ||
| 29 | + //$files_model->load(['ImportersFiles' => $this->configuration->toArray()]); | ||
| 30 | + $update_date = date('Y-m-d H:i:s'); | ||
| 31 | + $files_model->time_start = $update_date; | ||
| 32 | + // запишем дату начала загрузки | ||
| 33 | + if (!$files_model->save()) { | ||
| 34 | + $this->errors[] = implode( ', ', $files_model->getErrors()); | ||
| 35 | + return false; | ||
| 36 | + //CustomVarDamp::dumpAndDie($files_model->implode ( ', ', getErrors())()); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + // 2. запишем полученные данные в таблицу товаров (Details) | ||
| 41 | + $details_model = new Details(); | ||
| 42 | + // преобразуем числовые значения | ||
| 43 | + foreach ($this->data as &$row) { | ||
| 44 | + $row['PRICE'] = \Yii::$app->multiparser->convertToFloat($row['PRICE']); | ||
| 45 | + $row['BOX'] = \Yii::$app->multiparser->convertToInteger($row['BOX']); | ||
| 46 | + // присвоим полный артикул | ||
| 47 | + $row['FULL_ARTICLE'] = $row['ARTICLE']; | ||
| 48 | + if(isset($row['ADD_BOX'])) | ||
| 49 | + $row['ADD_BOX'] = \Yii::$app->multiparser->convertToInteger($row['ADD_BOX']); | ||
| 50 | + | ||
| 51 | + // проверим все ли обязательные колонки были указаны пользователем | ||
| 52 | + $details_model->load(['Details' => $row]); | ||
| 53 | + | ||
| 54 | + if (!$details_model->validate()) | ||
| 55 | + break; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + if ($details_model->hasErrors()) { | ||
| 59 | + //@todo предоставить более детальную информацию об ошибке | ||
| 60 | + throw new \ErrorException('Ошибка записи товаров'); | ||
| 61 | + } | ||
| 62 | + else{ | ||
| 63 | + // дополним данные значением импортера и даты обновления цены | ||
| 64 | + $this->data = \Yii::$app->multiparser->addColumns($this->data, ['IMPORT_ID' => $this->configuration['importer_id'], 'timestamp' => $update_date]); | ||
| 65 | + | ||
| 66 | + try { | ||
| 67 | + //@todo add transaction | ||
| 68 | + // попытаемся вставить данные в БД с апдейтом по ключам | ||
| 69 | + $details_model->ManualInsert($this->data); | ||
| 70 | + | ||
| 71 | + // 3. зафиксируем дату конца загрузки в файлах поставщика | ||
| 72 | + | ||
| 73 | + $files_model->time_end = date('Y-m-d H:i:s'); | ||
| 74 | + // CustomVarDamp::dumpAndDie($files_model); | ||
| 75 | + if (!$files_model->save()) { | ||
| 76 | + throw new \ErrorException(implode( ', ', $files_model->getErrors())); | ||
| 77 | +// $this->errors[] = $files_model->implode ( ', ', getErrors()); | ||
| 78 | +// return false; | ||
| 79 | + // CustomVarDamp::dumpAndDie($files_model->implode ( ', ', getErrors())()); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + // 4. зафиксируем дату загрузки в таблице поставщиков | ||
| 83 | + $imp_model = Importers::findOne($this->configuration['importer_id']); | ||
| 84 | + $imp_model->price_date_update = $update_date; | ||
| 85 | + | ||
| 86 | + if (!$imp_model->save()) { | ||
| 87 | +// $this->errors[] = $imp_model->implode ( ', ', getErrors())(); | ||
| 88 | +// return false; | ||
| 89 | + throw new \ErrorException(implode( ', ', $imp_model->getErrors())); | ||
| 90 | + // CustomVarDamp::dumpAndDie($imp_model->implode ( ', ', getErrors())()); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + | ||
| 94 | + } catch (ErrorException $e) { | ||
| 95 | + //CustomVarDamp::dump($e->getMessage()); | ||
| 96 | + throw new \ErrorException( $e->getMessage() ); | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + | ||
| 101 | + return true; | ||
| 102 | + } | ||
| 103 | +} | ||
| 0 | \ No newline at end of file | 104 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace common\models; | ||
| 4 | + | ||
| 5 | +use Yii; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * This is the model class for table "w_accounts". | ||
| 9 | + * | ||
| 10 | + * @property integer $id | ||
| 11 | + * @property integer $if_manager | ||
| 12 | + * @property string $email | ||
| 13 | + * @property string $pass | ||
| 14 | + * @property integer $margin_id | ||
| 15 | + * @property string $name | ||
| 16 | + * @property string $phones | ||
| 17 | + * @property integer $country | ||
| 18 | + * @property integer $city | ||
| 19 | + * @property string $address | ||
| 20 | + * @property string $comment | ||
| 21 | + * @property integer $rating | ||
| 22 | + * @property string $dt | ||
| 23 | + * @property integer $is_active | ||
| 24 | + * @property integer $is_firm | ||
| 25 | + * @property string $last_loginin | ||
| 26 | + * @property string $firm_inn | ||
| 27 | + * @property string $firm_bank | ||
| 28 | + * @property double $balance | ||
| 29 | + * @property integer $office_id | ||
| 30 | + * @property integer $is_scribe | ||
| 31 | + * @property integer $set_manager_id | ||
| 32 | + * @property string $phones2 | ||
| 33 | + * @property string $phones3 | ||
| 34 | + * @property integer $car | ||
| 35 | + * @property integer $mod | ||
| 36 | + * @property string $snumb | ||
| 37 | + * @property integer $deliveries | ||
| 38 | + * @property integer $scode | ||
| 39 | + * @property string $firm_ur_adr | ||
| 40 | + * @property string $firm_fiz_adr | ||
| 41 | + * @property string $firm_code_eg | ||
| 42 | + * @property string $firm_rs | ||
| 43 | + * @property string $firm_mfo | ||
| 44 | + * @property string $firm_site | ||
| 45 | + * @property string $company | ||
| 46 | + */ | ||
| 47 | +class WAccounts extends \yii\db\ActiveRecord | ||
| 48 | +{ | ||
| 49 | + /** | ||
| 50 | + * @inheritdoc | ||
| 51 | + */ | ||
| 52 | + public static function tableName() | ||
| 53 | + { | ||
| 54 | + return 'w_accounts'; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * @inheritdoc | ||
| 59 | + */ | ||
| 60 | + public function rules() | ||
| 61 | + { | ||
| 62 | + return [ | ||
| 63 | + [['if_manager', 'margin_id', 'country', 'city', 'rating', 'dt', 'is_active', 'is_firm', 'office_id', 'is_scribe', 'set_manager_id', 'car', 'mod', 'deliveries', 'scode'], 'integer'], | ||
| 64 | + [['email', 'pass', 'name', 'phones', 'comment', 'dt', 'set_manager_id'], 'required'], | ||
| 65 | + [['comment'], 'string'], | ||
| 66 | + [['balance'], 'number'], | ||
| 67 | + [['email', 'name', 'firm_site'], 'string', 'max' => 150], | ||
| 68 | + [['pass'], 'string', 'max' => 30], | ||
| 69 | + [['phones', 'phones2', 'phones3'], 'string', 'max' => 50], | ||
| 70 | + [['address', 'firm_inn', 'firm_bank'], 'string', 'max' => 254], | ||
| 71 | + [['last_loginin'], 'string', 'max' => 15], | ||
| 72 | + [['snumb', 'firm_ur_adr', 'firm_fiz_adr', 'firm_code_eg', 'firm_rs', 'firm_mfo', 'company'], 'string', 'max' => 255], | ||
| 73 | + [['email'], 'unique'] | ||
| 74 | + ]; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * @inheritdoc | ||
| 79 | + */ | ||
| 80 | + public function attributeLabels() | ||
| 81 | + { | ||
| 82 | + return [ | ||
| 83 | + 'id' => Yii::t('app', 'ID'), | ||
| 84 | + 'if_manager' => Yii::t('app', 'If Manager'), | ||
| 85 | + 'email' => Yii::t('app', 'Email'), | ||
| 86 | + 'pass' => Yii::t('app', 'Pass'), | ||
| 87 | + 'margin_id' => Yii::t('app', 'Margin ID'), | ||
| 88 | + 'name' => Yii::t('app', 'Name'), | ||
| 89 | + 'phones' => Yii::t('app', 'Phones'), | ||
| 90 | + 'country' => Yii::t('app', 'Country'), | ||
| 91 | + 'city' => Yii::t('app', 'City'), | ||
| 92 | + 'address' => Yii::t('app', 'Address'), | ||
| 93 | + 'comment' => Yii::t('app', 'Comment'), | ||
| 94 | + 'rating' => Yii::t('app', 'Rating'), | ||
| 95 | + 'dt' => Yii::t('app', 'Dt'), | ||
| 96 | + 'is_active' => Yii::t('app', 'Is Active'), | ||
| 97 | + 'is_firm' => Yii::t('app', 'Is Firm'), | ||
| 98 | + 'last_loginin' => Yii::t('app', 'Last Loginin'), | ||
| 99 | + 'firm_inn' => Yii::t('app', 'Firm Inn'), | ||
| 100 | + 'firm_bank' => Yii::t('app', 'Firm Bank'), | ||
| 101 | + 'balance' => Yii::t('app', 'Balance'), | ||
| 102 | + 'office_id' => Yii::t('app', 'Office ID'), | ||
| 103 | + 'is_scribe' => Yii::t('app', 'Is Scribe'), | ||
| 104 | + 'set_manager_id' => Yii::t('app', 'Set Manager ID'), | ||
| 105 | + 'phones2' => Yii::t('app', 'Phones2'), | ||
| 106 | + 'phones3' => Yii::t('app', 'Phones3'), | ||
| 107 | + 'car' => Yii::t('app', 'Car'), | ||
| 108 | + 'mod' => Yii::t('app', 'Mod'), | ||
| 109 | + 'snumb' => Yii::t('app', 'Snumb'), | ||
| 110 | + 'deliveries' => Yii::t('app', 'Deliveries'), | ||
| 111 | + 'scode' => Yii::t('app', 'Scode'), | ||
| 112 | + 'firm_ur_adr' => Yii::t('app', 'Firm Ur Adr'), | ||
| 113 | + 'firm_fiz_adr' => Yii::t('app', 'Firm Fiz Adr'), | ||
| 114 | + 'firm_code_eg' => Yii::t('app', 'Firm Code Eg'), | ||
| 115 | + 'firm_rs' => Yii::t('app', 'Firm Rs'), | ||
| 116 | + 'firm_mfo' => Yii::t('app', 'Firm Mfo'), | ||
| 117 | + 'firm_site' => Yii::t('app', 'Firm Site'), | ||
| 118 | + 'company' => Yii::t('app', 'Company'), | ||
| 119 | + ]; | ||
| 120 | + } | ||
| 121 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace common\models; | ||
| 4 | + | ||
| 5 | +use Yii; | ||
| 6 | +use yii\base\Model; | ||
| 7 | +use yii\data\ActiveDataProvider; | ||
| 8 | +use common\models\WAccounts; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * WAccountsSearch represents the model behind the search form about `common\models\WAccounts`. | ||
| 12 | + */ | ||
| 13 | +class WAccountsSearch extends WAccounts | ||
| 14 | +{ | ||
| 15 | + /** | ||
| 16 | + * @inheritdoc | ||
| 17 | + */ | ||
| 18 | + public function rules() | ||
| 19 | + { | ||
| 20 | + return [ | ||
| 21 | + [['id', 'if_manager', 'margin_id', 'country', 'city', 'rating', 'dt', 'is_active', 'is_firm', 'office_id', 'is_scribe', 'set_manager_id', 'car', 'mod', 'deliveries', 'scode'], 'integer'], | ||
| 22 | + [['email', 'pass', 'name', 'phones', 'address', 'comment', 'last_loginin', 'firm_inn', 'firm_bank', 'phones2', 'phones3', 'snumb', 'firm_ur_adr', 'firm_fiz_adr', 'firm_code_eg', 'firm_rs', 'firm_mfo', 'firm_site', 'company'], 'safe'], | ||
| 23 | + [['balance'], 'number'], | ||
| 24 | + ]; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * @inheritdoc | ||
| 29 | + */ | ||
| 30 | + public function scenarios() | ||
| 31 | + { | ||
| 32 | + // bypass scenarios() implementation in the parent class | ||
| 33 | + return Model::scenarios(); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Creates data provider instance with search query applied | ||
| 38 | + * | ||
| 39 | + * @param array $params | ||
| 40 | + * | ||
| 41 | + * @return ActiveDataProvider | ||
| 42 | + */ | ||
| 43 | + public function search($params) | ||
| 44 | + { | ||
| 45 | + $query = WAccounts::find(); | ||
| 46 | + | ||
| 47 | + $dataProvider = new ActiveDataProvider([ | ||
| 48 | + 'query' => $query, | ||
| 49 | + ]); | ||
| 50 | + | ||
| 51 | + $this->load($params); | ||
| 52 | + | ||
| 53 | + if (!$this->validate()) { | ||
| 54 | + // uncomment the following line if you do not want to return any records when validation fails | ||
| 55 | + // $query->where('0=1'); | ||
| 56 | + return $dataProvider; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + $query->andFilterWhere([ | ||
| 60 | + 'id' => $this->id, | ||
| 61 | + 'if_manager' => $this->if_manager, | ||
| 62 | + 'margin_id' => $this->margin_id, | ||
| 63 | + 'country' => $this->country, | ||
| 64 | + 'city' => $this->city, | ||
| 65 | + 'rating' => $this->rating, | ||
| 66 | + 'dt' => $this->dt, | ||
| 67 | + 'is_active' => $this->is_active, | ||
| 68 | + 'is_firm' => $this->is_firm, | ||
| 69 | + 'balance' => $this->balance, | ||
| 70 | + 'office_id' => $this->office_id, | ||
| 71 | + 'is_scribe' => $this->is_scribe, | ||
| 72 | + 'set_manager_id' => $this->set_manager_id, | ||
| 73 | + 'car' => $this->car, | ||
| 74 | + 'mod' => $this->mod, | ||
| 75 | + 'deliveries' => $this->deliveries, | ||
| 76 | + 'scode' => $this->scode, | ||
| 77 | + ]); | ||
| 78 | + | ||
| 79 | + $query->andFilterWhere(['like', 'email', $this->email]) | ||
| 80 | + ->andFilterWhere(['like', 'pass', $this->pass]) | ||
| 81 | + ->andFilterWhere(['like', 'name', $this->name]) | ||
| 82 | + ->andFilterWhere(['like', 'phones', $this->phones]) | ||
| 83 | + ->andFilterWhere(['like', 'address', $this->address]) | ||
| 84 | + ->andFilterWhere(['like', 'comment', $this->comment]) | ||
| 85 | + ->andFilterWhere(['like', 'last_loginin', $this->last_loginin]) | ||
| 86 | + ->andFilterWhere(['like', 'firm_inn', $this->firm_inn]) | ||
| 87 | + ->andFilterWhere(['like', 'firm_bank', $this->firm_bank]) | ||
| 88 | + ->andFilterWhere(['like', 'phones2', $this->phones2]) | ||
| 89 | + ->andFilterWhere(['like', 'phones3', $this->phones3]) | ||
| 90 | + ->andFilterWhere(['like', 'snumb', $this->snumb]) | ||
| 91 | + ->andFilterWhere(['like', 'firm_ur_adr', $this->firm_ur_adr]) | ||
| 92 | + ->andFilterWhere(['like', 'firm_fiz_adr', $this->firm_fiz_adr]) | ||
| 93 | + ->andFilterWhere(['like', 'firm_code_eg', $this->firm_code_eg]) | ||
| 94 | + ->andFilterWhere(['like', 'firm_rs', $this->firm_rs]) | ||
| 95 | + ->andFilterWhere(['like', 'firm_mfo', $this->firm_mfo]) | ||
| 96 | + ->andFilterWhere(['like', 'firm_site', $this->firm_site]) | ||
| 97 | + ->andFilterWhere(['like', 'company', $this->company]); | ||
| 98 | + | ||
| 99 | + return $dataProvider; | ||
| 100 | + } | ||
| 101 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace common\models; | ||
| 4 | + | ||
| 5 | +use Yii; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * This is the model class for table "w_dic_cities". | ||
| 9 | + * | ||
| 10 | + * @property integer $id | ||
| 11 | + * @property string $name | ||
| 12 | + * @property integer $is_active | ||
| 13 | + * @property integer $parent | ||
| 14 | + */ | ||
| 15 | +class WDicCities extends \yii\db\ActiveRecord | ||
| 16 | +{ | ||
| 17 | + /** | ||
| 18 | + * @inheritdoc | ||
| 19 | + */ | ||
| 20 | + public static function tableName() | ||
| 21 | + { | ||
| 22 | + return 'w_dic_cities'; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * @inheritdoc | ||
| 27 | + */ | ||
| 28 | + public function rules() | ||
| 29 | + { | ||
| 30 | + return [ | ||
| 31 | + [['name', 'parent'], 'required'], | ||
| 32 | + [['is_active', 'parent'], 'integer'], | ||
| 33 | + [['name'], 'string', 'max' => 254], | ||
| 34 | + [['parent', 'name'], 'unique', 'targetAttribute' => ['parent', 'name'], 'message' => 'The combination of Name and Parent has already been taken.'] | ||
| 35 | + ]; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * @inheritdoc | ||
| 40 | + */ | ||
| 41 | + public function attributeLabels() | ||
| 42 | + { | ||
| 43 | + return [ | ||
| 44 | + 'id' => Yii::t('app', 'ID'), | ||
| 45 | + 'name' => Yii::t('app', 'Name'), | ||
| 46 | + 'is_active' => Yii::t('app', 'Is Active'), | ||
| 47 | + 'parent' => Yii::t('app', 'Parent'), | ||
| 48 | + ]; | ||
| 49 | + } | ||
| 50 | +} |
console/config/main.php
| @@ -18,8 +18,14 @@ return [ | @@ -18,8 +18,14 @@ return [ | ||
| 18 | 'class' => 'yii\log\FileTarget', | 18 | 'class' => 'yii\log\FileTarget', |
| 19 | 'levels' => ['error', 'warning'], | 19 | 'levels' => ['error', 'warning'], |
| 20 | ], | 20 | ], |
| 21 | - ], | 21 | + [ |
| 22 | + 'class' => 'yii\log\FileTarget', | ||
| 23 | + 'logFile' => 'C:\xampp\htdocs\ital\console\runtime\logs\parser.log', | ||
| 24 | + 'levels' => ['info', 'error'], | ||
| 25 | + // 'categories' => ['parser'], | ||
| 26 | + ], | ||
| 22 | ], | 27 | ], |
| 23 | ], | 28 | ], |
| 24 | 'params' => $params, | 29 | 'params' => $params, |
| 30 | +] | ||
| 25 | ]; | 31 | ]; |
| 1 | +<?php | ||
| 2 | +namespace console\controllers; | ||
| 3 | + | ||
| 4 | +use yii\console\Controller; | ||
| 5 | +use yii\helpers\Console; | ||
| 6 | +use common\components\PriceWriter; | ||
| 7 | +use backend\models\ImportersFiles; | ||
| 8 | + | ||
| 9 | +class ParserController extends Controller{ | ||
| 10 | + public function actionParseCSV () | ||
| 11 | + { | ||
| 12 | + \common\components\CustomVarDamp::dumpAndDie(45); | ||
| 13 | + if( $arr_id_files = Yii::$app->cache->get( 'files_to_parse' ) ) { | ||
| 14 | + $arr_id_files = json_decode( $arr_id_files ); | ||
| 15 | + foreach ( $arr_id_files as $file_name ) { | ||
| 16 | + $file_path = Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv'; | ||
| 17 | + $config = ['record_id' => $file_name, | ||
| 18 | + 'importer_id' => ImportersFiles::findOne(['id' => $file_name])->id, | ||
| 19 | + 'parser_config' => ['keys' => ['DESCR', 'ARTICLE', 'BRAND', 'PRICE', 'BOX']] | ||
| 20 | + ]; | ||
| 21 | + if( $this->parseFileConsole( $file_path, $config ) ){ | ||
| 22 | + unlink( $file_path ); | ||
| 23 | + if (isset( $arr_id_files[$file_path] ) ) { | ||
| 24 | + unset($arr_id_files[$file_path]); | ||
| 25 | + } | ||
| 26 | + } else { | ||
| 27 | + // Yii::$app->log-> | ||
| 28 | + // не дошли до конца по этому остаки вернем в кеш | ||
| 29 | + Yii::$app->cache->set( 'files_to_parse',json_encode( $arr_id_files ) ); | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + if ( !count( $arr_id_files ) ) { | ||
| 33 | + Yii::$app->cache->delete( 'files_to_parse' ); | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + public function actionParseXML () | ||
| 38 | + { | ||
| 39 | + | ||
| 40 | + } | ||
| 41 | + protected function parseFileConsole( $file_path, $configuration ){ | ||
| 42 | + $parser_config = []; | ||
| 43 | + if ( isset( $configuration['parser_config'] ) ) { | ||
| 44 | + $parser_config = $configuration['parser_config']; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + $data = Yii::$app->multiparser->parse( $file_path, $parser_config ); | ||
| 48 | + | ||
| 49 | + $writer = new PriceWriter(); | ||
| 50 | + $writer->configuration = $configuration; | ||
| 51 | + $writer->data = $data; | ||
| 52 | + $writer->mode = 1; //console-режим | ||
| 53 | + if ( $writer->writeDataToDB() ){ | ||
| 54 | + Console::output('It is working'); | ||
| 55 | + return true; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + return false; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public function actionTest () | ||
| 62 | + { | ||
| 63 | + // Console::output('It is working '); | ||
| 64 | + \Yii::warning('1'); | ||
| 65 | + \Yii::info('2'); | ||
| 66 | +// \Yii::info('3'); | ||
| 67 | +// \Yii::warning('4'); | ||
| 68 | + | ||
| 69 | + } | ||
| 70 | +} | ||
| 0 | \ No newline at end of file | 71 | \ No newline at end of file |
console/migrations/m150925_111922_add_foreign_key_ImportFiles.php
| @@ -2,17 +2,29 @@ | @@ -2,17 +2,29 @@ | ||
| 2 | 2 | ||
| 3 | use yii\db\Schema; | 3 | use yii\db\Schema; |
| 4 | use yii\db\Migration; | 4 | use yii\db\Migration; |
| 5 | +use backend\models\ImportersFiles; | ||
| 5 | 6 | ||
| 6 | class m150925_111922_add_foreign_key_ImportFiles extends Migration | 7 | class m150925_111922_add_foreign_key_ImportFiles extends Migration |
| 7 | { | 8 | { |
| 8 | - public function up() | 9 | + public function safeUp() |
| 9 | { | 10 | { |
| 10 | - $this->addForeignKey('importer_fk', '{{%importer_files}}', 'importer_id', '{{%importer}}', 'id'); | 11 | + // сначала отберем записи которых нет уже в поставщиках |
| 12 | + $id_arr = (new \yii\db\Query()) | ||
| 13 | + ->select(['{{%importers_files}}.id']) | ||
| 14 | + ->from('{{%importers_files}}') | ||
| 15 | + ->leftJoin('{{%importers}}', 'importer_id = {{%importers}}.id') | ||
| 16 | + ->where(['name' => null]) | ||
| 17 | + ->all(); | ||
| 18 | + $id_arr = array_column($id_arr,'id'); | ||
| 19 | + // удалим их | ||
| 20 | + $this->delete('{{%importers_files}}',['id' => $id_arr]); | ||
| 21 | + | ||
| 22 | + $this->addForeignKey('importer_fk', '{{%importers_files}}', 'importer_id', '{{%importers}}', 'id'); | ||
| 11 | } | 23 | } |
| 12 | 24 | ||
| 13 | public function down() | 25 | public function down() |
| 14 | { | 26 | { |
| 15 | - $this->dropForeignKey('importer_fk', '{{%importer_files}}'); | 27 | + $this->dropForeignKey('importer_fk', '{{%importers_files}}'); |
| 16 | } | 28 | } |
| 17 | 29 | ||
| 18 | } | 30 | } |
console/migrations/m150929_110456_addTempTableUser.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Schema; | ||
| 4 | +use yii\db\Migration; | ||
| 5 | + | ||
| 6 | +class m150929_110456_addTempTableUser 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 | + $user_array = [ | ||
| 30 | + 'username' => 'admin', | ||
| 31 | + 'auth_key' => 'admin', | ||
| 32 | + 'password_hash' => Yii::$app->security->generatePasswordHash('admin'), | ||
| 33 | + 'password_reset_token' => 'admin', | ||
| 34 | + 'email'=> 'admin@test.com', | ||
| 35 | + 'status' => '10', | ||
| 36 | + 'created_at'=>'000000', | ||
| 37 | + 'updated_at' => '000000' | ||
| 38 | + ]; | ||
| 39 | + $this->insert('user', $user_array); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public function down() | ||
| 43 | + { | ||
| 44 | + $this->dropTable('user'); | ||
| 45 | + } | ||
| 46 | +} |
console/migrations/m150929_113358_change_Importer_dataPrice.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Schema; | ||
| 4 | +use yii\db\Migration; | ||
| 5 | + | ||
| 6 | +class m150929_113358_change_Importer_dataPrice extends Migration | ||
| 7 | +{ | ||
| 8 | + public function safeUp() | ||
| 9 | + { | ||
| 10 | + // увеличим размерность строки, так как при преобразовании из таймстампа в дату может не хватить символов | ||
| 11 | + $this->alterColumn('{{%importers}}','price_date_update','VARCHAR(80)' ); | ||
| 12 | + // конвертем в дату | ||
| 13 | + $this->update('{{%importers}}',['price_date_update'=> new yii\db\Expression('FROM_UNIXTIME(price_date_update)')]); | ||
| 14 | + // а из даты в таймстамп | ||
| 15 | + $this->alterColumn('{{%importers}}','price_date_update','TIMESTAMP NOT NULL' ); | ||
| 16 | + $this->createIndex('price_date', '{{%importers}}', 'price_date_update', false); | ||
| 17 | + | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + public function safedown() | ||
| 22 | + { | ||
| 23 | + $this->alterColumn('{{%importers}}','price_date','varchar(15)' ); | ||
| 24 | + $this->dropIndex('price_date', '{{%importers}}'); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | +} |
framework/core/Convert.php
| @@ -166,63 +166,63 @@ class Convert { | @@ -166,63 +166,63 @@ class Convert { | ||
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | /** | 168 | /** |
| 169 | - * Converts an XML string to a PHP array | ||
| 170 | - * See http://phpsecurity.readthedocs.org/en/latest/Injection-Attacks.html#xml-external-entity-injection | ||
| 171 | - * | ||
| 172 | - * @uses recursiveXMLToArray() | ||
| 173 | - * @param string $val | ||
| 174 | - * @param boolean $disableDoctypes Disables the use of DOCTYPE, and will trigger an error if encountered. | ||
| 175 | - * false by default. | ||
| 176 | - * @param boolean $disableExternals Disables the loading of external entities. false by default. | ||
| 177 | - * @return array | ||
| 178 | - */ | ||
| 179 | - public static function xml2array($val, $disableDoctypes = false, $disableExternals = false) { | ||
| 180 | - // Check doctype | ||
| 181 | - if($disableDoctypes && preg_match('/\<\!DOCTYPE.+]\>/', $val)) { | ||
| 182 | - throw new InvalidArgumentException('XML Doctype parsing disabled'); | ||
| 183 | - } | 169 | + * Converts an XML string to a PHP array |
| 170 | + * See http://phpsecurity.readthedocs.org/en/latest/Injection-Attacks.html#xml-external-entity-injection | ||
| 171 | + * | ||
| 172 | + * @uses recursiveXMLToArray() | ||
| 173 | + * @param string $val | ||
| 174 | + * @param boolean $disableDoctypes Disables the use of DOCTYPE, and will trigger an error if encountered. | ||
| 175 | + * false by default. | ||
| 176 | + * @param boolean $disableExternals Disables the loading of external entities. false by default. | ||
| 177 | + * @return array | ||
| 178 | + */ | ||
| 179 | + public static function xml2array($val, $disableDoctypes = false, $disableExternals = false) { | ||
| 180 | + // Check doctype | ||
| 181 | + if($disableDoctypes && preg_match('/\<\!DOCTYPE.+]\>/', $val)) { | ||
| 182 | + throw new InvalidArgumentException('XML Doctype parsing disabled'); | ||
| 183 | + } | ||
| 184 | 184 | ||
| 185 | - // Disable external entity loading | ||
| 186 | - if($disableExternals) $oldVal = libxml_disable_entity_loader($disableExternals); | ||
| 187 | - try { | ||
| 188 | - $xml = new SimpleXMLElement($val); | ||
| 189 | - $result = self::recursiveXMLToArray($xml); | ||
| 190 | - } catch(Exception $ex) { | ||
| 191 | - if($disableExternals) libxml_disable_entity_loader($oldVal); | ||
| 192 | - throw $ex; | ||
| 193 | - } | ||
| 194 | - if($disableExternals) libxml_disable_entity_loader($oldVal); | ||
| 195 | - return $result; | ||
| 196 | - } | 185 | + // Disable external entity loading |
| 186 | + if($disableExternals) $oldVal = libxml_disable_entity_loader($disableExternals); | ||
| 187 | + try { | ||
| 188 | + $xml = new SimpleXMLElement($val); | ||
| 189 | + $result = self::recursiveXMLToArray($xml); | ||
| 190 | + } catch(Exception $ex) { | ||
| 191 | + if($disableExternals) libxml_disable_entity_loader($oldVal); | ||
| 192 | + throw $ex; | ||
| 193 | + } | ||
| 194 | + if($disableExternals) libxml_disable_entity_loader($oldVal); | ||
| 195 | + return $result; | ||
| 196 | + } | ||
| 197 | 197 | ||
| 198 | - /** | ||
| 199 | - * Convert a XML string to a PHP array recursively. Do not | ||
| 200 | - * call this function directly, Please use {@link Convert::xml2array()} | ||
| 201 | - * | ||
| 202 | - * @param SimpleXMLElement | ||
| 203 | - * | ||
| 204 | - * @return mixed | ||
| 205 | - */ | ||
| 206 | - protected static function recursiveXMLToArray($xml) { | ||
| 207 | - if(is_object($xml) && get_class($xml) == 'SimpleXMLElement') { | ||
| 208 | - $attributes = $xml->attributes(); | ||
| 209 | - foreach($attributes as $k => $v) { | ||
| 210 | - if($v) $a[$k] = (string) $v; | ||
| 211 | - } | ||
| 212 | - $x = $xml; | ||
| 213 | - $xml = get_object_vars($xml); | ||
| 214 | - } | ||
| 215 | - if(is_array($xml)) { | ||
| 216 | - if(count($xml) == 0) return (string) $x; // for CDATA | ||
| 217 | - foreach($xml as $key => $value) { | ||
| 218 | - $r[$key] = self::recursiveXMLToArray($value); | ||
| 219 | - } | ||
| 220 | - if(isset($a)) $r['@'] = $a; // Attributes | ||
| 221 | - return $r; | ||
| 222 | - } | ||
| 223 | - | ||
| 224 | - return (string) $xml; | ||
| 225 | - } | 198 | + /** |
| 199 | + * Convert a XML string to a PHP array recursively. Do not | ||
| 200 | + * call this function directly, Please use {@link Convert::xml2array()} | ||
| 201 | + * | ||
| 202 | + * @param SimpleXMLElement | ||
| 203 | + * | ||
| 204 | + * @return mixed | ||
| 205 | + */ | ||
| 206 | + protected static function recursiveXMLToArray($xml) { | ||
| 207 | + if(is_object($xml) && get_class($xml) == 'SimpleXMLElement') { | ||
| 208 | + $attributes = $xml->attributes(); | ||
| 209 | + foreach($attributes as $k => $v) { | ||
| 210 | + if($v) $a[$k] = (string) $v; | ||
| 211 | + } | ||
| 212 | + $x = $xml; | ||
| 213 | + $xml = get_object_vars($xml); | ||
| 214 | + } | ||
| 215 | + if(is_array($xml)) { | ||
| 216 | + if(count($xml) == 0) return (string) $x; // for CDATA | ||
| 217 | + foreach($xml as $key => $value) { | ||
| 218 | + $r[$key] = self::recursiveXMLToArray($value); | ||
| 219 | + } | ||
| 220 | + if(isset($a)) $r['@'] = $a; // Attributes | ||
| 221 | + return $r; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + return (string) $xml; | ||
| 225 | + } | ||
| 226 | 226 | ||
| 227 | /** | 227 | /** |
| 228 | * Create a link if the string is a valid URL | 228 | * Create a link if the string is a valid URL |
framework/lang/fr.yml
| @@ -403,7 +403,11 @@ fr: | @@ -403,7 +403,11 @@ fr: | ||
| 403 | DELETE: Supprime | 403 | DELETE: Supprime |
| 404 | DELETEDRECORDS: '{count} enregistrements supprimés.' | 404 | DELETEDRECORDS: '{count} enregistrements supprimés.' |
| 405 | EMPTYBEFOREIMPORT: 'Remplacer les données' | 405 | EMPTYBEFOREIMPORT: 'Remplacer les données' |
| 406 | +<<<<<<< HEAD | ||
| 406 | IMPORT: 'Importer de CSV' | 407 | IMPORT: 'Importer de CSV' |
| 408 | +======= | ||
| 409 | + IMPORT: 'Importers de CSV' | ||
| 410 | +>>>>>>> ead5cb60ac983cdb680ec70731de195b537be6cd | ||
| 407 | IMPORTEDRECORDS: '{count} enregistrements importés.' | 411 | IMPORTEDRECORDS: '{count} enregistrements importés.' |
| 408 | NOCSVFILE: 'Veuillez choisir un fichier CSV à importer' | 412 | NOCSVFILE: 'Veuillez choisir un fichier CSV à importer' |
| 409 | NOIMPORT: 'Rien à importer' | 413 | NOIMPORT: 'Rien à importer' |
| @@ -417,9 +421,15 @@ fr: | @@ -417,9 +421,15 @@ fr: | ||
| 417 | IMPORTSPECTITLE: 'Spécification de %s' | 421 | IMPORTSPECTITLE: 'Spécification de %s' |
| 418 | ModelAdmin_Tools_ss: | 422 | ModelAdmin_Tools_ss: |
| 419 | FILTER: Filtrer | 423 | FILTER: Filtrer |
| 424 | +<<<<<<< HEAD | ||
| 420 | IMPORT: Importer | 425 | IMPORT: Importer |
| 421 | ModelSidebar_ss: | 426 | ModelSidebar_ss: |
| 422 | IMPORT_TAB_HEADER: Importer | 427 | IMPORT_TAB_HEADER: Importer |
| 428 | +======= | ||
| 429 | + IMPORT: Importers | ||
| 430 | + ModelSidebar_ss: | ||
| 431 | + IMPORT_TAB_HEADER: Importers | ||
| 432 | +>>>>>>> ead5cb60ac983cdb680ec70731de195b537be6cd | ||
| 423 | SEARCHLISTINGS: Rechercher | 433 | SEARCHLISTINGS: Rechercher |
| 424 | MoneyField: | 434 | MoneyField: |
| 425 | FIELDLABELAMOUNT: Quantité | 435 | FIELDLABELAMOUNT: Quantité |
vendor/yiisoft/multiparser/Converter.php
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | namespace yii\multiparser; | 9 | namespace yii\multiparser; |
| 10 | +use common\components\CustomVarDamp; | ||
| 10 | use yii\base\Behavior; | 11 | use yii\base\Behavior; |
| 11 | 12 | ||
| 12 | // класс который содержит преобразователи значений (фильтры) используемые при парсинге | 13 | // класс который содержит преобразователи значений (фильтры) используемые при парсинге |
| @@ -19,7 +20,6 @@ class Converter extends Behavior | @@ -19,7 +20,6 @@ class Converter extends Behavior | ||
| 19 | 20 | ||
| 20 | public static function convertToFloat($value) | 21 | public static function convertToFloat($value) |
| 21 | { | 22 | { |
| 22 | - echo 1; | ||
| 23 | if ($value == '') { | 23 | if ($value == '') { |
| 24 | $value = 0; | 24 | $value = 0; |
| 25 | } | 25 | } |
| @@ -51,8 +51,6 @@ class Converter extends Behavior | @@ -51,8 +51,6 @@ class Converter extends Behavior | ||
| 51 | 51 | ||
| 52 | public static function convertToString($value) | 52 | public static function convertToString($value) |
| 53 | { | 53 | { |
| 54 | - | ||
| 55 | - | ||
| 56 | $res = ''; | 54 | $res = ''; |
| 57 | if (is_array($value)) { | 55 | if (is_array($value)) { |
| 58 | 56 | ||
| @@ -101,7 +99,7 @@ class Converter extends Behavior | @@ -101,7 +99,7 @@ class Converter extends Behavior | ||
| 101 | public static function convertByConfiguration( $arr, $configuration ) | 99 | public static function convertByConfiguration( $arr, $configuration ) |
| 102 | { | 100 | { |
| 103 | $result = $arr; | 101 | $result = $arr; |
| 104 | - //\common\components\CustomVarDamp::dumpAndDie($configuration); | 102 | + // \common\components\CustomVarDamp::dumpAndDie( $result ); |
| 105 | $hasKey = isset( $configuration['hasKey'] ); | 103 | $hasKey = isset( $configuration['hasKey'] ); |
| 106 | foreach ( $configuration['configuration'] as $key => $value ) { | 104 | foreach ( $configuration['configuration'] as $key => $value ) { |
| 107 | 105 | ||
| @@ -111,7 +109,7 @@ class Converter extends Behavior | @@ -111,7 +109,7 @@ class Converter extends Behavior | ||
| 111 | foreach ($value as $sub_value) { | 109 | foreach ($value as $sub_value) { |
| 112 | if (isset($arr[$sub_value])) { | 110 | if (isset($arr[$sub_value])) { |
| 113 | // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле | 111 | // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле |
| 114 | - $result[$arr[$sub_value]] = self::$key( $arr[$sub_value] ); | 112 | + $result[$sub_value] = self::$key( $arr[$sub_value] ); |
| 115 | } | 113 | } |
| 116 | 114 | ||
| 117 | } | 115 | } |
| @@ -119,7 +117,7 @@ class Converter extends Behavior | @@ -119,7 +117,7 @@ class Converter extends Behavior | ||
| 119 | 117 | ||
| 120 | if (isset($arr[$value])) { | 118 | if (isset($arr[$value])) { |
| 121 | // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле | 119 | // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле |
| 122 | - $result[$arr[$value]] = self::$key( $arr[$value] ); | 120 | + $result[$value] = self::$key( $arr[$value] ); |
| 123 | } | 121 | } |
| 124 | 122 | ||
| 125 | } | 123 | } |
vendor/yiisoft/multiparser/CsvParser.php
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | 3 | ||
| 4 | */ | 4 | */ |
| 5 | namespace yii\multiparser; | 5 | namespace yii\multiparser; |
| 6 | +use common\components\CustomVarDamp; | ||
| 6 | 7 | ||
| 7 | 8 | ||
| 8 | /** | 9 | /** |
| @@ -97,7 +98,7 @@ class CsvParser implements ParserInterface | @@ -97,7 +98,7 @@ class CsvParser implements ParserInterface | ||
| 97 | 98 | ||
| 98 | while (!$finish) { | 99 | while (!$finish) { |
| 99 | $j = 0; | 100 | $j = 0; |
| 100 | - $row = $this->readRow(); | 101 | + $row = $this->file->fgetcsv();; |
| 101 | if ($row === false) { | 102 | if ($row === false) { |
| 102 | continue; | 103 | continue; |
| 103 | } | 104 | } |
| @@ -129,7 +130,7 @@ class CsvParser implements ParserInterface | @@ -129,7 +130,7 @@ class CsvParser implements ParserInterface | ||
| 129 | $empty_lines = 0; | 130 | $empty_lines = 0; |
| 130 | while ( $empty_lines < 3 ) { | 131 | while ( $empty_lines < 3 ) { |
| 131 | // прочтем строку из файла. Если там есть значения - то в ней массив, иначе - false | 132 | // прочтем строку из файла. Если там есть значения - то в ней массив, иначе - false |
| 132 | - $row = $this->readRow(); | 133 | + $row = $this->readRow( $current_line ); |
| 133 | 134 | ||
| 134 | if ($row === false) { | 135 | if ($row === false) { |
| 135 | //счетчик пустых строк | 136 | //счетчик пустых строк |
| @@ -139,19 +140,10 @@ class CsvParser implements ParserInterface | @@ -139,19 +140,10 @@ class CsvParser implements ParserInterface | ||
| 139 | // строка не пустая, имеем прочитанный массив значений | 140 | // строка не пустая, имеем прочитанный массив значений |
| 140 | $current_line++; | 141 | $current_line++; |
| 141 | if ($this->hasHeaderRow) { | 142 | if ($this->hasHeaderRow) { |
| 143 | + // в файле есть заголовок, но он еще не назначен, назначим | ||
| 142 | if ($this->keys === NULL) { | 144 | if ($this->keys === NULL) { |
| 143 | $this->keys = array_values($row); | 145 | $this->keys = array_values($row); |
| 144 | - } else { | ||
| 145 | - | ||
| 146 | - if (count($this->keys) !== count($row)) { | ||
| 147 | -// | ||
| 148 | - throw new \ErrorException("Invalid columns detected on line # {$current_line}", 0, 1, $this->file->getBasename(), $current_line); | ||
| 149 | - } | ||
| 150 | - | ||
| 151 | - $return[] = array_combine($this->keys, $row); | ||
| 152 | } | 146 | } |
| 153 | - } else { | ||
| 154 | - $return[] = $row; | ||
| 155 | } | 147 | } |
| 156 | // если у нас установлен лимит, при его достижении прекращаем парсинг | 148 | // если у нас установлен лимит, при его достижении прекращаем парсинг |
| 157 | if (($this->last_line) && ($current_line > $this->last_line)) { | 149 | if (($this->last_line) && ($current_line > $this->last_line)) { |
| @@ -159,6 +151,8 @@ class CsvParser implements ParserInterface | @@ -159,6 +151,8 @@ class CsvParser implements ParserInterface | ||
| 159 | } | 151 | } |
| 160 | // обнуляем счетчик, так как считаюся пустые строки ПОДРЯД | 152 | // обнуляем счетчик, так как считаюся пустые строки ПОДРЯД |
| 161 | $empty_lines = 0; | 153 | $empty_lines = 0; |
| 154 | + | ||
| 155 | + $return[] = $row; | ||
| 162 | } | 156 | } |
| 163 | 157 | ||
| 164 | $this->closeHandler(); | 158 | $this->closeHandler(); |
| @@ -174,16 +168,24 @@ class CsvParser implements ParserInterface | @@ -174,16 +168,24 @@ class CsvParser implements ParserInterface | ||
| 174 | /** | 168 | /** |
| 175 | * @return array - одномерный массив результата парсинга строки | 169 | * @return array - одномерный массив результата парсинга строки |
| 176 | */ | 170 | */ |
| 177 | - protected function readRow() | 171 | + protected function readRow( $current_line ) |
| 178 | { | 172 | { |
| 179 | - | ||
| 180 | $row = $this->file->fgetcsv(); | 173 | $row = $this->file->fgetcsv(); |
| 181 | - | ||
| 182 | if (is_array($row)) { | 174 | if (is_array($row)) { |
| 183 | - // попытаемся конвертировать прочитанные занчения согдасно конфигурации котнвертера значений | 175 | + // если есть заголовок, то перед конвертацией его нужно назначить |
| 176 | + if ($this->hasHeaderRow && $this->keys !== NULL) { | ||
| 177 | + | ||
| 178 | + if (count($this->keys) !== count($row)) { | ||
| 179 | +// | ||
| 180 | + throw new \ErrorException("Ошибка парсинга файла в строке # {$current_line}. Не соответсвие числа ключевых колонок (заголовка) - числу колонок с данными", 0, 1, $this->file->getBasename(), $current_line); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + $row = array_combine($this->keys, $row); | ||
| 184 | + } | ||
| 185 | + // попытаемся конвертировать прочитанные значения согласно конфигурации котнвертера значений | ||
| 184 | $row = $this->convert($row); | 186 | $row = $this->convert($row); |
| 185 | - // \common\components\CustomVarDamp::dump($row); | ||
| 186 | - if ($this->first_column) { | 187 | + // обрежем массив к первой значимой колонке |
| 188 | + if ( $this->first_column ) { | ||
| 187 | 189 | ||
| 188 | $row = array_slice($row, $this->first_column); | 190 | $row = array_slice($row, $this->first_column); |
| 189 | 191 |
vendor/yiisoft/multiparser/YiiMultiparser.php
| @@ -39,14 +39,5 @@ public $configuration; | @@ -39,14 +39,5 @@ public $configuration; | ||
| 39 | 39 | ||
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | - public function init() | ||
| 43 | - { | ||
| 44 | - if( isset($this->configuration['glob']) && isset($this->configuration['glob']['ini'])){ | ||
| 45 | - foreach ($this->configuration['glob']['ini'] as $ini_setting => $ini_setting_value) { | ||
| 46 | - ini_set( $ini_setting, $ini_setting_value ); | ||
| 47 | - } | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - } | ||
| 51 | 42 | ||
| 52 | } | 43 | } |
| 53 | \ No newline at end of file | 44 | \ No newline at end of file |