Skip to content

Commit f9329d8

Browse files
committed
MC-4244: Skip URL rewrites multiplication
1 parent 5b3d796 commit f9329d8

File tree

9 files changed

+78
-51
lines changed

9 files changed

+78
-51
lines changed

app/code/Magento/CatalogUrlRewrite/Model/Storage/DbStorage.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ protected function prepareSelect(array $data)
2828
}
2929

3030
$select = $this->connection->select();
31-
$select->from([
32-
'url_rewrite' => $this->resource->getTableName(self::TABLE_NAME)
33-
]);
31+
$select->from(
32+
[
33+
'url_rewrite' => $this->resource->getTableName(self::TABLE_NAME)
34+
]
35+
);
3436
$select->joinLeft(
3537
['relation' => $this->resource->getTableName(Product::TABLE_NAME)],
3638
'url_rewrite.url_rewrite_id = relation.url_rewrite_id',

app/code/Magento/CatalogUrlRewrite/Model/Storage/DynamicStorage.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ protected function prepareSelect(array $data)
6767
unset($data[UrlRewrite::METADATA]);
6868
}
6969
$select = $this->connection->select();
70-
$select->from([
71-
'url_rewrite' => $this->resource->getTableName(self::TABLE_NAME)
72-
]);
70+
$select->from(
71+
[
72+
'url_rewrite' => $this->resource->getTableName(self::TABLE_NAME)
73+
]
74+
);
7375
$select->joinLeft(
7476
['relation' => $this->resource->getTableName(Product::TABLE_NAME)],
7577
'url_rewrite.url_rewrite_id = relation.url_rewrite_id'

app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/CategoryProcessUrlRewriteMovingObserverTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,15 @@ public function testCategoryProcessUrlRewriteAfterMovingWithChangedParentId()
9898
->disableOriginalConstructor()
9999
->setMethods(['getCategory'])
100100
->getMock();
101-
$categoryMock = $this->createPartialMock(Category::class, [
102-
'dataHasChangedFor',
103-
'getEntityId',
104-
'getStoreId',
105-
'setData'
106-
]);
101+
$categoryMock = $this->createPartialMock(
102+
Category::class,
103+
[
104+
'dataHasChangedFor',
105+
'getEntityId',
106+
'getStoreId',
107+
'setData'
108+
]
109+
);
107110

108111
$categoryMock->expects($this->once())->method('dataHasChangedFor')->with('parent_id')
109112
->willReturn(true);

app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/CategoryProcessUrlRewriteSavingObserverTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,16 @@ protected function setUp()
7676
\Magento\Framework\Event\Observer::class,
7777
['getEvent', 'getData']
7878
);
79-
$this->category = $this->createPartialMock(Category::class, [
80-
'hasData',
81-
'getParentId',
82-
'getStoreId',
83-
'dataHasChangedFor',
84-
'getChangedProductIds',
85-
]);
79+
$this->category = $this->createPartialMock(
80+
Category::class,
81+
[
82+
'hasData',
83+
'getParentId',
84+
'getStoreId',
85+
'dataHasChangedFor',
86+
'getChangedProductIds',
87+
]
88+
);
8689
$this->observer->expects($this->any())
8790
->method('getEvent')
8891
->willReturnSelf();

app/code/Magento/UrlRewrite/Controller/Router.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ protected function redirect($request, $url, $code)
146146
*/
147147
protected function getRewrite($requestPath, $storeId)
148148
{
149-
return $this->urlFinder->findOneByData([
150-
UrlRewrite::REQUEST_PATH => ltrim($requestPath, '/'),
151-
UrlRewrite::STORE_ID => $storeId,
152-
]);
149+
return $this->urlFinder->findOneByData(
150+
[
151+
UrlRewrite::REQUEST_PATH => ltrim($requestPath, '/'),
152+
UrlRewrite::STORE_ID => $storeId,
153+
]
154+
);
153155
}
154156
}

app/code/Magento/UrlRewrite/Model/CompositeUrlFinder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ public function findOneByData(array $data)
105105
*/
106106
private function getChildren(): array
107107
{
108-
uasort($this->children, function ($first, $second) {
109-
return (int)$first['sortOrder'] <=> (int)$second['sortOrder'];
110-
});
108+
uasort(
109+
$this->children,
110+
function ($first, $second) {
111+
return (int)$first['sortOrder'] <=> (int)$second['sortOrder'];
112+
}
113+
);
111114
return $this->children;
112115
}
113116
}

app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,17 @@ public function testRewriteAfterStoreSwitcher()
140140
$this->urlFinder
141141
->expects($this->any())
142142
->method('findOneByData')
143-
->willReturnMap([
143+
->willReturnMap(
144144
[
145145
[
146-
UrlRewrite::REQUEST_PATH => $initialRequestPath,
147-
UrlRewrite::STORE_ID => $currentStoreId,
148-
],
149-
$urlRewrite,
146+
[
147+
UrlRewrite::REQUEST_PATH => $initialRequestPath,
148+
UrlRewrite::STORE_ID => $currentStoreId,
149+
],
150+
$urlRewrite,
151+
]
150152
]
151-
]);
153+
);
152154
$this->actionFactory
153155
->expects($this->once())
154156
->method('create')
@@ -204,21 +206,23 @@ public function testNoRewriteAfterStoreSwitcherWhenOldRewriteEqualsToNewOne()
204206
$urlRewrite->expects($this->any())->method('getRequestPath')->will($this->returnValue('old-request-path'));
205207

206208
$this->urlFinder->expects($this->any())->method('findOneByData')->will(
207-
$this->returnValueMap([
208-
[
209-
[UrlRewrite::REQUEST_PATH => 'request-path', UrlRewrite::STORE_ID => 'old-store-id'],
210-
$oldUrlRewrite,
211-
],
209+
$this->returnValueMap(
212210
[
213211
[
214-
UrlRewrite::ENTITY_TYPE => 'entity-type',
215-
UrlRewrite::ENTITY_ID => 'entity-id',
216-
UrlRewrite::STORE_ID => 'current-store-id',
217-
UrlRewrite::IS_AUTOGENERATED => 1,
212+
[UrlRewrite::REQUEST_PATH => 'request-path', UrlRewrite::STORE_ID => 'old-store-id'],
213+
$oldUrlRewrite,
218214
],
219-
$urlRewrite
220-
],
221-
])
215+
[
216+
[
217+
UrlRewrite::ENTITY_TYPE => 'entity-type',
218+
UrlRewrite::ENTITY_ID => 'entity-id',
219+
UrlRewrite::STORE_ID => 'current-store-id',
220+
UrlRewrite::IS_AUTOGENERATED => 1,
221+
],
222+
$urlRewrite
223+
],
224+
]
225+
)
222226
);
223227

224228
$this->assertNull($this->router->match($this->request));

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteGeneratorTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ public function testGenerateWithSpecificCategoryUrlKey()
4646
$generator = $this->objectManager->get(ProductUrlRewriteGenerator::class);
4747
$urls = $generator->generate($product);
4848

49-
$actualUrls = array_map(function ($url) {
50-
/** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $url */
51-
return $url->getRequestPath();
52-
}, $urls);
49+
$actualUrls = array_map(
50+
function ($url) {
51+
/** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $url */
52+
return $url->getRequestPath();
53+
},
54+
$urls
55+
);
5356

5457
self::assertTrue(in_array('p002.html', $actualUrls));
5558
self::assertTrue(in_array('cat-1/p002.html', $actualUrls));

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/UrlRewriteHandlerTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ public function testGenerateProductUrlRewrites()
6161
->setAnchorsAbove(false);
6262

6363
$generatedUrls = $this->handler->generateProductUrlRewrites($category);
64-
$actual = array_values(array_map(function (UrlRewrite $urlRewrite) {
65-
return $urlRewrite->getRequestPath();
66-
}, $generatedUrls));
64+
$actual = array_values(
65+
array_map(
66+
function (UrlRewrite $urlRewrite) {
67+
return $urlRewrite->getRequestPath();
68+
},
69+
$generatedUrls
70+
)
71+
);
6772

6873
$expected = [
6974
'store-1-key.html', // the Default store

0 commit comments

Comments
 (0)