diff --git a/backend/components/base/BaseController.php b/backend/components/base/BaseController.php
index 46c156c..21e496a 100644
--- a/backend/components/base/BaseController.php
+++ b/backend/components/base/BaseController.php
@@ -45,11 +45,9 @@ class BaseController extends Controller {
}
-
+//
// private function resizeImg($w, $h, $filepath,$newfilepath){
-// list($orig_width, $orig_height) = getimagesize($filepath);
-// $width = $orig_width;
-// $height = $orig_height;
+// list($width, $height) = getimagesize($filepath);
// if($width > $height) {
// $y = 0;
// $x = ($width - $height) / 2;
@@ -76,7 +74,7 @@ class BaseController extends Controller {
{
$model = new ImageSizerForm();
- //die(print_r(Yii::$app->request->post()));
+
if ($model->load(Yii::$app->request->post())) {
$model->file = UploadedFile::getInstance($model, 'file');
@@ -85,6 +83,7 @@ class BaseController extends Controller {
$imgDir = Yii::getAlias('@storage/'.$md5_file.'/');
$imageAlias = Yii::getAlias($imgDir.$model->width.'x'.$model->height.'.'.$model->file->extension);
$imageLink = '/storage/'.$md5_file.$model->width.'x'.$model->height.'.'.$model->file->extension;
+
if(!is_dir($imgDir)) {
mkdir($imgDir, 0755, true);
}
diff --git a/backend/components/parsers/CustomConverter.php b/backend/components/parsers/CustomConverter.php
deleted file mode 100644
index b054b8c..0000000
--- a/backend/components/parsers/CustomConverter.php
+++ /dev/null
@@ -1,87 +0,0 @@
- $sub_value) {
- if (isset($key_array[$key])) {
- // если такой ключ в базовом массиве (массиве ключей) есть, то заменим новым, иначе просто удалим
- $new_key = $key_array[$key];
- if( !array_key_exists( $new_key , $res ) ){
- $res[ $new_key ] = $res[$key];
- }
- }
- unset( $res[$key] );
- }
-
- return $res;
- },
- $value_arr, $key_array);
- return $result;
- }
-
- /**
- * @param $value_arr - двумерный массив к которому нужно добавить колонки
- * @param $add_array - массив с колонками (ключи) и занчениями колонок
- * @return mixed
- */
- public function addColumns ( array $value_arr , array $add_array )
- {
- $i = 0;
- while ($i < count($value_arr)) {
- foreach ($add_array as $add_key => $add_value) {
- $value_arr[$i][$add_key] = $add_value;
- }
- $i++;
- }
- return $value_arr;
- }
-
- public static function convertToDetails ( array $row )
- {
- // присвоим полный артикул
- $row['FULL_ARTICLE'] = $row['ARTICLE'];
-
- $details_model = new Details();
- // проверим все ли обязательные колонки были указаны пользователем
- $details_model->load(['Details' => $row]);
-
- if (!$details_model->validate()){
- $errors = '';
- foreach ( $details_model->errors as $key => $arr_errors ) {
- $errors .= "Аттрибут $key - " . implode( ' , ', $arr_errors );
- }
- throw new \ErrorException( $errors );
- }
- return $row;
- }
-
-
-
-}
\ No newline at end of file
diff --git a/backend/components/parsers/CustomCsvParser.php b/backend/components/parsers/CustomCsvParser.php
deleted file mode 100644
index f2c4f0c..0000000
--- a/backend/components/parsers/CustomCsvParser.php
+++ /dev/null
@@ -1,47 +0,0 @@
-converter_conf)) {
- if ($this->hasHeaderRow) {
- // если у файла есть заголовок, то в результате имеем ассоциативный массив
- $this->converter_conf['hasKey'] = 1;
- }
-
- }
-
- }
-
- /**
- * @param $arr
- * @return mixed
- * преобразовует значения прочитанного массива в нужные типы, согласно конфигурации конвертера
- */
- protected function convert($arr)
- {
- $arr = \Yii::$app->multiparser->convertByConfiguration($arr, $this->converter_conf);
-
- return $arr;
-
- }
-
-}
\ No newline at end of file
diff --git a/backend/components/parsers/MailParser.php b/backend/components/parsers/MailParser.php
deleted file mode 100644
index 4c4f5a9..0000000
--- a/backend/components/parsers/MailParser.php
+++ /dev/null
@@ -1,105 +0,0 @@
-parts) && count($structure->parts)) {
- for ($i = 0; $i < count($structure->parts); $i++) {
- $attachments[$i] = array(
- 'is_attachment' => false,
- 'filename' => '',
- 'name' => '',
- 'attachment' => '');
-
- if ($structure->parts[$i]->ifdparameters) {
- foreach ($structure->parts[$i]->dparameters as $object) {
- if (strtolower($object->attribute) == 'filename') {
- $attachments[$i]['is_attachment'] = true;
- $attachments[$i]['filename'] = $object->value;
- }
- }
- }
-
- if ($structure->parts[$i]->ifparameters) {
- foreach ($structure->parts[$i]->parameters as $object) {
- if (strtolower($object->attribute) == 'name') {
- $attachments[$i]['is_attachment'] = true;
- $attachments[$i]['name'] = $object->value;
- }
- }
- }
-
- if ($attachments[$i]['is_attachment']) {
- $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i + 1);
- if ($structure->parts[$i]->encoding == 3) { // 3 = BASE64
- $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
- } elseif ($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
- $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
- }
- }
- } // for($i = 0; $i < count($structure->parts); $i++)
- } // if(isset($structure->parts) && count($structure->parts))
-
-
- if (count($attachments) != 0) {
-
-
- foreach ($attachments as $at) {
-
- if ($at['is_attachment'] == 1) {
- //die(__DIR__);
- file_put_contents('test.csv', $at['attachment']);
-
- }
- }
-
- }
-
- }
-
- // echo $output;
- }
- /* close the connection */
- imap_close($inbox);
- }
-}
\ No newline at end of file
diff --git a/backend/components/parsers/config.php b/backend/components/parsers/config.php
deleted file mode 100644
index a18abc6..0000000
--- a/backend/components/parsers/config.php
+++ /dev/null
@@ -1,68 +0,0 @@
-
- ['web' =>
- ['class' => 'backend\components\parsers\CustomCsvParser',
- 'auto_detect_first_line' => true,
- 'converter_conf' => ['class' => ' backend\components\parsers\CustomConverter',
- 'configuration' => ["string" => 'DESCR'],]
- ],
-
- 'basic_column' => [
- Null => 'Пусто',
- "BRAND" => 'Бренд',
- "ARTICLE"=> 'Артикул',
- "PRICE" => 'Цена',
- "DESCR" => 'Наименование',
- "BOX" => 'Колво',
- "ADD_BOX"=> 'В пути',
- "GROUP" => 'Группа RG'
- ],
- 'console' =>
- ['class' => 'backend\components\parsers\CustomCsvParser',
- 'auto_detect_first_line' => true,
- 'hasHeaderRow' => true,
- 'converter_conf' => ['class' => ' backend\components\parsers\CustomConverter',
- 'hasKey' => 1,
- 'configuration' => ["string" => 'DESCR',
- "float" => 'PRICE',
- "integer" => ['BOX','ADD_BOX'],
- "details" => [], // @todo сделать отдельно конфигурирование валидации
- "integer" => ['BOX','ADD_BOX']
-
- ]
- ],],
-
- 'basic_column' => [
- "BRAND" => 'Бренд',
- "ARTICLE"=> 'Артикул',
- "PRICE" => 'Цена',
- "DESCR" => 'Наименование',
- "BOX" => 'Колво',
- "ADD_BOX"=> 'В пути',
- "GROUP" => 'Группа RG'
- ],
- ],
- 'xml' =>
- ['web' =>
- ['class' => 'yii\multiparser\XmlParser',
- 'node' => 'Товар',],
-
- 'basic_column' => [
- "BRAND" => 'Производитель',
- "ARTICLE"=> 'Код',
- "PRICE" => 'Розница',
- "DESCR" => 'Наименование',
- "BOX" => 'Колво',
- "ADD_BOX"=> 'Ожидаемое',
- "GROUP" => 'Группа'
- ],
- ]
- ];
-
-
-//[
-// "float" => 'PRICE',
-// "integer" => ['BOX' , 'ADD_BOX' ],
-// "prefix" => 'ARTICLE'
-//]
\ No newline at end of file
diff --git a/backend/components/views/image_sizer.php b/backend/components/views/image_sizer.php
index 69ee0c5..8a824c2 100644
--- a/backend/components/views/image_sizer.php
+++ b/backend/components/views/image_sizer.php
@@ -12,7 +12,7 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl
?>
-= $form->field($model, 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo"]); ?>
+= $form->field( new \backend\models\ImageSizerForm(), 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo"]); ?>
= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?>
@@ -25,7 +25,7 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl
$("#= $field?>").fileupload({
dataType: 'json',
- formData: {
+ ImageSizerForm: {
height: =$height?>,
width: = $width?>
},
diff --git a/backend/config/main.php b/backend/config/main.php
index 8486a60..2c2adc9 100644
--- a/backend/config/main.php
+++ b/backend/config/main.php
@@ -5,7 +5,6 @@ $params = array_merge(
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
-$mp_configuration = require( __DIR__ . '/../components/parsers/config.php');
return [
'id' => 'app-backend',
@@ -39,15 +38,7 @@ return [
'adminUrl' => '/admin'
],
- 'multiparser'=>[
- 'class' => 'yii\multiparser\YiiMultiparser',
- 'configuration' => $mp_configuration,
- 'as behavior' => [
- 'class' => 'backend\components\parsers\CustomConverter',
- ],
-
- ],
],
'params' => $params,
];
diff --git a/backend/controllers/ParserController.php b/backend/controllers/ParserController.php
index 9a0586c..7868577 100644
--- a/backend/controllers/ParserController.php
+++ b/backend/controllers/ParserController.php
@@ -117,7 +117,6 @@ class ParserController extends BaseController
// сохраняем в кеш модель - в ней настройки для дальнейшей обработки данных
Yii::$app->getCache()->set('parser_configuration', serialize($model));
-
} else {
// не прошла валидация форма загрузки файлов
//@todo - отправка на страницу ошибок
@@ -219,11 +218,10 @@ class ParserController extends BaseController
public function actionServerFiles ()
{
-
$arr_id_files = [];
// получим список файлов которые ожидают к загрузке
- foreach ( glob(Yii::getAlias('@temp_upload') . '/*.csv') as $server_file ) {
+ foreach ( glob(Yii::getAlias('@temp_upload') . '/*.csv' ) as $server_file ) {
$file_id = basename($server_file,".csv");
$arr_id_files[] = (int) $file_id;
}
@@ -265,74 +263,17 @@ class ParserController extends BaseController
public function actionLaunchCroneUploads ()
{
-
-
foreach (glob(Yii::getAlias('@temp_upload') . '/*.csv') as $server_file) {
$file_name = basename($server_file,".csv");
- rename( $server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv');
+ // rename( $server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv');
+ copy( $server_file, Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv' );
}
-
- //$this->redirect('server-files');
- $this->actionParseCsv();
+ Yii::$app->session->setFlash( 'server-files', 'Файл успешно загружен' );
+ $this->redirect('server-files');
}
- public function actionParseCsv ()
- {
- // Console::output('1');
- foreach (glob( \Yii::getAlias('@auto_upload') . '/*.csv' ) as $file_path) {
- $file_name = basename( $file_path,".csv" );
- // Console::output('2');
- $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id;
- $keys = Importers::findOne( ['id' => $importer_id] )->keys;
-
- $config = ['record_id' => $file_name,
- 'importer_id' => $importer_id,
- 'parser_config' => ['keys' => $keys,
- 'mode' => 'console']
- ];
- // Console::output('3');
- if( $this->parseFileConsole( $file_path, $config ) ){
- // Console::output('4');
- unlink( $file_path );
- if (isset( $arr_id_files[$file_path] ) ) {
- unset( $arr_id_files[$file_path] );
- }
- }
- }
-
-
- //return $this->redirect('serverFiles');
- }
- protected function parseFileConsole( $file_path, $configuration ){
-
- if( !file_exists( $file_path ) )
- throw new ErrorException("$file_path - файл не найден!");
-
- $parser_config = [];
- if ( isset( $configuration['parser_config'] ) ) {
- $parser_config = $configuration['parser_config'];
- }
- $data = \Yii::$app->multiparser->parse( $file_path, $parser_config );
- if (! $data) {
- // @todo переделать, что бы ошибка автоматически останавливала сценарий
- die;
- }
-
-
- $writer = new PriceWriter();
- $writer->configuration = $configuration;
- $writer->data = $data;
- $writer->mode = 1; //console-режим
- if ( $writer->writeDataToDB() ){
-
- return true;
- }
-
- return false;
- }
-
}
diff --git a/backend/models/ImageSizerForm.php b/backend/models/ImageSizerForm.php
index 227d03f..4ebe896 100644
--- a/backend/models/ImageSizerForm.php
+++ b/backend/models/ImageSizerForm.php
@@ -13,6 +13,11 @@ class ImageSizerForm extends Model
* @var UploadedFile file attribute
*/
public $file;
+ public $width;
+ public $height;
+ public $field;
+ public $model;
+ public $form;
/**
* @return array the validation rules.
diff --git a/backend/views/parser/server-files.php b/backend/views/parser/server-files.php
index 804ab7a..1256e16 100644
--- a/backend/views/parser/server-files.php
+++ b/backend/views/parser/server-files.php
@@ -19,6 +19,7 @@ Pjax::begin(['id' => 'server_files_grid']);
?>
+ = Html::tag('h3', \Yii::$app->session->setFlash( 'server-files'),['class'=>'bg-success'])?>
= Html::encode($this->title) ?>
diff --git a/common/components/PriceWriter.php b/common/components/PriceWriter.php
index f7b2985..29dfed8 100644
--- a/common/components/PriceWriter.php
+++ b/common/components/PriceWriter.php
@@ -34,9 +34,8 @@ class PriceWriter {
// 2. запишем полученные данные в таблицу товаров (Details)
$details_model = new Details();
-
// только для ручной загрузки, в авто режиме все делает конвертер при первом же проходе (в процессе парсинга)
- if ($this->mode = 0) {
+ if ($this->mode == 0) {
// преобразуем числовые значения
foreach ($this->data as &$row) {
$row['PRICE'] = \Yii::$app->multiparser->convertToFloat($row['PRICE']);
@@ -48,7 +47,6 @@ class PriceWriter {
// проверим все ли обязательные колонки были указаны пользователем
$details_model->load(['Details' => $row]);
-
if (!$details_model->validate())
//@todo предоставить более детальную информацию об ошибке
throw new \ErrorException('Ошибка записи товаров');
@@ -85,4 +83,6 @@ class PriceWriter {
return true;
}
+
+
}
\ No newline at end of file
diff --git a/common/components/parsers/CustomConverter.php b/common/components/parsers/CustomConverter.php
new file mode 100644
index 0000000..b054b8c
--- /dev/null
+++ b/common/components/parsers/CustomConverter.php
@@ -0,0 +1,87 @@
+ $sub_value) {
+ if (isset($key_array[$key])) {
+ // если такой ключ в базовом массиве (массиве ключей) есть, то заменим новым, иначе просто удалим
+ $new_key = $key_array[$key];
+ if( !array_key_exists( $new_key , $res ) ){
+ $res[ $new_key ] = $res[$key];
+ }
+ }
+ unset( $res[$key] );
+ }
+
+ return $res;
+ },
+ $value_arr, $key_array);
+ return $result;
+ }
+
+ /**
+ * @param $value_arr - двумерный массив к которому нужно добавить колонки
+ * @param $add_array - массив с колонками (ключи) и занчениями колонок
+ * @return mixed
+ */
+ public function addColumns ( array $value_arr , array $add_array )
+ {
+ $i = 0;
+ while ($i < count($value_arr)) {
+ foreach ($add_array as $add_key => $add_value) {
+ $value_arr[$i][$add_key] = $add_value;
+ }
+ $i++;
+ }
+ return $value_arr;
+ }
+
+ public static function convertToDetails ( array $row )
+ {
+ // присвоим полный артикул
+ $row['FULL_ARTICLE'] = $row['ARTICLE'];
+
+ $details_model = new Details();
+ // проверим все ли обязательные колонки были указаны пользователем
+ $details_model->load(['Details' => $row]);
+
+ if (!$details_model->validate()){
+ $errors = '';
+ foreach ( $details_model->errors as $key => $arr_errors ) {
+ $errors .= "Аттрибут $key - " . implode( ' , ', $arr_errors );
+ }
+ throw new \ErrorException( $errors );
+ }
+ return $row;
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/common/components/parsers/CustomCsvParser.php b/common/components/parsers/CustomCsvParser.php
new file mode 100644
index 0000000..a889969
--- /dev/null
+++ b/common/components/parsers/CustomCsvParser.php
@@ -0,0 +1,47 @@
+converter_conf)) {
+ if ($this->hasHeaderRow) {
+ // если у файла есть заголовок, то в результате имеем ассоциативный массив
+ $this->converter_conf['hasKey'] = 1;
+ }
+
+ }
+
+ }
+
+ /**
+ * @param $arr
+ * @return mixed
+ * преобразовует значения прочитанного массива в нужные типы, согласно конфигурации конвертера
+ */
+ protected function convert($arr)
+ {
+ $arr = \Yii::$app->multiparser->convertByConfiguration($arr, $this->converter_conf);
+
+ return $arr;
+
+ }
+
+}
\ No newline at end of file
diff --git a/common/components/parsers/MailParser.php b/common/components/parsers/MailParser.php
new file mode 100644
index 0000000..4c4f5a9
--- /dev/null
+++ b/common/components/parsers/MailParser.php
@@ -0,0 +1,105 @@
+parts) && count($structure->parts)) {
+ for ($i = 0; $i < count($structure->parts); $i++) {
+ $attachments[$i] = array(
+ 'is_attachment' => false,
+ 'filename' => '',
+ 'name' => '',
+ 'attachment' => '');
+
+ if ($structure->parts[$i]->ifdparameters) {
+ foreach ($structure->parts[$i]->dparameters as $object) {
+ if (strtolower($object->attribute) == 'filename') {
+ $attachments[$i]['is_attachment'] = true;
+ $attachments[$i]['filename'] = $object->value;
+ }
+ }
+ }
+
+ if ($structure->parts[$i]->ifparameters) {
+ foreach ($structure->parts[$i]->parameters as $object) {
+ if (strtolower($object->attribute) == 'name') {
+ $attachments[$i]['is_attachment'] = true;
+ $attachments[$i]['name'] = $object->value;
+ }
+ }
+ }
+
+ if ($attachments[$i]['is_attachment']) {
+ $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i + 1);
+ if ($structure->parts[$i]->encoding == 3) { // 3 = BASE64
+ $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
+ } elseif ($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
+ $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
+ }
+ }
+ } // for($i = 0; $i < count($structure->parts); $i++)
+ } // if(isset($structure->parts) && count($structure->parts))
+
+
+ if (count($attachments) != 0) {
+
+
+ foreach ($attachments as $at) {
+
+ if ($at['is_attachment'] == 1) {
+ //die(__DIR__);
+ file_put_contents('test.csv', $at['attachment']);
+
+ }
+ }
+
+ }
+
+ }
+
+ // echo $output;
+ }
+ /* close the connection */
+ imap_close($inbox);
+ }
+}
\ No newline at end of file
diff --git a/common/components/parsers/config.php b/common/components/parsers/config.php
new file mode 100644
index 0000000..ba758eb
--- /dev/null
+++ b/common/components/parsers/config.php
@@ -0,0 +1,50 @@
+
+ ['web' =>
+ ['class' => 'backend\components\parsers\CustomCsvParser',
+ 'auto_detect_first_line' => true,
+ 'converter_conf' => ['class' => ' backend\components\parsers\CustomConverter',
+ 'configuration' => ["string" => 'DESCR'],]
+ ],
+ 'console' =>
+ ['class' => 'backend\components\parsers\CustomCsvParser',
+ 'auto_detect_first_line' => true,
+ 'hasHeaderRow' => true,
+ 'converter_conf' => ['class' => ' backend\components\parsers\CustomConverter',
+ 'hasKey' => 1,
+ 'configuration' => ["string" => 'DESCR',
+ "float" => 'PRICE',
+ "integer" => ['BOX','ADD_BOX'],
+ "details" => [] // @todo сделать отдельно конфигурирование валидации
+
+ ]
+ ],],
+
+ 'basic_column' => [
+ Null => 'Пусто',
+ "BRAND" => 'Бренд',
+ "ARTICLE"=> 'Артикул',
+ "PRICE" => 'Цена',
+ "DESCR" => 'Наименование',
+ "BOX" => 'Колво',
+ "ADD_BOX"=> 'В пути',
+ "GROUP" => 'Группа RG'
+ ],
+ ],
+ 'xml' =>
+ ['web' =>
+ ['class' => 'yii\multiparser\XmlParser',
+ 'node' => 'Товар',],
+ ],
+ 'basic_column' => [
+ "BRAND" => 'Производитель',
+ "ARTICLE"=> 'Код',
+ "PRICE" => 'Розница',
+ "DESCR" => 'Наименование',
+ "BOX" => 'Колво',
+ "ADD_BOX"=> 'Ожидаемое',
+ "GROUP" => 'Группа'
+ ],
+ ];
+
diff --git a/common/config/bootstrap.php b/common/config/bootstrap.php
index 3f897d3..ec66076 100644
--- a/common/config/bootstrap.php
+++ b/common/config/bootstrap.php
@@ -6,3 +6,4 @@ Yii::setAlias('console', dirname(dirname(__DIR__)) . '/console');
Yii::setAlias('auto_upload', dirname(dirname(__DIR__)) . '/backend/uploads/auto');
Yii::setAlias('manual_upload', dirname(dirname(__DIR__)) . '/backend/uploads/manual');
Yii::setAlias('temp_upload', dirname(dirname(__DIR__)) . '/backend/uploads/temp');
+Yii::setAlias('storage', dirname(dirname(__DIR__)) . '/storage');
diff --git a/common/config/main.php b/common/config/main.php
index bccb223..bb448b8 100644
--- a/common/config/main.php
+++ b/common/config/main.php
@@ -1,4 +1,5 @@
'ru-RU',
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
@@ -13,6 +14,15 @@ return [
'module/
//' => '//',
]
],
+ 'multiparser'=>[
+
+ 'class' => 'yii\multiparser\YiiMultiparser',
+ 'configuration' => $mp_configuration,
+ 'as behavior' => [
+ 'class' => 'backend\components\parsers\CustomConverter',
+ ],
+
+ ],
],
];
diff --git a/console/controllers/ParserController.php b/console/controllers/ParserController.php
index fa8eccd..058e356 100644
--- a/console/controllers/ParserController.php
+++ b/console/controllers/ParserController.php
@@ -12,60 +12,64 @@ class ParserController extends Controller{
public function actionParseCsv ()
{
- Console::output('1');
+ \Yii::info('Начало загрузки файлов прайсов csv','parser');
foreach (glob( \Yii::getAlias('@auto_upload') . '/*.csv' ) as $file_path) {
- $file_name = basename($file_path,".csv");
- Console::output('2');
- $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id;
- $keys = Importers::findOne( ['id' => $importer_id] )->keys;
-
- $config = ['record_id' => $file_name,
- 'importer_id' => $importer_id,
- 'parser_config' => ['keys' => $keys,
- 'mode' => 'console']
- ];
- Console::output('3');
- if( $this->parseFileConsole( $file_path, $config ) ){
- Console::output('4');
- unlink( $file_path );
- if (isset( $arr_id_files[$file_path] ) ) {
- unset( $arr_id_files[$file_path] );
- }
- }
- }
+ $file_name = basename( $file_path,".csv" );
+ \Yii::info("Обработка файла - $file_path",'parser');
+ $importer_id = ImportersFiles::findOne(['id' => $file_name])->importer_id;
+ $keys = Importers::findOne( ['id' => $importer_id] )->keys;
+ $config = ['record_id' => $file_name,
+ 'importer_id' => $importer_id,
+ 'parser_config' => ['keys' => $keys,
+ 'mode' => 'console']
+ ];
+ if( $this->parseFileConsole( $file_path, $config ) ){
+ unlink( \Yii::getAlias('@temp_upload') . '/' . $file_name . '.csv' );
+ \Yii::info("Загрузка файла - $file_path успешно завершена",'parser');
+ } else{
+ \Yii::error( "Загрузка файла - $file_path завершена с ошибкой", 'parser' );
+ }
+ //при любом завершении скрипта файл с очереди автозагрузки нужно удалить
+ unlink( \Yii::getAlias('@auto_upload') . '/' . $file_name . '.csv' );
+ }
- //return $this->redirect('serverFiles');
}
- public function actionParseXml ()
- {
- }
protected function parseFileConsole( $file_path, $configuration ){
if( !file_exists( $file_path ) )
- throw new ErrorException("$file_path does not exist!");
+ throw new ErrorException("$file_path - файл не найден!");
$parser_config = [];
if ( isset( $configuration['parser_config'] ) ) {
$parser_config = $configuration['parser_config'];
}
-
$data = \Yii::$app->multiparser->parse( $file_path, $parser_config );
+ if (! $data) {
+ // @todo переделать, что бы ошибка автоматически останавливала сценарий
+ return false;
+ }
$writer = new PriceWriter();
$writer->configuration = $configuration;
$writer->data = $data;
$writer->mode = 1; //console-режим
+
if ( $writer->writeDataToDB() ){
- Console::output('It is working');
+
return true;
}
return false;
}
+ public function actionParseXml ()
+ {
+
+ }
+
public function actionTest ()
{
Console::output('It is working ');
diff --git a/console/migrations/m130524_201442_init.php b/console/migrations/m130524_201442_init.php
deleted file mode 100644
index 81a322a..0000000
--- a/console/migrations/m130524_201442_init.php
+++ /dev/null
@@ -1,34 +0,0 @@
-db->driverName === 'mysql') {
- // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
- $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
- }
-
- $this->createTable('{{%user}}', [
- 'id' => $this->primaryKey(),
- 'username' => $this->string()->notNull()->unique(),
- 'auth_key' => $this->string(32)->notNull(),
- 'password_hash' => $this->string()->notNull(),
- 'password_reset_token' => $this->string()->unique(),
- 'email' => $this->string()->notNull()->unique(),
-
- 'status' => $this->smallInteger()->notNull()->defaultValue(10),
- 'created_at' => $this->integer()->notNull(),
- 'updated_at' => $this->integer()->notNull(),
- ], $tableOptions);
- }
-
- public function down()
- {
- $this->dropTable('{{%user}}');
- }
-}
diff --git a/console/migrations/m150818_125718_create_user_180815.php b/console/migrations/m150818_125718_create_user_180815.php
deleted file mode 100644
index db70571..0000000
--- a/console/migrations/m150818_125718_create_user_180815.php
+++ /dev/null
@@ -1,44 +0,0 @@
- 'admin',
- 'auth_key' => 'admin',
- 'password_hash' => Yii::$app->security->generatePasswordHash('admin'),
- 'password_reset_token' => 'admin',
- 'email'=> 'admin@test.com',
- 'status' => '10',
- 'created_at'=>'000000',
- 'updated_at' => '000000'
- ];
- $this->insert('{{%user}}', $user_array);
- }
-
-
-
- public function down()
- {
- $this->dropTable('{{%user}}');
- }
-
- /*
- // Use safeUp/safeDown to run migration code within a transaction
- public function safeUp()
- {
- }
-
- public function safeDown()
- {
- }
- */
-}
diff --git a/console/migrations/m150831_130250_addImporters.php b/console/migrations/m150831_130250_addImporters.php
deleted file mode 100644
index 2fbc121..0000000
--- a/console/migrations/m150831_130250_addImporters.php
+++ /dev/null
@@ -1,62 +0,0 @@
-db->driverName === 'mysql') {
- $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
- }
-
- $this->createTable('{{%importer}}', [
- 'id' => $this->primaryKey(6)->notNull() . ' AUTO_INCREMENT',
- 'code' =>'varchar(254) NOT NULL',
- 'name' => 'varchar(254) NOT NULL',
- 'name_price' => 'varchar(254) NOT NULL',
- 'currency_id' => 'int(3) unsigned NOT NULL',
- 'delivery' => 'varchar(254) NOT NULL',
- 'email' => 'varchar(254) NOT NULL',
- 'info' => 'text NOT NULL',
- 'active' => 'tinyint(1) unsigned NOT NULL DEFAULT 1',
- 'PARSER_IS_ACTIVE' => 'tinyint(1) unsigned NOT NULL DEFAULT 0',
- 'PARSER_COLUMN_COUNT' => 'int(6) unsigned DEFAULT NULL',
- 'PARSER_FIELD_BRAND' => 'int(3) unsigned DEFAULT NULL',
- 'PARSER_FIELD_ARTICLE' => 'int(3) unsigned DEFAULT NULL',
- 'PARSER_FIELD_ARTICLE_PREFIX' => 'tinyint(1) unsigned NOT NULL DEFAULT 0',
- 'PARSER_FIELD_PRICE' => 'int(3) unsigned DEFAULT NULL',
- 'PARSER_FIELD_DESCR' =>'int(3) unsigned DEFAULT NULL',
- 'PARSER_FIELD_BOX' => 'int(3) unsigned DEFAULT NULL',
- 'PARSER_FIELD_ADD_BOX' => 'int(3) unsigned DEFAULT NULL',
- 'PARSER_FIELD_GROUP_RG' => 'int(3) unsigned DEFAULT NULL',
- 'PARSER_FIELD_SIGN' => 'varchar(1) NOT NULL',
- 'PARSER_FIELD_MULTIPLIER' => 'float(8,2) unsigned DEFAULT NULL',
- 'price_date_update' => 'varchar(15) NOT NULL'
-
- ], $tableOptions);
-
- $this->createIndex('code', '{{%importer}}', 'code', true);
- $this->createIndex('name', '{{%importer}}', 'name', true);
- $this->createIndex('active', '{{%importer}}', 'active', false);
- }
-
- public function down()
- {
- $this->dropTable('{{%importer}}');
-
- }
-
- /*
- // Use safeUp/safeDown to run migration code within a transaction
- public function safeUp()
- {
- }
-
- public function safeDown()
- {
- }
- */
-}
diff --git a/console/migrations/m150901_135806_addImportersFiles.php b/console/migrations/m150901_135806_addImportersFiles.php
deleted file mode 100644
index 647e773..0000000
--- a/console/migrations/m150901_135806_addImportersFiles.php
+++ /dev/null
@@ -1,42 +0,0 @@
-db->driverName === 'mysql') {
- $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
- }
-
- $this->createTable('{{%importer_files}}', [
- 'id' => $this->primaryKey(10)->notNull() . ' AUTO_INCREMENT',
- 'importer_id' => 'int(6) unsigned NOT NULL',
- 'upload_time' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',
- 'time_start' => 'timestamp NULL DEFAULT NULL',
- 'time_end' => 'timestamp NULL DEFAULT NULL',
- ], $tableOptions);
-
-
- $this->createIndex('importer_id', '{{%importer_files}}', 'importer_id, time_start', false);
- }
-
- public function down()
- {
- $this->dropTable('{{%importer_files}}');
- }
-
- /*
- // Use safeUp/safeDown to run migration code within a transaction
- public function safeUp()
- {
- }
-
- public function safeDown()
- {
- }
- */
-}
diff --git a/console/migrations/m150901_141850_addImportersPrefix.php b/console/migrations/m150901_141850_addImportersPrefix.php
deleted file mode 100644
index a59f15a..0000000
--- a/console/migrations/m150901_141850_addImportersPrefix.php
+++ /dev/null
@@ -1,41 +0,0 @@
-db->driverName === 'mysql') {
- $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
- }
-
- $this->createTable('{{%importer_prefix}}', [
- 'id' => $this->primaryKey(10)->notNull() . ' AUTO_INCREMENT',
- 'importer_id' => 'int(6) unsigned NOT NULL',
- 'brand' => 'varchar(100) NOT NULL',
- 'prefix' => 'varchar(50) NOT NULL',
- 'timestamp' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',
- ], $tableOptions);
-
- $this->createIndex('importer_id', '{{%importer_prefix}}', 'importer_id, brand, prefix', true);
- }
-
- public function down()
- {
- $this->dropTable('{{%importer_prefix}}');
- }
-
- /*
- // Use safeUp/safeDown to run migration code within a transaction
- public function safeUp()
- {
- }
-
- public function safeDown()
- {
- }
- */
-}
diff --git a/console/migrations/m150915_125129_addDetails.php b/console/migrations/m150915_125129_addDetails.php
deleted file mode 100644
index d8d5419..0000000
--- a/console/migrations/m150915_125129_addDetails.php
+++ /dev/null
@@ -1,40 +0,0 @@
-execute('CREATE TABLE `details` (
- `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `IMPORT_ID` int(6) unsigned NOT NULL,
- `BRAND` varchar(100) NOT NULL,
- `ARTICLE` varchar(100) NOT NULL,
- `FULL_ARTICLE` varchar(150) NOT NULL,
- `PRICE` float(15,2) unsigned NOT NULL,
- `DESCR` varchar(200) NOT NULL,
- `BOX` int(6) unsigned NOT NULL,
- `ADD_BOX` int(6) unsigned NOT NULL DEFAULT 0,
- `GROUP` varchar(200) NOT NULL DEFAULT \'\',
- `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`ARTICLE`,`BRAND`,`IMPORT_ID`),
- UNIQUE KEY `ID_delete` (`ID`),
- KEY `timestamp` (`timestamp`),
- KEY `ARTICLE` (`ARTICLE`,`BRAND`,`BOX`),
- KEY `BRAND` (`BRAND`,`ARTICLE`),
- KEY `ARTICLE_2` (`ARTICLE`,`BRAND`,`ADD_BOX`),
- KEY `IMPORT_ID` (`IMPORT_ID`,`ARTICLE`),
- KEY `IMPORT_ID_2` (`IMPORT_ID`,`timestamp`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8');
-
- }
-
- public function down()
- {
- $this->dropTable('{{%details}}');
-
- }
-
-}
diff --git a/console/migrations/m150922_094313_change_key_ImportFiles.php b/console/migrations/m150922_094313_change_key_ImportFiles.php
deleted file mode 100644
index 5606ec2..0000000
--- a/console/migrations/m150922_094313_change_key_ImportFiles.php
+++ /dev/null
@@ -1,22 +0,0 @@
-dropIndex('importer_id', '{{%importer_files}}');
- $this->createIndex('importer_id', '{{%importer_files}}', 'importer_id, upload_time', false);
- }
-
- public function down()
- {
- $this->dropIndex('importer_id', '{{%importer_files}}');
- $this->createIndex('importer_id', '{{%importer_files}}', 'importer_id, time_start', false);
- }
-
-
-}
diff --git a/console/migrations/m150922_144040_change_Importer_dataPrice.php b/console/migrations/m150922_144040_change_Importer_dataPrice.php
deleted file mode 100644
index f62873d..0000000
--- a/console/migrations/m150922_144040_change_Importer_dataPrice.php
+++ /dev/null
@@ -1,21 +0,0 @@
-alterColumn('{{%importer}}','price_date_update','TIMESTAMP' );
- $this->createIndex('price_date', '{{%importer}}', 'price_date_update', false);
- }
-
- public function down()
- {
- $this->alterColumn('{{%importer}}','price_date','varchar(15)' );
- $this->dropIndex('price_date', '{{%importer}}');
- }
-
-
-}
diff --git a/storage/676b4e1f18a2f68d1bf59850e8cafabc/x.png b/storage/676b4e1f18a2f68d1bf59850e8cafabc/x.png
new file mode 100644
index 0000000..cdcb6c9
Binary files /dev/null and b/storage/676b4e1f18a2f68d1bf59850e8cafabc/x.png differ
diff --git a/vendor/yiisoft/multiparser/Converter.php b/vendor/yiisoft/multiparser/Converter.php
index 1b44f15..e5d8524 100644
--- a/vendor/yiisoft/multiparser/Converter.php
+++ b/vendor/yiisoft/multiparser/Converter.php
@@ -51,7 +51,7 @@ class Converter extends Behavior
public static function convertToString($value)
{
- $res = '';
+ $res = $value;
if (is_array($value)) {
$res = Encoder::encodeArray($value);
@@ -98,8 +98,6 @@ class Converter extends Behavior
*/
public static function convertByConfiguration( $arr, $configuration )
{
- $result = $arr;
- // \common\components\CustomVarDamp::dumpAndDie( $result );
$hasKey = isset( $configuration['hasKey'] );
foreach ( $configuration['configuration'] as $key => $value ) {
if ( $hasKey ){
@@ -108,14 +106,14 @@ class Converter extends Behavior
//если пустой массив то конвертируем всю строку
if (count( $value ) === 0 ){
- $result = self::$key( $arr );
+ $arr = self::$key( $arr );
continue;
}
// иначе конвертируем каждую ячейку в отдельности
foreach ($value as $sub_value) {
if (isset($arr[$sub_value])) {
// конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле
- $result[$sub_value] = self::$key( $arr[$sub_value] );
+ $arr[$sub_value] = self::$key( $arr[$sub_value] );
}
}
@@ -123,19 +121,20 @@ class Converter extends Behavior
if (isset($arr[$value])) {
// конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле
- $result[$value] = self::$key( $arr[$value] );
+ $arr[$value] = self::$key( $arr[$value] );
+ // CustomVarDamp::dump($result);
}
}
} else {
// нет заголовка - мы можем конвертировать только строку в целом
- $result = self::$key( $arr );
+ $arr = self::$key( $arr );
}
}
- return $result;
+ return $arr;
}
--
libgit2 0.21.4