|
1
|
|
|
<?php
|
|
2
|
|
|
/**
|
|
3
|
|
|
* @author Alexey Tatarinov <[email protected]>
|
|
4
|
|
|
* @link https://github.com/shogodev/argilla/
|
|
5
|
|
|
* @copyright Copyright © 2003-2015 Shogo
|
|
6
|
|
|
* @license http://argilla.ru/LICENSE
|
|
7
|
|
|
*/
|
|
8
|
|
|
|
|
9
|
|
|
Yii::import('backend.modules.product.modules.import.components.*');
|
|
10
|
|
|
chdir(GlobalConfig::instance()->rootPath);
|
|
11
|
|
|
|
|
12
|
|
|
// Игнорируем E_NOTICE и E_NOTICE прежде всего для phpThumb, чтобы не прерывить импорт
|
|
13
|
|
|
error_reporting(E_ALL & ~E_NOTICE & ~E_NOTICE);
|
|
14
|
|
|
|
|
15
|
|
|
class ImagesImportCommand extends AbstractImagesImportCommand
|
|
16
|
|
|
{
|
|
17
|
|
|
public function actionIndex()
|
|
18
|
|
|
{
|
|
19
|
|
|
try
|
|
20
|
|
|
{
|
|
21
|
|
|
$this->actionImportFromCsv();
|
|
22
|
|
|
//$this->updateProducts();
|
|
23
|
|
|
}
|
|
24
|
|
|
catch(Exception $e)
|
|
25
|
|
|
{
|
|
26
|
|
|
$this->logger->error($e->getMessage());
|
|
27
|
|
|
}
|
|
28
|
|
|
}
|
|
29
|
|
|
|
|
30
|
|
|
public function actionImportFromCsv()
|
|
31
|
|
|
{
|
|
32
|
|
|
$imageWriter = new ImageWriter($this->logger);
|
|
33
|
|
|
$imageWriter->previews = array(
|
|
34
|
|
|
'origin' => array(4500, 4500),
|
|
35
|
|
|
'big' => array(600, 460),
|
|
36
|
|
|
'pre' => array(250, 190),
|
|
37
|
|
|
);
|
|
38
|
|
|
$imageWriter->uniqueAttribute = 'id';
|
|
39
|
|
|
$imageWriter->clear = false;
|
|
40
|
|
|
$imageWriter->clearTables = array('{{product_img}}');
|
|
41
|
|
|
$imageWriter->defaultJpegQuality = 95;
|
|
42
|
|
|
$imageWriter->phpThumbErrorExceptionToWarning = true;
|
|
43
|
|
|
$imageWriter->actionWithSameFiles = ImageWriter::FILE_ACTION_RENAME_NEW_FILE;
|
|
44
|
|
|
$imageWriter->actionWithExistingRecord = ImageWriter::DB_ACTION_EXISTING_RECORD_SKIP_SILENT;
|
|
45
|
|
|
|
|
46
|
|
|
$imageAggregator = new ImageAggregator($imageWriter);
|
|
47
|
|
|
$imageAggregator->groupByColumn = ImportHelper::lettersToNumber('a');
|
|
48
|
|
|
$imageAggregator->imagesColumns = ImportHelper::convertColumnIndexes(ImportHelper::getLettersRange('b-ab'));
|
|
|
|
|
|
|
49
|
|
|
/* $imageAggregator->replace = array(
|
|
50
|
|
|
'http://openfish.ru/wa-data/public/shop/products/' => ''
|
|
51
|
|
|
);*/
|
|
52
|
|
|
|
|
53
|
|
|
$imageAggregator->collectItemBufferSize = 100;
|
|
54
|
|
|
|
|
55
|
|
|
$csvReader = new ImportCsvReader($this->logger, $imageAggregator);
|
|
56
|
|
|
$csvReader->csvDelimiter = ',';
|
|
57
|
|
|
$csvReader->headerRowIndex = 1;
|
|
58
|
|
|
$csvReader->skipTopRowAmount = 1;
|
|
59
|
|
|
$csvReader->start();
|
|
60
|
|
|
$csvReader->processFiles(ImportHelper::getFiles('f/import_image'));
|
|
61
|
|
|
$csvReader->finish();
|
|
62
|
|
|
}
|
|
63
|
|
|
|
|
64
|
|
|
private function updateProducts()
|
|
|
|
|
|
|
65
|
|
|
{
|
|
66
|
|
|
$sql = array(
|
|
67
|
|
|
'UPDATE `{{product}}` SET visible=1 WHERE 1',
|
|
68
|
|
|
'UPDATE `{{product}}` SET visible=0 WHERE id NOT IN (SELECT parent FROM `{{product_img}}` WHERE 1)',
|
|
69
|
|
|
);
|
|
70
|
|
|
|
|
71
|
|
|
foreach($sql as $query)
|
|
72
|
|
|
{
|
|
73
|
|
|
$command = new CDbCommand(Yii::app()->db, $query);
|
|
74
|
|
|
$command->execute();
|
|
75
|
|
|
}
|
|
76
|
|
|
}
|
|
77
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..