Skip to content

Commit 9cdc5a1

Browse files
author
Oleksandr Karpenko
committed
MAGETWO-46483: Create sequence table for CMS pages
1 parent 9f67d9e commit 9cdc5a1

File tree

1 file changed

+31
-25
lines changed
  • app/code/Magento/Cms/Model/ResourceModel

1 file changed

+31
-25
lines changed

app/code/Magento/Cms/Model/ResourceModel/Page.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,29 @@
88

99
namespace Magento\Cms\Model\ResourceModel;
1010

11+
use Magento\Cms\Model\Page as CmsPage;
12+
use Magento\Framework\DB\Select;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Model\AbstractModel;
1115
use Magento\Framework\Model\Entity\MetadataPool;
1216
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
1317
use Magento\Framework\Model\ResourceModel\Db\Context;
1418
use Magento\Framework\Stdlib\DateTime;
19+
use Magento\Store\Model\Store;
1520
use Magento\Store\Model\StoreManagerInterface;
1621
use Magento\Framework\Model\EntityManager;
1722
use Magento\Cms\Api\Data\PageInterface;
1823

1924
/**
2025
* Cms page mysql resource
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2127
*/
2228
class Page extends AbstractDb
2329
{
2430
/**
2531
* Store model
2632
*
27-
* @var null|\Magento\Store\Model\Store
33+
* @var null|Store
2834
*/
2935
protected $_store = null;
3036

@@ -86,11 +92,11 @@ protected function _construct()
8692
/**
8793
* Process page data before saving
8894
*
89-
* @param \Magento\Framework\Model\AbstractModel $object
95+
* @param AbstractModel $object
9096
* @return $this
91-
* @throws \Magento\Framework\Exception\LocalizedException
97+
* @throws LocalizedException
9298
*/
93-
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
99+
protected function _beforeSave(AbstractModel $object)
94100
{
95101
/*
96102
* For two attributes which represent timestamp data in DB
@@ -104,13 +110,13 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
104110
}
105111

106112
if (!$this->isValidPageIdentifier($object)) {
107-
throw new \Magento\Framework\Exception\LocalizedException(
113+
throw new LocalizedException(
108114
__('The page URL key contains capital letters or disallowed symbols.')
109115
);
110116
}
111117

112118
if ($this->isNumericPageIdentifier($object)) {
113-
throw new \Magento\Framework\Exception\LocalizedException(
119+
throw new LocalizedException(
114120
__('The page URL key cannot be made of only numbers.')
115121
);
116122
}
@@ -120,12 +126,12 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
120126
/**
121127
* Load an object
122128
*
123-
* @param \Magento\Cms\Model\Page|\Magento\Framework\Model\AbstractModel $object
129+
* @param CmsPage|AbstractModel $object
124130
* @param mixed $value
125131
* @param string $field field to load by (defaults to model id)
126132
* @return $this
127133
*/
128-
public function load(\Magento\Framework\Model\AbstractModel $object, $value, $field = null)
134+
public function load(AbstractModel $object, $value, $field = null)
129135
{
130136
$entityMetadata = $this->metadataPool->getMetadata(PageInterface::class);
131137

@@ -138,7 +144,7 @@ public function load(\Magento\Framework\Model\AbstractModel $object, $value, $fi
138144
$isId = true;
139145
if ($field != $entityMetadata->getIdentifierField() || $object->getStoreId()) {
140146
$select = $this->_getLoadSelect($field, $value, $object);
141-
$select->reset(\Magento\Framework\DB\Select::COLUMNS)
147+
$select->reset(Select::COLUMNS)
142148
->columns($this->getMainTable() . '.' . $entityMetadata->getIdentifierField())
143149
->limit(1);
144150
$result = $this->getConnection()->fetchCol($select);
@@ -158,8 +164,8 @@ public function load(\Magento\Framework\Model\AbstractModel $object, $value, $fi
158164
*
159165
* @param string $field
160166
* @param mixed $value
161-
* @param \Magento\Cms\Model\Page|\Magento\Framework\Model\AbstractModel $object
162-
* @return \Magento\Framework\DB\Select
167+
* @param CmsPage|AbstractModel $object
168+
* @return Select
163169
*/
164170
protected function _getLoadSelect($field, $value, $object)
165171
{
@@ -170,7 +176,7 @@ protected function _getLoadSelect($field, $value, $object)
170176

171177
if ($object->getStoreId()) {
172178
$storeIds = [
173-
\Magento\Store\Model\Store::DEFAULT_STORE_ID,
179+
Store::DEFAULT_STORE_ID,
174180
(int)$object->getStoreId(),
175181
];
176182
$select->join(
@@ -193,7 +199,7 @@ protected function _getLoadSelect($field, $value, $object)
193199
* @param string $identifier
194200
* @param int|array $store
195201
* @param int $isActive
196-
* @return \Magento\Framework\DB\Select
202+
* @return Select
197203
*/
198204
protected function _getLoadByIdentifierSelect($identifier, $store, $isActive = null)
199205
{
@@ -220,21 +226,21 @@ protected function _getLoadByIdentifierSelect($identifier, $store, $isActive = n
220226
/**
221227
* Check whether page identifier is numeric
222228
*
223-
* @param \Magento\Framework\Model\AbstractModel $object
229+
* @param AbstractModel $object
224230
* @return bool
225231
*/
226-
protected function isNumericPageIdentifier(\Magento\Framework\Model\AbstractModel $object)
232+
protected function isNumericPageIdentifier(AbstractModel $object)
227233
{
228234
return preg_match('/^[0-9]+$/', $object->getData('identifier'));
229235
}
230236

231237
/**
232238
* Check whether page identifier is valid
233239
*
234-
* @param \Magento\Framework\Model\AbstractModel $object
240+
* @param AbstractModel $object
235241
* @return bool
236242
*/
237-
protected function isValidPageIdentifier(\Magento\Framework\Model\AbstractModel $object)
243+
protected function isValidPageIdentifier(AbstractModel $object)
238244
{
239245
return preg_match('/^[a-z0-9][a-z0-9_\/-]+(\.[a-z0-9_-]+)?$/', $object->getData('identifier'));
240246
}
@@ -251,9 +257,9 @@ public function checkIdentifier($identifier, $storeId)
251257
{
252258
$entityMetadata = $this->metadataPool->getMetadata(PageInterface::class);
253259

254-
$stores = [\Magento\Store\Model\Store::DEFAULT_STORE_ID, $storeId];
260+
$stores = [Store::DEFAULT_STORE_ID, $storeId];
255261
$select = $this->_getLoadByIdentifierSelect($identifier, $stores, 1);
256-
$select->reset(\Magento\Framework\DB\Select::COLUMNS)
262+
$select->reset(Select::COLUMNS)
257263
->columns('cp.' . $entityMetadata->getIdentifierField())
258264
->order('cps.store_id DESC')
259265
->limit(1);
@@ -269,13 +275,13 @@ public function checkIdentifier($identifier, $storeId)
269275
*/
270276
public function getCmsPageTitleByIdentifier($identifier)
271277
{
272-
$stores = [\Magento\Store\Model\Store::DEFAULT_STORE_ID];
278+
$stores = [Store::DEFAULT_STORE_ID];
273279
if ($this->_store) {
274280
$stores[] = (int)$this->getStore()->getId();
275281
}
276282

277283
$select = $this->_getLoadByIdentifierSelect($identifier, $stores);
278-
$select->reset(\Magento\Framework\DB\Select::COLUMNS)
284+
$select->reset(Select::COLUMNS)
279285
->columns('cp.title')
280286
->order('cps.store_id DESC')
281287
->limit(1);
@@ -347,7 +353,7 @@ public function lookupStoreIds($pageId)
347353
/**
348354
* Set store model
349355
*
350-
* @param \Magento\Store\Model\Store $store
356+
* @param Store $store
351357
* @return $this
352358
*/
353359
public function setStore($store)
@@ -359,19 +365,19 @@ public function setStore($store)
359365
/**
360366
* Retrieve store model
361367
*
362-
* @return \Magento\Store\Model\Store
368+
* @return Store
363369
*/
364370
public function getStore()
365371
{
366372
return $this->_storeManager->getStore($this->_store);
367373
}
368374

369375
/**
370-
* @param \Magento\Framework\Model\AbstractModel $object
376+
* @param AbstractModel $object
371377
* @return $this
372378
* @throws \Exception
373379
*/
374-
public function save(\Magento\Framework\Model\AbstractModel $object)
380+
public function save(AbstractModel $object)
375381
{
376382
if ($object->isDeleted()) {
377383
return $this->delete($object);

0 commit comments

Comments
 (0)