8
8
9
9
namespace Magento \Cms \Model \ResourceModel ;
10
10
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 ;
11
15
use Magento \Framework \Model \Entity \MetadataPool ;
12
16
use Magento \Framework \Model \ResourceModel \Db \AbstractDb ;
13
17
use Magento \Framework \Model \ResourceModel \Db \Context ;
14
18
use Magento \Framework \Stdlib \DateTime ;
19
+ use Magento \Store \Model \Store ;
15
20
use Magento \Store \Model \StoreManagerInterface ;
16
21
use Magento \Framework \Model \EntityManager ;
17
22
use Magento \Cms \Api \Data \PageInterface ;
18
23
19
24
/**
20
25
* Cms page mysql resource
26
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21
27
*/
22
28
class Page extends AbstractDb
23
29
{
24
30
/**
25
31
* Store model
26
32
*
27
- * @var null|\Magento\Store\Model\ Store
33
+ * @var null|Store
28
34
*/
29
35
protected $ _store = null ;
30
36
@@ -86,11 +92,11 @@ protected function _construct()
86
92
/**
87
93
* Process page data before saving
88
94
*
89
- * @param \Magento\Framework\Model\ AbstractModel $object
95
+ * @param AbstractModel $object
90
96
* @return $this
91
- * @throws \Magento\Framework\Exception\ LocalizedException
97
+ * @throws LocalizedException
92
98
*/
93
- protected function _beforeSave (\ Magento \ Framework \ Model \ AbstractModel $ object )
99
+ protected function _beforeSave (AbstractModel $ object )
94
100
{
95
101
/*
96
102
* For two attributes which represent timestamp data in DB
@@ -104,13 +110,13 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
104
110
}
105
111
106
112
if (!$ this ->isValidPageIdentifier ($ object )) {
107
- throw new \ Magento \ Framework \ Exception \ LocalizedException (
113
+ throw new LocalizedException (
108
114
__ ('The page URL key contains capital letters or disallowed symbols. ' )
109
115
);
110
116
}
111
117
112
118
if ($ this ->isNumericPageIdentifier ($ object )) {
113
- throw new \ Magento \ Framework \ Exception \ LocalizedException (
119
+ throw new LocalizedException (
114
120
__ ('The page URL key cannot be made of only numbers. ' )
115
121
);
116
122
}
@@ -120,12 +126,12 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
120
126
/**
121
127
* Load an object
122
128
*
123
- * @param \Magento\Cms\Model\Page|\Magento\Framework\Model\ AbstractModel $object
129
+ * @param CmsPage| AbstractModel $object
124
130
* @param mixed $value
125
131
* @param string $field field to load by (defaults to model id)
126
132
* @return $this
127
133
*/
128
- public function load (\ Magento \ Framework \ Model \ AbstractModel $ object , $ value , $ field = null )
134
+ public function load (AbstractModel $ object , $ value , $ field = null )
129
135
{
130
136
$ entityMetadata = $ this ->metadataPool ->getMetadata (PageInterface::class);
131
137
@@ -138,7 +144,7 @@ public function load(\Magento\Framework\Model\AbstractModel $object, $value, $fi
138
144
$ isId = true ;
139
145
if ($ field != $ entityMetadata ->getIdentifierField () || $ object ->getStoreId ()) {
140
146
$ select = $ this ->_getLoadSelect ($ field , $ value , $ object );
141
- $ select ->reset (\ Magento \ Framework \ DB \ Select::COLUMNS )
147
+ $ select ->reset (Select::COLUMNS )
142
148
->columns ($ this ->getMainTable () . '. ' . $ entityMetadata ->getIdentifierField ())
143
149
->limit (1 );
144
150
$ result = $ this ->getConnection ()->fetchCol ($ select );
@@ -158,8 +164,8 @@ public function load(\Magento\Framework\Model\AbstractModel $object, $value, $fi
158
164
*
159
165
* @param string $field
160
166
* @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
163
169
*/
164
170
protected function _getLoadSelect ($ field , $ value , $ object )
165
171
{
@@ -170,7 +176,7 @@ protected function _getLoadSelect($field, $value, $object)
170
176
171
177
if ($ object ->getStoreId ()) {
172
178
$ storeIds = [
173
- \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID ,
179
+ Store::DEFAULT_STORE_ID ,
174
180
(int )$ object ->getStoreId (),
175
181
];
176
182
$ select ->join (
@@ -193,7 +199,7 @@ protected function _getLoadSelect($field, $value, $object)
193
199
* @param string $identifier
194
200
* @param int|array $store
195
201
* @param int $isActive
196
- * @return \Magento\Framework\DB\ Select
202
+ * @return Select
197
203
*/
198
204
protected function _getLoadByIdentifierSelect ($ identifier , $ store , $ isActive = null )
199
205
{
@@ -220,21 +226,21 @@ protected function _getLoadByIdentifierSelect($identifier, $store, $isActive = n
220
226
/**
221
227
* Check whether page identifier is numeric
222
228
*
223
- * @param \Magento\Framework\Model\ AbstractModel $object
229
+ * @param AbstractModel $object
224
230
* @return bool
225
231
*/
226
- protected function isNumericPageIdentifier (\ Magento \ Framework \ Model \ AbstractModel $ object )
232
+ protected function isNumericPageIdentifier (AbstractModel $ object )
227
233
{
228
234
return preg_match ('/^[0-9]+$/ ' , $ object ->getData ('identifier ' ));
229
235
}
230
236
231
237
/**
232
238
* Check whether page identifier is valid
233
239
*
234
- * @param \Magento\Framework\Model\ AbstractModel $object
240
+ * @param AbstractModel $object
235
241
* @return bool
236
242
*/
237
- protected function isValidPageIdentifier (\ Magento \ Framework \ Model \ AbstractModel $ object )
243
+ protected function isValidPageIdentifier (AbstractModel $ object )
238
244
{
239
245
return preg_match ('/^[a-z0-9][a-z0-9_\/-]+(\.[a-z0-9_-]+)?$/ ' , $ object ->getData ('identifier ' ));
240
246
}
@@ -251,9 +257,9 @@ public function checkIdentifier($identifier, $storeId)
251
257
{
252
258
$ entityMetadata = $ this ->metadataPool ->getMetadata (PageInterface::class);
253
259
254
- $ stores = [\ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID , $ storeId ];
260
+ $ stores = [Store::DEFAULT_STORE_ID , $ storeId ];
255
261
$ select = $ this ->_getLoadByIdentifierSelect ($ identifier , $ stores , 1 );
256
- $ select ->reset (\ Magento \ Framework \ DB \ Select::COLUMNS )
262
+ $ select ->reset (Select::COLUMNS )
257
263
->columns ('cp. ' . $ entityMetadata ->getIdentifierField ())
258
264
->order ('cps.store_id DESC ' )
259
265
->limit (1 );
@@ -269,13 +275,13 @@ public function checkIdentifier($identifier, $storeId)
269
275
*/
270
276
public function getCmsPageTitleByIdentifier ($ identifier )
271
277
{
272
- $ stores = [\ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID ];
278
+ $ stores = [Store::DEFAULT_STORE_ID ];
273
279
if ($ this ->_store ) {
274
280
$ stores [] = (int )$ this ->getStore ()->getId ();
275
281
}
276
282
277
283
$ select = $ this ->_getLoadByIdentifierSelect ($ identifier , $ stores );
278
- $ select ->reset (\ Magento \ Framework \ DB \ Select::COLUMNS )
284
+ $ select ->reset (Select::COLUMNS )
279
285
->columns ('cp.title ' )
280
286
->order ('cps.store_id DESC ' )
281
287
->limit (1 );
@@ -347,7 +353,7 @@ public function lookupStoreIds($pageId)
347
353
/**
348
354
* Set store model
349
355
*
350
- * @param \Magento\Store\Model\ Store $store
356
+ * @param Store $store
351
357
* @return $this
352
358
*/
353
359
public function setStore ($ store )
@@ -359,19 +365,19 @@ public function setStore($store)
359
365
/**
360
366
* Retrieve store model
361
367
*
362
- * @return \Magento\Store\Model\ Store
368
+ * @return Store
363
369
*/
364
370
public function getStore ()
365
371
{
366
372
return $ this ->_storeManager ->getStore ($ this ->_store );
367
373
}
368
374
369
375
/**
370
- * @param \Magento\Framework\Model\ AbstractModel $object
376
+ * @param AbstractModel $object
371
377
* @return $this
372
378
* @throws \Exception
373
379
*/
374
- public function save (\ Magento \ Framework \ Model \ AbstractModel $ object )
380
+ public function save (AbstractModel $ object )
375
381
{
376
382
if ($ object ->isDeleted ()) {
377
383
return $ this ->delete ($ object );
0 commit comments