|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / app / code / Mageplaza / ImportExportCMS / Model / |
Filename | /home/dev2.destoffenstraat.com/app/code/Mageplaza/ImportExportCMS/Model/Block.php |
Size | 4.27 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 27-May-2021 03:54 |
Last accessed | 21-Aug-2025 22:39 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_ImportExportCMS
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\ImportExportCMS\Model;
use Magento\Cms\Model\Block as CmsBlock;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\ImportExport\Model\Import;
use Mageplaza\ImportExportCMS\Block\Adminhtml\Import\Result;
/**
* Class Block
*
* @package Mageplaza\ImportExportCMS\Model
*/
class Block extends AbstractImport
{
const MP_BLOCK_CMS_TABLE_NAME = 'cms_block';
const MP_BLOCK_STORE_CMS_TABLE_NAME = 'cms_block_store';
/**
* Valid column names
*
* @array
*/
protected $_validColumnNames = [
self::COL_TITLE,
self::COL_IDENTIFIER,
self::COL_CONTENT,
self::COL_STORE_ID,
self::COL_CREATION_TIME,
self::COL_UPDATE_TIME,
self::COL_IS_ACTIVE
];
/**
* @var array
*/
protected $_permanentAttributes = [
self::COL_TITLE,
self::COL_IDENTIFIER,
self::COL_CONTENT,
self::COL_STORE_ID,
self::COL_IS_ACTIVE
];
/**
* @var array
*/
protected $_listIdentifier = [];
/**
* @param Result $resultBlock
*/
protected function _saveAndReplaceEntity($resultBlock)
{
$behavior = $this->getBehavior();
$delimiter = ($this->getData(Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR)) ?: ',';
$edition = $this->_productMetadata->getEdition();
$blockCmsInfo = [
'cms_id' => (in_array($edition, ['Enterprise', 'B2B'])) ? 'row_id' : 'block_id',
'table_name' => $this->_resourceConnection->getTableName(self::MP_BLOCK_CMS_TABLE_NAME),
'store_table_name' => $this->_resourceConnection->getTableName(self::MP_BLOCK_STORE_CMS_TABLE_NAME),
'model' => $this->_blockFactory->create()
];
while ($bunch = $this->_importData->getNextBunch()) {
$entityList = $this->collectEntityList($bunch, $delimiter);
$listIdentifier = $this->_listIdentifier;
if (Import::BEHAVIOR_REPLACE == $behavior
&& $listIdentifier
&& $this->_deleteEntityFinish(array_unique($listIdentifier), $resultBlock)) {
$this->_saveEntityFinish($entityList, $resultBlock, $blockCmsInfo, Import::BEHAVIOR_REPLACE);
} elseif (Import::BEHAVIOR_APPEND == $behavior) {
$this->_saveEntityFinish($entityList, $resultBlock, $blockCmsInfo, Import::BEHAVIOR_APPEND);
}
}
}
/**
* @param array $bunch
* @param string $delimiter
*
* @return array
*/
public function collectEntityList($bunch, $delimiter)
{
$entityList = [];
foreach ($bunch as $rowData) {
$storeIds = explode($delimiter, $rowData[self::COL_STORE_ID]);
$rowData[self::COL_STORE_ID] = $storeIds;
if (!isset($rowData[self::COL_CREATION_TIME])) {
$rowData[self::COL_CREATION_TIME] = $this->_dateTime->date();
}
if (!isset($rowData[self::COL_UPDATE_TIME])) {
$rowData[self::COL_UPDATE_TIME] = $this->_dateTime->date();
}
$this->_listIdentifier[] = $rowData[self::COL_IDENTIFIER];
$entityList[] = $rowData;
}
return $entityList;
}
/**
* @return AbstractCollection
*/
protected function _getCmsCollection()
{
return $this->_blockFactory->create()->getCollection();
}
/**
* @param string $cmsId
*
* @return CmsBlock
*/
protected function _getCmsById($cmsId)
{
return $this->_blockFactory->create()->load($cmsId);
}
}
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_ImportExportCMS
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\ImportExportCMS\Model;
use Magento\Cms\Model\Block as CmsBlock;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\ImportExport\Model\Import;
use Mageplaza\ImportExportCMS\Block\Adminhtml\Import\Result;
/**
* Class Block
*
* @package Mageplaza\ImportExportCMS\Model
*/
class Block extends AbstractImport
{
const MP_BLOCK_CMS_TABLE_NAME = 'cms_block';
const MP_BLOCK_STORE_CMS_TABLE_NAME = 'cms_block_store';
/**
* Valid column names
*
* @array
*/
protected $_validColumnNames = [
self::COL_TITLE,
self::COL_IDENTIFIER,
self::COL_CONTENT,
self::COL_STORE_ID,
self::COL_CREATION_TIME,
self::COL_UPDATE_TIME,
self::COL_IS_ACTIVE
];
/**
* @var array
*/
protected $_permanentAttributes = [
self::COL_TITLE,
self::COL_IDENTIFIER,
self::COL_CONTENT,
self::COL_STORE_ID,
self::COL_IS_ACTIVE
];
/**
* @var array
*/
protected $_listIdentifier = [];
/**
* @param Result $resultBlock
*/
protected function _saveAndReplaceEntity($resultBlock)
{
$behavior = $this->getBehavior();
$delimiter = ($this->getData(Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR)) ?: ',';
$edition = $this->_productMetadata->getEdition();
$blockCmsInfo = [
'cms_id' => (in_array($edition, ['Enterprise', 'B2B'])) ? 'row_id' : 'block_id',
'table_name' => $this->_resourceConnection->getTableName(self::MP_BLOCK_CMS_TABLE_NAME),
'store_table_name' => $this->_resourceConnection->getTableName(self::MP_BLOCK_STORE_CMS_TABLE_NAME),
'model' => $this->_blockFactory->create()
];
while ($bunch = $this->_importData->getNextBunch()) {
$entityList = $this->collectEntityList($bunch, $delimiter);
$listIdentifier = $this->_listIdentifier;
if (Import::BEHAVIOR_REPLACE == $behavior
&& $listIdentifier
&& $this->_deleteEntityFinish(array_unique($listIdentifier), $resultBlock)) {
$this->_saveEntityFinish($entityList, $resultBlock, $blockCmsInfo, Import::BEHAVIOR_REPLACE);
} elseif (Import::BEHAVIOR_APPEND == $behavior) {
$this->_saveEntityFinish($entityList, $resultBlock, $blockCmsInfo, Import::BEHAVIOR_APPEND);
}
}
}
/**
* @param array $bunch
* @param string $delimiter
*
* @return array
*/
public function collectEntityList($bunch, $delimiter)
{
$entityList = [];
foreach ($bunch as $rowData) {
$storeIds = explode($delimiter, $rowData[self::COL_STORE_ID]);
$rowData[self::COL_STORE_ID] = $storeIds;
if (!isset($rowData[self::COL_CREATION_TIME])) {
$rowData[self::COL_CREATION_TIME] = $this->_dateTime->date();
}
if (!isset($rowData[self::COL_UPDATE_TIME])) {
$rowData[self::COL_UPDATE_TIME] = $this->_dateTime->date();
}
$this->_listIdentifier[] = $rowData[self::COL_IDENTIFIER];
$entityList[] = $rowData;
}
return $entityList;
}
/**
* @return AbstractCollection
*/
protected function _getCmsCollection()
{
return $this->_blockFactory->create()->getCollection();
}
/**
* @param string $cmsId
*
* @return CmsBlock
*/
protected function _getCmsById($cmsId)
{
return $this->_blockFactory->create()->load($cmsId);
}
}