11<?php
2+
23/**
34 * Copyright © Magento, Inc. All rights reserved.
45 * See COPYING.txt for license details.
56 */
7+
68namespace Magento \Sitemap \Model \ResourceModel \Cms ;
79
810use Magento \Cms \Api \Data \PageInterface ;
911use Magento \Cms \Api \GetUtilityPageIdentifiersInterface ;
1012use Magento \Cms \Model \Page as CmsPage ;
1113use Magento \Framework \App \ObjectManager ;
14+ use Magento \Framework \DataObject ;
1215use Magento \Framework \DB \Select ;
1316use Magento \Framework \EntityManager \EntityManager ;
1417use Magento \Framework \EntityManager \MetadataPool ;
2124 *
2225 * @api
2326 * @since 100.0.2
27+ * @SuppressWarnings(PHPMD.CamelCaseMethodName)
28+ * @SuppressWarnings(PHPMD.LongVariable)
2429 */
2530class Page extends AbstractDb
2631{
@@ -85,6 +90,7 @@ public function getConnection()
8590 * Retrieve cms page collection array
8691 *
8792 * @param int $storeId
93+ *
8894 * @return array
8995 */
9096 public function getCollection ($ storeId )
@@ -103,7 +109,17 @@ public function getCollection($storeId)
103109 'main_table.is_active = 1 '
104110 )->where (
105111 '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+ )
107123 )->where (
108124 'store_table.store_id IN(?) ' ,
109125 [0 , $ storeId ]
@@ -123,11 +139,12 @@ public function getCollection($storeId)
123139 * Prepare page object
124140 *
125141 * @param array $data
126- * @return \Magento\Framework\DataObject
142+ *
143+ * @return DataObject
127144 */
128145 protected function _prepareObject (array $ data )
129146 {
130- $ object = new \ Magento \ Framework \ DataObject ();
147+ $ object = new DataObject ();
131148 $ object ->setId ($ data [$ this ->getIdFieldName ()]);
132149 $ object ->setUrl ($ data ['url ' ]);
133150 $ object ->setUpdatedAt ($ data ['updated_at ' ]);
@@ -140,7 +157,8 @@ protected function _prepareObject(array $data)
140157 *
141158 * @param CmsPage|AbstractModel $object
142159 * @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+ *
144162 * @return $this
145163 * @since 100.1.0
146164 */
@@ -168,6 +186,7 @@ public function load(AbstractModel $object, $value, $field = null)
168186 if ($ isId ) {
169187 $ this ->entityManager ->load ($ object , $ value );
170188 }
189+
171190 return $ this ;
172191 }
173192
@@ -190,6 +209,7 @@ public function save(AbstractModel $object)
190209 $ object ->setHasDataChanges (false );
191210 return $ this ;
192211 }
212+
193213 $ object ->validateBeforeSave ();
194214 $ object ->beforeSave ();
195215 if ($ object ->isSaveAllowed ()) {
@@ -201,13 +221,15 @@ public function save(AbstractModel $object)
201221 $ this ->unserializeFields ($ object );
202222 $ this ->processAfterSaves ($ object );
203223 }
224+
204225 $ this ->addCommitCallback ([$ object , 'afterCommitCallback ' ])->commit ();
205226 $ object ->setHasDataChanges (false );
206227 } catch (\Exception $ e ) {
207228 $ this ->rollBack ();
208229 $ object ->setHasDataChanges (true );
209230 throw $ e ;
210231 }
232+
211233 return $ this ;
212234 }
213235
0 commit comments