![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/shiplab/Model/ResourceModel/Config/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\Shiplab\Model\ResourceModel\Config; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Model\AbstractModel; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; /** * Core config data resource model * * @author Magento Core Team <[email protected]> * @api * @since 100.0.2 */ class Data extends AbstractDb { /** * Clear Scope data * * @param string $scopeCode * @param int|array $scopeIds * @return void * @throws LocalizedException */ public function clearScopeData($scopeCode, $scopeIds) { if (!is_array($scopeIds)) { $scopeIds = [$scopeIds]; } $this->getConnection()->delete( $this->getMainTable(), ['scope = ?' => $scopeCode, 'scope_id IN (?)' => $scopeIds] ); } /** * Define main table * * @return void */ protected function _construct() { $this->_init('extmag_configuration', 'config_id'); } /** * Convert array to comma separated value * * @param AbstractModel $object * @return $this * @throws LocalizedException */ protected function _beforeSave(AbstractModel $object) { if (!$object->getId()) { $this->_checkUnique($object); } if (is_array($object->getValue())) { $object->setValue(join(',', $object->getValue())); } return parent::_beforeSave($object); } /** * Validate unique configuration data before save * Set id to object if exists configuration instead of throw exception * * @param AbstractModel $object * @return $this * @throws LocalizedException */ protected function _checkUnique(AbstractModel $object) { $select = $this->getConnection()->select()->from( $this->getMainTable(), [$this->getIdFieldName()] )->where( 'scope = :scope' )->where( 'scope_id = :scope_id' )->where( 'path = :path' ); $bind = [ 'scope' => $object->getScope(), 'scope_id' => $object->getScopeId(), 'path' => $object->getPath(), ]; $configId = $this->getConnection()->fetchOne($select, $bind); if ($configId) { $object->setId($configId); } return $this; } }