Skip to content

Commit cab017a

Browse files
committed
EE Staging compatibility + Media & Related code refactoring
1 parent 0f75757 commit cab017a

File tree

10 files changed

+873
-642
lines changed

10 files changed

+873
-642
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [not-released]
5+
## [100.2.0] - 2017-02-03
6+
7+
* add: code refactoring for media and related
8+
* add: compatibility with staging modules
9+
10+
## [100.1.2] - 2017-02-01
611

712
* fix: load model import
813
* fix: Use the configured category suffix instead of hardcoded.html

Category/Model/Factory/Import.php

+24-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use \Magento\Framework\App\Cache\TypeListInterface;
1212
use \Magento\Framework\Module\Manager as moduleManager;
1313
use \Magento\Framework\App\Config\ScopeConfigInterface as scopeConfig;
14+
use \Magento\Staging\Model\VersionManager;
1415
use \Zend_Db_Expr as Expr;
1516
use \Exception;
1617

@@ -229,6 +230,20 @@ public function createEntities()
229230
$connection = $this->_entities->getResource()->getConnection();
230231
$tmpTable = $this->_entities->getTableName($this->getCode());
231232

233+
if ($connection->isTableExists($connection->getTableName('sequence_catalog_category'))) {
234+
$values = array(
235+
'sequence_value' => '_entity_id',
236+
);
237+
$parents = $connection->select()->from($tmpTable, $values);
238+
$connection->query(
239+
$connection->insertFromSelect(
240+
$parents, $connection->getTableName('sequence_catalog_category'), array_keys($values), 1
241+
)
242+
);
243+
}
244+
245+
$table = $connection->getTableName('catalog_category_entity');
246+
232247
$values = array(
233248
'entity_id' => '_entity_id',
234249
'attribute_set_id' => new Expr(3),
@@ -239,17 +254,24 @@ public function createEntities()
239254
'level' => 'level',
240255
'children_count' => new Expr('0'),
241256
);
257+
258+
if ($this->_entities->getColumnIdentifier($table) == 'row_id') {
259+
$values['row_id'] = '_entity_id';
260+
$values['created_in'] = new Expr(1);
261+
$values['updated_in'] = new Expr(VersionManager::MAX_VERSION);
262+
}
263+
242264
$parents = $connection->select()->from($tmpTable, $values);
243265
$connection->query(
244266
$connection->insertFromSelect(
245-
$parents, $connection->getTableName('catalog_category_entity'), array_keys($values), 1
267+
$parents, $table, array_keys($values), 1
246268
)
247269
);
248270

249271
$values = array(
250272
'created_at' => new Expr('now()')
251273
);
252-
$connection->update($connection->getTableName('catalog_category_entity'), $values, 'created_at IS NULL');
274+
$connection->update($table, $values, 'created_at IS NULL');
253275
}
254276

255277
/**

Entities/Model/Entities.php

+11
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ public function setValues($tableSuffix, $entityTable, $values, $entityTypeId, $s
187187
return $this;
188188
}
189189

190+
/**
191+
* Retrieve column identifier
192+
*
193+
* @param string $table
194+
* @return string
195+
*/
196+
public function getColumnIdentifier($table)
197+
{
198+
return $this->_getResource()->getColumnIdentifier($table);
199+
}
200+
190201
/**
191202
* Copy column to an other
192203
*

Entities/Model/ResourceModel/Entities.php

+28-3
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ public function matchEntity($tableName, $pimKey, $entityTable, $entityKey, $impo
293293
$pimgentoTable = $connection->getTableName('pimgento_entities');
294294
$entityTable = $connection->getTableName($entityTable);
295295

296+
if ($entityKey == 'entity_id') {
297+
$entityKey = $this->getColumnIdentifier($entityTable);
298+
}
299+
296300
/* Update entity_id column from pimgento_entities table */
297301
$connection->query('
298302
UPDATE `' . $tableName . '` t
@@ -370,25 +374,28 @@ public function setValues($tableName, $entityTable, $values, $entityTypeId, $sto
370374
foreach ($values as $code => $value) {
371375
if (($attribute = $this->getAttribute($code, $entityTypeId))) {
372376
if ($attribute['backend_type'] !== 'static') {
377+
$backendType = $attribute['backend_type'];
378+
379+
$identifier = $this->getColumnIdentifier($entityTable . '_' . $backendType);
380+
373381
$select = $connection->select()
374382
->from(
375383
$tableName,
376384
array(
377385
'attribute_id' => new Expr($attribute['attribute_id']),
378386
'store_id' => new Expr($storeId),
379-
'entity_id' => '_entity_id',
387+
$identifier => '_entity_id',
380388
'value' => $value
381389
)
382390
);
383391
if ($connection->tableColumnExists($tableName, $value)) {
384392
$select->where('TRIM(`' . $value . '`) <> ?', new Expr('""'));
385393
}
386-
$backendType = $attribute['backend_type'];
387394

388395
$insert = $connection->insertFromSelect(
389396
$select,
390397
$connection->getTableName($entityTable . '_' . $backendType),
391-
array('attribute_id', 'store_id', 'entity_id', 'value'),
398+
array('attribute_id', 'store_id', $identifier, 'value'),
392399
$mode
393400
);
394401
$connection->query($insert);
@@ -465,4 +472,22 @@ protected function formatColumn($column)
465472
return trim(str_replace(PHP_EOL, '', preg_replace('/\s+/', ' ', trim($column))), '""');
466473
}
467474

475+
/**
476+
* Retrieve if row id column exists
477+
*
478+
* @param string $table
479+
* @param string $identifier
480+
* @return string
481+
*/
482+
public function getColumnIdentifier($table, $identifier = 'entity_id')
483+
{
484+
$connection = $this->getConnection();
485+
486+
if ($connection->tableColumnExists($table, 'row_id')) {
487+
$identifier = 'row_id';
488+
}
489+
490+
return $identifier;
491+
}
492+
468493
}

Product/Helper/Media.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function getMediaAbsolutePath()
179179
*/
180180
public function isCleanFiles()
181181
{
182-
return $this->imageConfig['clean_files'];
182+
return isset($this->imageConfig['clean_files']) ? $this->imageConfig['clean_files'] : 0;
183183
}
184184

185185
/**
@@ -199,7 +199,7 @@ public function getMediaGalleryAttributeId()
199199
*/
200200
public function cleanFiles()
201201
{
202-
$folder = $this->getImportFolder().'files/';
202+
$folder = $this->getImportFolder() . 'files/';
203203

204204
if (is_dir($folder)) {
205205
$this->delTree($folder);

0 commit comments

Comments
 (0)