Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
7 
16 {
22  protected function _construct()
23  {
24  $this->_init('core_config_data', 'config_id');
25  }
26 
33  protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
34  {
35  if (!$object->getId()) {
36  $this->_checkUnique($object);
37  }
38 
39  if (is_array($object->getValue())) {
40  $object->setValue(join(',', $object->getValue()));
41  }
42  return parent::_beforeSave($object);
43  }
44 
52  protected function _checkUnique(\Magento\Framework\Model\AbstractModel $object)
53  {
54  $select = $this->getConnection()->select()->from(
55  $this->getMainTable(),
56  [$this->getIdFieldName()]
57  )->where(
58  'scope = :scope'
59  )->where(
60  'scope_id = :scope_id'
61  )->where(
62  'path = :path'
63  );
64  $bind = [
65  'scope' => $object->getScope(),
66  'scope_id' => $object->getScopeId(),
67  'path' => $object->getPath(),
68  ];
69 
70  $configId = $this->getConnection()->fetchOne($select, $bind);
71  if ($configId) {
72  $object->setId($configId);
73  }
74 
75  return $this;
76  }
77 
85  public function clearScopeData($scopeCode, $scopeIds)
86  {
87  if (!is_array($scopeIds)) {
88  $scopeIds = [$scopeIds];
89  }
90  $this->getConnection()->delete(
91  $this->getMainTable(),
92  ['scope = ?' => $scopeCode, 'scope_id IN (?)' => $scopeIds]
93  );
94  }
95 }
_beforeSave(\Magento\Framework\Model\AbstractModel $object)
Definition: Data.php:33
clearScopeData($scopeCode, $scopeIds)
Definition: Data.php:85
_checkUnique(\Magento\Framework\Model\AbstractModel $object)
Definition: Data.php:52