diff --git a/backend/controllers/CheckPriceController.php b/backend/controllers/CheckPriceController.php index 4931632..eda7d19 100644 --- a/backend/controllers/CheckPriceController.php +++ b/backend/controllers/CheckPriceController.php @@ -61,7 +61,6 @@ class CheckPriceController extends BaseController public function actionIndex() { - if(Yii::$app->request->isAjax){ CustomVarDamp::dumpAndDie(1); } @@ -84,6 +83,7 @@ class CheckPriceController extends BaseController public function actionView ($id) { + // @todo переписать запрос - нужно условие на равенство даты, а также вьюшка должна быть модальным окном вызываемой по аджаксу $query = Details::find()->where(['IMPORT_ID' => $id])->orderBy(['timestamp' => SORT_DESC]); $provider = new ActiveDataProvider([ diff --git a/backend/controllers/ParserController.php b/backend/controllers/ParserController.php index 9797d53..b23ec73 100644 --- a/backend/controllers/ParserController.php +++ b/backend/controllers/ParserController.php @@ -92,13 +92,13 @@ class ParserController extends BaseController CustomVarDamp::dump($e->getMessage()); } // получим id только что записанной записи - его запишем в название файла - $id = $files_model->find() + $model->record_id = $files_model->find() ->where(['importer_id' => $files_model->importer_id]) ->orderBy(['id' => SORT_DESC]) ->one() ->id; - $file_name = $id . '.' . $model->file->extension; + $file_name = $model->record_id . '.' . $model->file->extension; if ($model->mode) { $model->file_path = Yii::getAlias('@auto_upload') . '/' . $file_name; @@ -188,10 +188,10 @@ class ParserController extends BaseController // 1. запишем дату старта в таблицу файлов поставщика (ImportersFiles) - $files_model = new ImporterFiles(); - // id поставщика и id загруженного файла получим из конфигурации - $files_model->load(['ImporterFiles' => $configuration->toArray()]); + // id загруженного файла получим из конфигурации + $files_model = ImporterFiles::findOne( $configuration->record_id ); + //$files_model->load(['ImporterFiles' => $configuration->toArray()]); $update_date = date('Y-m-d H:i:s'); $files_model->time_start = $update_date; // запишем дату начала загрузки @@ -206,7 +206,7 @@ class ParserController extends BaseController $details_model->load(['Details' => $data[0]]); if ($details_model->validate()) { // дополним данные значением импортера и даты обновления цены - $data = \Yii::$app->multiparser->addColumns($data, ['IMPORT_ID' => $configuration['importer_id'], 'timestamp' => $update_date]); + $data = \Yii::$app->multiparser->addColumns($data, ['IMPORT_ID' => $configuration->importer_id, 'timestamp' => $update_date]); try { //@todo add transaction @@ -234,7 +234,6 @@ class ParserController extends BaseController Yii::$app->getCache()->delete('parser_configuration'); unlink($configuration['file_path']); - return $this->render('index', ['model' => $configuration]); } catch (ErrorException $e) { diff --git a/backend/models/ImporterFiles.php b/backend/models/ImporterFiles.php index e4d01fd..350a0bb 100644 --- a/backend/models/ImporterFiles.php +++ b/backend/models/ImporterFiles.php @@ -35,6 +35,10 @@ class ImporterFiles extends \yii\db\ActiveRecord ]; } + public function getImporter () + { + return $this->hasOne(Importer::className(), ['id' => 'importer_id'])->name; + } /** * @inheritdoc */ diff --git a/backend/models/UploadFileParsingForm.php b/backend/models/UploadFileParsingForm.php index 150d96b..3f8eb10 100644 --- a/backend/models/UploadFileParsingForm.php +++ b/backend/models/UploadFileParsingForm.php @@ -26,6 +26,7 @@ class UploadFileParsingForm extends Model public $file_path; public $success; public $mode; //0 - режим ручной загрузки, 1 - режим автозагрузки + public $record_id; // id таблицы в которую записывается информация о файле /** * @return array the validation rules. @@ -52,7 +53,7 @@ class UploadFileParsingForm extends Model ['importer_id', 'integer','max' => 999999, 'min' => 0 ], [['action','delete_prefix', 'delete_price', 'success'], 'boolean', 'except' => 'auto' ], // только для ручной загрузки ['delimiter', 'string', 'max' => 1], - ['mode', 'safe'], + [['mode','record_id'], 'safe'], ['delimiter', 'default', 'value' => ';'], [ 'success', 'default', 'value' => false] @@ -87,10 +88,8 @@ class UploadFileParsingForm extends Model 'delete_price', 'delete_prefix', 'file_path', - // id записи таблицы ImportersFiles, получаем из имени загруженного файла - 'id' => function () { - return $this->file->getBaseName(); - }, + // id записи таблицы ImportersFiles, + // 'id' => 'record_id', ]; } diff --git a/console/migrations/m150922_094313_change_key_ImportFiles.php b/console/migrations/m150922_094313_change_key_ImportFiles.php index e1f63db..5606ec2 100644 --- a/console/migrations/m150922_094313_change_key_ImportFiles.php +++ b/console/migrations/m150922_094313_change_key_ImportFiles.php @@ -5,6 +5,7 @@ use yii\db\Migration; class m150922_094313_change_key_ImportFiles extends Migration { + //@todo вероятно что эта миграция ненужна - посмотреть ближе к концу проекта на ключи которые используются - остальные удалить. public function up() { $this->dropIndex('importer_id', '{{%importer_files}}'); diff --git a/console/migrations/m150925_111922_add_foreign_key_ImportFiles.php b/console/migrations/m150925_111922_add_foreign_key_ImportFiles.php new file mode 100644 index 0000000..10f44aa --- /dev/null +++ b/console/migrations/m150925_111922_add_foreign_key_ImportFiles.php @@ -0,0 +1,18 @@ +addForeignKey('importer_fk', '{{%importer_files}}', 'importer_id', '{{%importer}}', 'id'); + } + + public function down() + { + $this->dropForeignKey('importer_fk', '{{%importer_files}}'); + } + +} diff --git a/vendor/yiisoft/multiparser/CsvParser.php b/vendor/yiisoft/multiparser/CsvParser.php index 27d8a73..fee2fc5 100644 --- a/vendor/yiisoft/multiparser/CsvParser.php +++ b/vendor/yiisoft/multiparser/CsvParser.php @@ -125,9 +125,18 @@ class CsvParser implements ParserInterface $return = []; $current_line = 0; - //$this->keys = NULL; + // будем считать количество пустых строк подряд - при трех подряд - считаем что это конец файла и выходим + $empty_lines = 0; + while ( $empty_lines < 3 ) { + // прочтем строку из файла. Если там есть значения - то в ней массив, иначе - false + $row = $this->readRow(); - while (($row = $this->readRow()) !== FALSE) { + if ($row === false) { + //счетчик пустых строк + $empty_lines++; + continue; + } + // строка не пустая, имеем прочитанный массив значений $current_line++; if ($this->hasHeaderRow) { if ($this->keys === NULL) { @@ -148,7 +157,8 @@ class CsvParser implements ParserInterface if (($this->last_line) && ($current_line > $this->last_line)) { break; } - + // обнуляем счетчик, так как считаюся пустые строки ПОДРЯД + $empty_lines = 0; } $this->closeHandler(); -- libgit2 0.21.4