Skip to content

Commit

Permalink
Merge pull request #1869 from magento-borg/MAGETWO-85893-2.3-develop-…
Browse files Browse the repository at this point in the history
…merge

[borg] MAGETWO-85893: Updating 2.3-develop
  • Loading branch information
pdohogne-magento authored Dec 20, 2017
2 parents 5017fda + fc97826 commit 9b50b19
Show file tree
Hide file tree
Showing 125 changed files with 4,634 additions and 1,785 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,75 +7,93 @@

namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute;

use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Controller\Adminhtml\Product\Attribute;
use Magento\Catalog\Helper\Product;
use Magento\Catalog\Model\Product\AttributeSet\BuildFactory;
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator;
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory;
use Magento\Eav\Model\Entity\Attribute\Set;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory;
use Magento\Framework\Cache\FrontendInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filter\FilterManager;
use Magento\Framework\Registry;
use Magento\Framework\View\LayoutFactory;
use Magento\Framework\View\Result\PageFactory;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute
class Save extends Attribute
{
/**
* @var \Magento\Catalog\Model\Product\AttributeSet\BuildFactory
* @var BuildFactory
*/
protected $buildFactory;

/**
* @var \Magento\Framework\Filter\FilterManager
* @var FilterManager
*/
protected $filterManager;

/**
* @var \Magento\Catalog\Helper\Product
* @var Product
*/
protected $productHelper;

/**
* @var \Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory
* @var AttributeFactory
*/
protected $attributeFactory;

/**
* @var \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory
* @var ValidatorFactory
*/
protected $validatorFactory;

/**
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory
* @var CollectionFactory
*/
protected $groupCollectionFactory;

/**
* @var \Magento\Framework\View\LayoutFactory
* @var LayoutFactory
*/
private $layoutFactory;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Cache\FrontendInterface $attributeLabelCache
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Catalog\Model\Product\AttributeSet\BuildFactory $buildFactory
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory $attributeFactory
* @param \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory
* @param \Magento\Framework\Filter\FilterManager $filterManager
* @param \Magento\Catalog\Helper\Product $productHelper
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
* @param Context $context
* @param FrontendInterface $attributeLabelCache
* @param Registry $coreRegistry
* @param BuildFactory $buildFactory
* @param PageFactory $resultPageFactory
* @param AttributeFactory $attributeFactory
* @param ValidatorFactory $validatorFactory
* @param CollectionFactory $groupCollectionFactory
* @param FilterManager $filterManager
* @param Product $productHelper
* @param LayoutFactory $layoutFactory
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Cache\FrontendInterface $attributeLabelCache,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Catalog\Model\Product\AttributeSet\BuildFactory $buildFactory,
\Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory $attributeFactory,
\Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory,
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory,
\Magento\Framework\Filter\FilterManager $filterManager,
\Magento\Catalog\Helper\Product $productHelper,
\Magento\Framework\View\LayoutFactory $layoutFactory
Context $context,
FrontendInterface $attributeLabelCache,
Registry $coreRegistry,
PageFactory $resultPageFactory,
BuildFactory $buildFactory,
AttributeFactory $attributeFactory,
ValidatorFactory $validatorFactory,
CollectionFactory $groupCollectionFactory,
FilterManager $filterManager,
Product $productHelper,
LayoutFactory $layoutFactory
) {
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
$this->buildFactory = $buildFactory;
Expand All @@ -88,7 +106,7 @@ public function __construct(
}

/**
* @return \Magento\Backend\Model\View\Result\Redirect
* @return Redirect
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
Expand All @@ -105,32 +123,43 @@ public function execute()
$name = trim($name);

try {
/** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */
/** @var $attributeSet Set */
$attributeSet = $this->buildFactory->create()
->setEntityTypeId($this->_entityTypeId)
->setSkeletonId($setId)
->setName($name)
->getAttributeSet();
} catch (AlreadyExistsException $alreadyExists) {
$this->messageManager->addError(__('An attribute set named \'%1\' already exists.', $name));
$this->messageManager->addErrorMessage(__('An attribute set named \'%1\' already exists.', $name));
$this->_session->setAttributeData($data);
return $this->returnResult('catalog/*/edit', ['_current' => true], ['error' => true]);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while saving the attribute.'));
$this->messageManager->addExceptionMessage(
$e,
__('Something went wrong while saving the attribute.')
);
}
}

$attributeId = $this->getRequest()->getParam('attribute_id');
$attributeCode = $this->getRequest()->getParam('attribute_code')
?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]);

/** @var $model ProductAttributeInterface */
$model = $this->attributeFactory->create();
if ($attributeId) {
$model->load($attributeId);
}
$attributeCode = $model && $model->getId()
? $model->getAttributeCode()
: $this->getRequest()->getParam('attribute_code');
$attributeCode = $attributeCode ?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]);
if (strlen($attributeCode) > 0) {
$validatorAttrCode = new \Zend_Validate_Regex(
['pattern' => '/^[a-z\x{600}-\x{6FF}][a-z\x{600}-\x{6FF}_0-9]{0,30}$/u']
);
if (!$validatorAttrCode->isValid($attributeCode)) {
$this->messageManager->addError(
$this->messageManager->addErrorMessage(
__(
'Attribute code "%1" is invalid. Please use only letters (a-z), ' .
'numbers (0-9) or underscore(_) in this field, first character should be a letter.',
Expand All @@ -148,11 +177,11 @@ public function execute()

//validate frontend_input
if (isset($data['frontend_input'])) {
/** @var $inputType \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator */
/** @var $inputType Validator */
$inputType = $this->validatorFactory->create();
if (!$inputType->isValid($data['frontend_input'])) {
foreach ($inputType->getMessages() as $message) {
$this->messageManager->addError($message);
$this->messageManager->addErrorMessage($message);
}
return $this->returnResult(
'catalog/*/edit',
Expand All @@ -162,18 +191,14 @@ public function execute()
}
}

/* @var $model \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
$model = $this->attributeFactory->create();

if ($attributeId) {
$model->load($attributeId);
if (!$model->getId()) {
$this->messageManager->addError(__('This attribute no longer exists.'));
$this->messageManager->addErrorMessage(__('This attribute no longer exists.'));
return $this->returnResult('catalog/*/', [], ['error' => true]);
}
// entity type check
if ($model->getEntityTypeId() != $this->_entityTypeId) {
$this->messageManager->addError(__('We can\'t update the attribute.'));
$this->messageManager->addErrorMessage(__('We can\'t update the attribute.'));
$this->_session->setAttributeData($data);
return $this->returnResult('catalog/*/', [], ['error' => true]);
}
Expand All @@ -193,7 +218,7 @@ public function execute()
);
}

$data += ['is_filterable' => 0, 'is_filterable_in_search' => 0, 'apply_to' => []];
$data += ['is_filterable' => 0, 'is_filterable_in_search' => 0];

if ($model->getIsUserDefined() === null || $model->getIsUserDefined() != 0) {
$data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
Expand Down Expand Up @@ -241,7 +266,7 @@ public function execute()

try {
$model->save();
$this->messageManager->addSuccess(__('You saved the product attribute.'));
$this->messageManager->addSuccessMessage(__('You saved the product attribute.'));

$this->_attributeLabelCache->clean();
$this->_session->setAttributeData(false);
Expand All @@ -265,7 +290,7 @@ public function execute()
}
return $this->returnResult('catalog/*/', [], ['error' => false]);
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
$this->_session->setAttributeData($data);
return $this->returnResult(
'catalog/*/edit',
Expand All @@ -281,7 +306,7 @@ public function execute()
* @param string $path
* @param array $params
* @param array $response
* @return \Magento\Framework\Controller\Result\Json|\Magento\Backend\Model\View\Result\Redirect
* @return Json|Redirect
*/
private function returnResult($path = '', array $params = [], array $response = [])
{
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Cms/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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;

Expand Down Expand Up @@ -57,6 +56,10 @@ protected function _construct()
*/
public function beforeSave()
{
if ($this->hasDataChanges()) {
$this->setUpdateTime(null);
}

$needle = 'block_id="' . $this->getId() . '"';
if (false == strstr($this->getContent(), $needle)) {
return parent::beforeSave();
Expand Down
7 changes: 5 additions & 2 deletions app/code/Magento/Cms/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
namespace Magento\Cms\Model;

use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Model\ResourceModel\Page as ResourceCmsPage;
use Magento\Cms\Helper\Page as PageHelper;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Magento\Cms\Helper\Page as PageHelper;

/**
* Cms Page Model
Expand Down Expand Up @@ -547,6 +546,10 @@ public function beforeSave()
$originalIdentifier = $this->getOrigData('identifier');
$currentIdentifier = $this->getIdentifier();

if ($this->hasDataChanges()) {
$this->setUpdateTime(null);
}

if (!$this->getId() || $originalIdentifier === $currentIdentifier) {
return parent::beforeSave();
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Cms/Model/ResourceModel/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

use Magento\Cms\Api\Data\BlockInterface;
use Magento\Framework\DB\Select;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Store\Model\Store;
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Cms/Model/ResourceModel/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

namespace Magento\Cms\Model\ResourceModel;

use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Model\Page as CmsPage;
use Magento\Framework\DB\Select;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Framework\Stdlib\DateTime;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\EntityManager\EntityManager;
use Magento\Cms\Api\Data\PageInterface;

/**
* Cms page mysql resource
Expand Down
Loading

0 comments on commit 9b50b19

Please sign in to comment.