b374k
m1n1 1.01
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/Page.php
Size5.52 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified27-May-2021 03:54
Last accessed23-Aug-2025 01:52
Actionsedit | rename | delete | download (gzip)
Viewtext | 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\Page as CmsPage;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\ImportExport\Model\Import;
use Mageplaza\ImportExportCMS\Block\Adminhtml\Import\Result;

/**
* Class Page
*
* @package Mageplaza\ImportExportCMS\Model
*/
class Page extends AbstractImport
{
const COL_CONTENT_HEADING = 'content_heading';
const COL_META_TITLE = 'meta_title';
const COL_META_KEYWORDS = 'meta_keywords';
const COL_META_DESCRIPTION = 'meta_description';
const COL_LAYOUT = 'page_layout';
const COL_LAYOUT_UPDATE_XML = 'layout_update_xml';
const COL_CUSTOM_DESIGN_FROM = 'custom_theme_from';
const COL_CUSTOM_DESIGN_TO = 'custom_theme_to';
const COL_CUSTOM_DESIGN_ROOT_THEME = 'custom_root_template';
const COL_CUSTOM_DESIGN_THEME = 'custom_theme';
const COL_CUSTOM_DESIGN_LAYOUT = 'custom_layout_update_xml';
const COL_SORT_ORDER = 'sort_order';
const MP_PAGE_CMS_TABLE_NAME = 'cms_page';
const MP_PAGE_STORE_CMS_TABLE_NAME = 'cms_page_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,
self::COL_CONTENT_HEADING,
self::COL_META_TITLE,
self::COL_META_KEYWORDS,
self::COL_META_DESCRIPTION,
self::COL_LAYOUT,
self::COL_LAYOUT_UPDATE_XML,
self::COL_CUSTOM_DESIGN_FROM,
self::COL_CUSTOM_DESIGN_TO,
self::COL_CUSTOM_DESIGN_ROOT_THEME,
self::COL_CUSTOM_DESIGN_THEME,
self::COL_CUSTOM_DESIGN_LAYOUT,
self::COL_SORT_ORDER
];

/**
* @var array
*/
protected $_permanentAttributes = [
self::COL_TITLE,
self::COL_IDENTIFIER,
self::COL_STORE_ID,
self::COL_IS_ACTIVE,
self::COL_LAYOUT
];

/**
* @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();
$pageCmsInfo = [
'cms_id' => (in_array($edition, ['Enterprise', 'B2B'])) ? 'row_id' : 'page_id',
'table_name' => $this->_resourceConnection->getTableName(self::MP_PAGE_CMS_TABLE_NAME),
'store_table_name' => $this->_resourceConnection->getTableName(self::MP_PAGE_STORE_CMS_TABLE_NAME),
'model' => $this->_pageFactory->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, $pageCmsInfo, Import::BEHAVIOR_REPLACE);
} elseif (Import::BEHAVIOR_APPEND == $behavior) {
$this->_saveEntityFinish($entityList, $resultBlock, $pageCmsInfo, 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();
}
if (!isset($rowData[self::COL_SORT_ORDER])) {
$rowData[self::COL_SORT_ORDER] = 0;
}
$this->_listIdentifier[] = $rowData[self::COL_IDENTIFIER];
$entityList[] = $rowData;
}

return $entityList;
}

/**
* @return AbstractCollection
*/
protected function _getCmsCollection()
{
return $this->_pageFactory->create()->getCollection();
}

/**
* @param string $cmsId
*
* @return CmsPage
*/
protected function _getCmsById($cmsId)
{
return $this->_pageFactory->create()->load($cmsId);
}
}