1
1
<?php
2
+
2
3
/**
3
4
* Copyright © Magento, Inc. All rights reserved.
4
5
* See COPYING.txt for license details.
5
6
*/
7
+
6
8
namespace Magento \Sitemap \Model \ResourceModel \Cms ;
7
9
8
10
use Magento \Cms \Api \Data \PageInterface ;
9
11
use Magento \Cms \Api \GetUtilityPageIdentifiersInterface ;
10
12
use Magento \Cms \Model \Page as CmsPage ;
11
13
use Magento \Framework \App \ObjectManager ;
14
+ use Magento \Framework \DataObject ;
12
15
use Magento \Framework \DB \Select ;
13
16
use Magento \Framework \EntityManager \EntityManager ;
14
17
use Magento \Framework \EntityManager \MetadataPool ;
21
24
*
22
25
* @api
23
26
* @since 100.0.2
27
+ * @SuppressWarnings(PHPMD.CamelCaseMethodName)
28
+ * @SuppressWarnings(PHPMD.LongVariable)
24
29
*/
25
30
class Page extends AbstractDb
26
31
{
@@ -85,6 +90,7 @@ public function getConnection()
85
90
* Retrieve cms page collection array
86
91
*
87
92
* @param int $storeId
93
+ *
88
94
* @return array
89
95
*/
90
96
public function getCollection ($ storeId )
@@ -103,7 +109,17 @@ public function getCollection($storeId)
103
109
'main_table.is_active = 1 '
104
110
)->where (
105
111
'main_table.identifier NOT IN (?) ' ,
106
- $ this ->getUtilityPageIdentifiers ->execute ()
112
+ array_map (
113
+ // When two CMS pages have the same URL key (in different
114
+ // stores), the value stored in configuration is 'url-key|ID'.
115
+ // This function strips the trailing '|ID' so that this where()
116
+ // matches the url-key configured.
117
+ // See https://github.com/magento/magento2/issues/35001
118
+ static function ($ urlKey ) {
119
+ return explode ('| ' , $ urlKey , 2 )[0 ];
120
+ },
121
+ $ this ->getUtilityPageIdentifiers ->execute ()
122
+ )
107
123
)->where (
108
124
'store_table.store_id IN(?) ' ,
109
125
[0 , $ storeId ]
@@ -123,11 +139,12 @@ public function getCollection($storeId)
123
139
* Prepare page object
124
140
*
125
141
* @param array $data
126
- * @return \Magento\Framework\DataObject
142
+ *
143
+ * @return DataObject
127
144
*/
128
145
protected function _prepareObject (array $ data )
129
146
{
130
- $ object = new \ Magento \ Framework \ DataObject ();
147
+ $ object = new DataObject ();
131
148
$ object ->setId ($ data [$ this ->getIdFieldName ()]);
132
149
$ object ->setUrl ($ data ['url ' ]);
133
150
$ object ->setUpdatedAt ($ data ['updated_at ' ]);
@@ -140,7 +157,8 @@ protected function _prepareObject(array $data)
140
157
*
141
158
* @param CmsPage|AbstractModel $object
142
159
* @param mixed $value
143
- * @param string $field field to load by (defaults to model id)
160
+ * @param string $field Field to load by (defaults to model id).
161
+ *
144
162
* @return $this
145
163
* @since 100.1.0
146
164
*/
@@ -168,6 +186,7 @@ public function load(AbstractModel $object, $value, $field = null)
168
186
if ($ isId ) {
169
187
$ this ->entityManager ->load ($ object , $ value );
170
188
}
189
+
171
190
return $ this ;
172
191
}
173
192
@@ -190,6 +209,7 @@ public function save(AbstractModel $object)
190
209
$ object ->setHasDataChanges (false );
191
210
return $ this ;
192
211
}
212
+
193
213
$ object ->validateBeforeSave ();
194
214
$ object ->beforeSave ();
195
215
if ($ object ->isSaveAllowed ()) {
@@ -201,13 +221,15 @@ public function save(AbstractModel $object)
201
221
$ this ->unserializeFields ($ object );
202
222
$ this ->processAfterSaves ($ object );
203
223
}
224
+
204
225
$ this ->addCommitCallback ([$ object , 'afterCommitCallback ' ])->commit ();
205
226
$ object ->setHasDataChanges (false );
206
227
} catch (\Exception $ e ) {
207
228
$ this ->rollBack ();
208
229
$ object ->setHasDataChanges (true );
209
230
throw $ e ;
210
231
}
232
+
211
233
return $ this ;
212
234
}
213
235
0 commit comments