Skip to content

Commit

Permalink
Merge pull request #264 from magento-south/MAGETWO-41241
Browse files Browse the repository at this point in the history
[South] CMS Staging. Adaptation
  • Loading branch information
slavvka committed Dec 24, 2015
2 parents b37999c + 854c816 commit eee63de
Show file tree
Hide file tree
Showing 26 changed files with 1,355 additions and 288 deletions.
12 changes: 8 additions & 4 deletions app/code/Magento/Cms/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
namespace Magento\Cms\Model;

use Magento\Cms\Api\Data\BlockInterface;
use Magento\Cms\Model\ResourceModel\Block as ResourceCmsBlock;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Model\AbstractModel;

/**
* CMS block model
*
* @method \Magento\Cms\Model\ResourceModel\Block _getResource()
* @method \Magento\Cms\Model\ResourceModel\Block getResource()
* @method ResourceCmsBlock _getResource()
* @method ResourceCmsBlock getResource()
* @method Block setStoreId(array $storeId)
* @method array getStoreId()
*/
class Block extends \Magento\Framework\Model\AbstractModel implements BlockInterface, IdentityInterface
class Block extends AbstractModel implements BlockInterface, IdentityInterface
{
/**
* CMS block cache tag
Expand Down Expand Up @@ -51,7 +55,7 @@ protected function _construct()
/**
* Prevent blocks recursion
*
* @return \Magento\Framework\Model\AbstractModel
* @return AbstractModel
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function beforeSave()
Expand Down
10 changes: 7 additions & 3 deletions app/code/Magento/Cms/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
namespace Magento\Cms\Model;

use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Model\ResourceModel\Page as ResourceCmsPage;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Model\AbstractModel;

/**
* Cms Page Model
*
* @method \Magento\Cms\Model\ResourceModel\Page _getResource()
* @method \Magento\Cms\Model\ResourceModel\Page getResource()
* @method ResourceCmsPage _getResource()
* @method ResourceCmsPage getResource()
* @method Page setStoreId(array $storeId)
* @method array getStoreId()
*/
class Page extends \Magento\Framework\Model\AbstractModel implements PageInterface, IdentityInterface
class Page extends AbstractModel implements PageInterface, IdentityInterface
{
/**
* No route page id
Expand Down
38 changes: 23 additions & 15 deletions app/code/Magento/Cms/Model/ResourceModel/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ abstract class AbstractCollection extends \Magento\Framework\Model\ResourceModel
*/
protected $storeManager;

/**
* @var \Magento\Framework\Model\Entity\MetadataPool
*/
protected $metadataPool;

/**
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
*/
Expand All @@ -32,45 +38,47 @@ public function __construct(
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Model\Entity\MetadataPool $metadataPool,
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
) {
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
$this->storeManager = $storeManager;
$this->metadataPool = $metadataPool;
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
}

/**
* Perform operations after collection load
*
* @param string $tableName
* @param string $columnName
* @param string|null $linkField
* @return void
*/
protected function performAfterLoad($tableName, $columnName)
protected function performAfterLoad($tableName, $linkField)
{
$items = $this->getColumnValues($columnName);
if (count($items)) {
$linkedIds = $this->getColumnValues($linkField);
if (count($linkedIds)) {
$connection = $this->getConnection();
$select = $connection->select()->from(['cms_entity_store' => $this->getTable($tableName)])
->where('cms_entity_store.' . $columnName . ' IN (?)', $items);
->where('cms_entity_store.' . $linkField . ' IN (?)', $linkedIds);
$result = $connection->fetchPairs($select);
if ($result) {
foreach ($this as $item) {
$entityId = $item->getData($columnName);
if (!isset($result[$entityId])) {
$linkedId = $item->getData($linkField);
if (!isset($result[$linkedId])) {
continue;
}
if ($result[$entityId] == 0) {
if ($result[$linkedId] == 0) {
$stores = $this->storeManager->getStores(false, true);
$storeId = current($stores)->getId();
$storeCode = key($stores);
} else {
$storeId = $result[$item->getData($columnName)];
$storeId = $result[$linkedId];
$storeCode = $this->storeManager->getStore($storeId)->getCode();
}
$item->setData('_first_store_id', $storeId);
$item->setData('store_code', $storeCode);
$item->setData('store_id', [$result[$entityId]]);
$item->setData('store_id', [$result[$linkedId]]);
}
}
}
Expand Down Expand Up @@ -129,18 +137,18 @@ protected function performAddStoreFilter($store, $withAdmin = true)
* Join store relation table if there is store filter
*
* @param string $tableName
* @param string $columnName
* @param string|null $linkField
* @return void
*/
protected function joinStoreRelationTable($tableName, $columnName)
protected function joinStoreRelationTable($tableName, $linkField)
{
if ($this->getFilter('store')) {
$this->getSelect()->join(
['store_table' => $this->getTable($tableName)],
'main_table.' . $columnName . ' = store_table.' . $columnName,
'main_table.' . $linkField . ' = store_table.' . $linkField,
[]
)->group(
'main_table.' . $columnName
'main_table.' . $linkField
);
}
parent::_renderFiltersBefore();
Expand Down
Loading

0 comments on commit eee63de

Please sign in to comment.