Skip to content

Commit 0ce7599

Browse files
Merge remote-tracking branch '35156/sitemap/cms-page-exclude' into comm_voted_v3
2 parents e333ee9 + 9f84768 commit 0ce7599

File tree

2 files changed

+40
-7
lines changed
  • app/code/Magento/Sitemap

2 files changed

+40
-7
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
2+
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
56
*/
7+
68
namespace Magento\Sitemap\Model\ResourceModel\Cms;
79

810
use Magento\Cms\Api\Data\PageInterface;
911
use Magento\Cms\Api\GetUtilityPageIdentifiersInterface;
1012
use Magento\Cms\Model\Page as CmsPage;
1113
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\DataObject;
1215
use Magento\Framework\DB\Select;
1316
use Magento\Framework\EntityManager\EntityManager;
1417
use Magento\Framework\EntityManager\MetadataPool;
@@ -21,6 +24,8 @@
2124
*
2225
* @api
2326
* @since 100.0.2
27+
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
28+
* @SuppressWarnings(PHPMD.LongVariable)
2429
*/
2530
class 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

app/code/Magento/Sitemap/Test/Unit/Model/ResourceModel/Cms/PageTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
56
*/
7+
68
declare(strict_types=1);
79

810
namespace Magento\Sitemap\Test\Unit\Model\ResourceModel\Cms;
@@ -25,6 +27,8 @@
2527
/**
2628
* Provide tests for Cms Page resource model.
2729
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
31+
* @SuppressWarnings(PHPMD.LongVariable)
2832
*/
2933
class PageTest extends TestCase
3034
{
@@ -104,7 +108,11 @@ public function testGetCollection()
104108
$pageId = 'testPageId';
105109
$url = 'testUrl';
106110
$updatedAt = 'testUpdatedAt';
107-
$pageIdentifiers = ['testCmsHomePage', 'testCmsNoRoute', 'testCmsNoCookies'];
111+
$pageIdentifiers = [
112+
'testCmsHomePage|ID' => 'testCmsHomePage',
113+
'testCmsNoRoute' => 'testCmsNoRoute',
114+
'testCmsNoCookies' => 'testCmsNoCookies',
115+
];
108116
$storeId = 1;
109117
$linkField = 'testLinkField';
110118
$expectedPage = new DataObject();
@@ -147,7 +155,10 @@ public function testGetCollection()
147155
->method('where')
148156
->withConsecutive(
149157
[$this->identicalTo('main_table.is_active = 1')],
150-
[$this->identicalTo('main_table.identifier NOT IN (?)'), $this->identicalTo($pageIdentifiers)],
158+
[
159+
$this->identicalTo('main_table.identifier NOT IN (?)'),
160+
$this->identicalTo(array_values($pageIdentifiers))
161+
],
151162
[$this->identicalTo('store_table.store_id IN(?)'), $this->identicalTo([0, $storeId])]
152163
)->willReturnSelf();
153164

@@ -176,7 +187,7 @@ public function testGetCollection()
176187

177188
$this->getUtilityPageIdentifiers->expects($this->once())
178189
->method('execute')
179-
->willReturn($pageIdentifiers);
190+
->willReturn(array_keys($pageIdentifiers));
180191

181192
$this->resource->expects($this->exactly(2))
182193
->method('getTableName')

0 commit comments

Comments
 (0)