/** * Invalidate WebApi cache if needed. * * @param \Magento\Framework\App\Config\Value $subject * @param \Magento\Framework\App\Config\Value $result * @return \Magento\Framework\App\Config\Value * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterAfterSave(\Magento\Framework\App\Config\Value $subject, \Magento\Framework\App\Config\Value $result) { if ($subject->getPath() == \Magento\WebapiSecurity\Model\Plugin\AnonymousResourceSecurity::XML_ALLOW_INSECURE && $subject->isValueChanged()) { $this->cacheTypeList->invalidate(\Magento\Framework\App\Cache\Type\Webapi::TYPE_IDENTIFIER); } return $result; }
/** * After save handler * * @param \Magento\Framework\App\Config\Value $subject * @param mixed $result * * @return mixed */ public function afterSave(\Magento\Framework\App\Config\Value $subject, $result) { if ($subject->isValueChanged()) { $this->_eavIndexerProcessor->markIndexerAsInvalid(); } return $result; }
public function testProcess() { $path = 'design/head/logo'; $value = 'path/to/logo'; $this->backendModelFactory->expects($this->once())->method('createByPath')->with($path, ['value' => $value])->willReturn($this->backendModel); $this->backendModel->expects($this->once())->method('afterLoad'); $this->backendModel->expects($this->once())->method('getValue')->willReturn($value); $this->assertEquals($value, $this->valueProcessor->process($value, $path)); }
public function testProcess() { $path = 'design/head/logo'; $value = 'path/to/logo'; $scope = 'websites'; $scopeId = 1; $this->backendModelFactory->expects($this->once())->method('createByPath')->with($path, ['value' => $value, 'field_config' => ['path' => $path], 'scope' => $scope, 'scope_id' => $scopeId])->willReturn($this->backendModel); $this->backendModel->expects($this->once())->method('afterLoad'); $this->backendModel->expects($this->once())->method('getValue')->willReturn($value); $this->assertEquals($value, $this->valueProcessor->process($value, $scope, $scopeId, ['path' => $path])); }
public function testCreate() { $scope = 'website'; $scopeId = 1; $data = ['scope' => $scope, 'scopeId' => $scopeId, 'value' => 'value', 'config' => ['path' => 'design/head/default_title', 'backend_model' => 'Magento\\Framework\\App\\Config\\Value']]; $this->metadataProviderMock->expects($this->once())->method('get')->willReturn(['head_default_title' => ['path' => 'design/head/default_title']]); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collection); $this->collection->expects($this->once())->method('addPathsFilter')->with(['head_default_title' => 'design/head/default_title']); $this->collection->expects($this->once())->method('addFieldToFilter')->with('scope', $scope); $this->collection->expects($this->once())->method('addScopeIdFilter')->with($scopeId); $this->collection->expects($this->once())->method('getData')->willReturn([['config_id' => 1, 'path' => 'design/head/default_title']]); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Config\\Value', ['data' => ['path' => 'design/head/default_title', 'scope' => $scope, 'scope_id' => $scopeId, 'field_config' => $data['config'], 'config_id' => 1]])->willReturn($this->backendModel); $this->backendModel->expects($this->once())->method('setValue')->willReturn('value'); $this->assertSame($this->backendModel, $this->model->create($data)); }
/** * Clean compiled JS/CSS when updating configuration settings * * @return $this */ public function afterSave() { if ($this->isValueChanged()) { $this->_mergeService->cleanMergedJsCss(); } return parent::afterSave(); }
/** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Paypal\Model\CertFactory $certFactory * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Paypal\Model\CertFactory $certFactory, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = []) { $this->_certFactory = $certFactory; $this->_encryptor = $encryptor; $this->_tmpDirectory = $filesystem->getDirectoryRead(DirectoryList::SYS_TMP); parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); }
/** * @param int $callNumber * @param string $oldValue * @dataProvider afterSaveDataProvider */ public function testAfterSave($callNumber, $oldValue) { $this->cacheTypeListMock->expects($this->exactly($callNumber))->method('invalidate'); $this->configMock->expects($this->any())->method('getValue')->willReturn($oldValue); $this->model->setValue('some_value'); $this->assertInstanceOf(get_class($this->model), $this->model->afterSave()); }
/** * @return $this */ public function afterSave() { if ($this->isValueChanged()) { $this->updateSuffixForUrlRewrites(); } return parent::afterSave(); }
/** * Validate minimum product qty value * * @return $this */ public function beforeSave() { parent::beforeSave(); $minQty = (int) $this->getValue() >= 0 ? (int) $this->getValue() : (int) $this->getOldValue(); $this->setValue((string) $minQty); return $this; }
/** * @return $this */ public function afterSave() { /** @var \Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate $tableRate */ $tableRate = $this->_tablerateFactory->create(); $tableRate->uploadAndImport($this); return parent::afterSave(); }
/** * Check and process robots file * * @return $this */ public function afterSave() { if ($this->getValue()) { $this->_directory->writeFile($this->_file, $this->getValue()); } return parent::afterSave(); }
/** * Invalidate cache type, when value was changed * * @return $this */ public function afterSave() { if ($this->isValueChanged()) { $this->cacheTypeList->invalidate(\Magento\Framework\View\Element\AbstractBlock::CACHE_GROUP); } return parent::afterSave(); }
/** * Cron settings after save * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function afterSave() { $enabled = $this->getData('groups/log/fields/enabled/value'); $time = $this->getData('groups/log/fields/time/value'); $frequency = $this->getData('groups/log/fields/frequency/value'); $frequencyWeekly = \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY; $frequencyMonthly = \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY; if ($enabled) { $cronExprArray = [intval($time[1]), intval($time[0]), $frequency == $frequencyMonthly ? '1' : '*', '*', $frequency == $frequencyWeekly ? '1' : '*']; $cronExprString = join(' ', $cronExprArray); } else { $cronExprString = ''; } try { /** @var $configValue \Magento\Framework\App\Config\ValueInterface */ $configValue = $this->_configValueFactory->create(); $configValue->load(self::CRON_STRING_PATH, 'path'); $configValue->setValue($cronExprString)->setPath(self::CRON_STRING_PATH)->save(); /** @var $configValue \Magento\Framework\App\Config\ValueInterface */ $configValue = $this->_configValueFactory->create(); $configValue->load(self::CRON_MODEL_PATH, 'path'); $configValue->setValue($this->_runModelPath)->setPath(self::CRON_MODEL_PATH)->save(); } catch (\Exception $e) { throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t save the Cron expression.')); } return parent::afterSave(); }
/** * @return $this */ public function beforeSave() { if (is_array($this->getValue())) { $this->setValue(serialize($this->getValue())); } return parent::beforeSave(); }
/** * Validate minimum product qty value * * @return $this */ protected function _beforeSave() { parent::_beforeSave(); $minQty = (int) $this->getValue() >= 0 ? (int) $this->getValue() : (int) $this->getOldValue(); $this->setValue((string) $minQty); return $this; }
/** * @return \Magento\Framework\Model\AbstractModel|void */ public function afterSave() { /** @var \WebShopApps\MatrixRate\Model\ResourceModel\Carrier\Matrixrate $matrixRate */ $matrixRate = $this->_matrixrateFactory->create(); $matrixRate->uploadAndImport($this); return parent::afterSave(); }
/** * Save EAV default value after save * * @return $this */ public function afterSave() { $result = parent::afterSave(); $attributeObject = $this->eavConfig->getAttribute('customer', 'disable_auto_group_change'); $attributeObject->setData('default_value', $this->getValue()); $attributeObject->save(); return $result; }
/** * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSave() { if (!empty($this->getValue()) && !$this->_isRegexp($this->getValue())) { $this->messageManager->addNotice(__('Invalid regular expression: %value', ['value' => $this->getValue()])); $this->setValue(null); } return parent::beforeSave(); }
/** * SeoObserver constructor. * * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param \Mageplaza\Seo\Helper\Data $helper * @param array $data */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, SeoHelper $helper, array $data = []) { $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $this->_fileRobot = 'robots.txt'; $this->_fileHtaccess = '.htaccess'; $this->_helper = $helper; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); }
/** * Validate specified value against frontend area * * @return $this */ public function beforeSave() { if ('' != $this->getValue()) { $design = clone $this->_design; $design->setDesignTheme($this->getValue(), \Magento\Framework\App\Area::AREA_FRONTEND); } return parent::beforeSave(); }
/** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Core\Model\File\UploaderFactory $uploaderFactory * @param \Magento\Backend\Model\Config\Backend\File\RequestData\RequestDataInterface $requestData * @param \Magento\Framework\App\Filesystem $filesystem * @param \Magento\Framework\Model\Resource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\Db $resourceCollection * @param array $data */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Core\Model\File\UploaderFactory $uploaderFactory, \Magento\Backend\Model\Config\Backend\File\RequestData\RequestDataInterface $requestData, \Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = array()) { $this->_uploaderFactory = $uploaderFactory; $this->_requestData = $requestData; $this->_filesystem = $filesystem; $this->_mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::MEDIA_DIR); parent::__construct($context, $registry, $config, $resource, $resourceCollection, $data); }
/** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory * @param \Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface $requestData * @param Filesystem $filesystem * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory, \Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface $requestData, Filesystem $filesystem, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = []) { $this->_uploaderFactory = $uploaderFactory; $this->_requestData = $requestData; $this->_filesystem = $filesystem; $this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); }
/** * After save call * Invalidate catalog search index if engine was changed * * @return $this */ public function afterSave() { parent::afterSave(); if ($this->isValueChanged()) { $this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->invalidate(); } return $this; }
/** * Set status 'invalidate' for blocks and other output caches * * @return $this */ public function afterSave() { $types = array_keys($this->_config->getValue(self::XML_PATH_INVALID_CACHES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); if ($this->isValueChanged()) { $this->cacheTypeList->invalidate($types); } return parent::afterSave(); }
/** * Prepare and store cron settings after save * * @return $this */ public function afterSave() { if ($this->isValueChanged()) { $this->_resetNotificationFlag(\Magento\Tax\Model\Config::XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT); $this->_resetNotificationFlag(\Magento\Tax\Model\Config::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY); } return parent::afterSave(); }
/** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $configsFactory * @param \Magento\Store\Model\WebsiteFactory $websiteFactory * @param \Magento\Store\Model\StoreFactory $storeFactory * @param \Magento\Framework\Locale\CurrencyInterface $localeCurrency * @param \Magento\Framework\Model\ModelResource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $configsFactory, \Magento\Store\Model\WebsiteFactory $websiteFactory, \Magento\Store\Model\StoreFactory $storeFactory, \Magento\Framework\Locale\CurrencyInterface $localeCurrency, \Magento\Framework\Model\ModelResource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = []) { $this->_configsFactory = $configsFactory; $this->_websiteFactory = $websiteFactory; $this->_storeFactory = $storeFactory; $this->_localeCurrency = $localeCurrency; parent::__construct($context, $registry, $config, $resource, $resourceCollection, $data); }
/** * Delete custom admin url from configuration if "Use Custom Admin Url" option disabled * * @return $this */ public function afterSave() { $value = $this->getValue(); if (!$value) { $this->_configWriter->delete(Custom::XML_PATH_SECURE_BASE_URL, Custom::CONFIG_SCOPE, Custom::CONFIG_SCOPE_ID); $this->_configWriter->delete(Custom::XML_PATH_UNSECURE_BASE_URL, Custom::CONFIG_SCOPE, Custom::CONFIG_SCOPE_ID); } return parent::afterSave(); }
/** * Validate a domain name value * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSave() { $value = $this->getValue(); if (!empty($value) && !$this->configValidator->isValid($value)) { $msg = __('Invalid cookie lifetime: ' . join('; ', $this->configValidator->getMessages())); throw new \Magento\Framework\Exception\LocalizedException($msg); } return parent::beforeSave(); }
/** * Validate expiration period value before saving * * @return $this */ public function beforeSave() { parent::beforeSave(); $expirationPeriod = (int) $this->getValue(); if ($expirationPeriod < 1) { $expirationPeriod = (int) $this->getOldValue(); } $this->setValue((string) $expirationPeriod); return $this; }