Skip to content

Commit 8bc3974

Browse files
committed
Updated "no-regen-url-key" code. Updated README and CHANGELOG.
1 parent 93d95ec commit 8bc3974

8 files changed

+24
-22
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.4.3] - 2019-05-12
8+
### Added
9+
- new option "no-regen-url-key"
10+
11+
### Changed
12+
- fixed a "typo" issue
13+
714
## [1.4.2] - 2019-04-04
815
### Added
916
- new option "--check-use-category-in-product-url"

Console/Command/RegenerateUrlRewrites.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected function configure()
112112
self::INPUT_KEY_NO_REGEN_URL_KEY,
113113
null,
114114
InputOption::VALUE_NONE,
115-
'Prevent URL_key regeneration'
115+
'Prevent url_key regeneration'
116116
),
117117
]);
118118
}
@@ -220,6 +220,10 @@ public function getCommandOptions()
220220
$this->_commandOptions['saveOldUrls'] = true;
221221
}
222222

223+
if (isset($options[self::INPUT_KEY_NO_REGEN_URL_KEY]) && $options[self::INPUT_KEY_NO_REGEN_URL_KEY] === true) {
224+
$this->_commandOptions['noRegenUrlKey'] = true;
225+
}
226+
223227
if (isset($options[self::INPUT_KEY_NO_REINDEX]) && $options[self::INPUT_KEY_NO_REINDEX] === true) {
224228
$this->_commandOptions['runReindex'] = false;
225229
}

Console/Command/RegenerateUrlRewritesAbstract.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function __construct(
259259
$this->_commandOptions['categoryId'] = null;
260260
$this->_commandOptions['productId'] = null;
261261
$this->_commandOptions['checkUseCategoryInProductUrl'] = false;
262-
$this->_commandOptions[SELF::INPUT_KEY_NO_REGEN_URL_KEY] = false;
262+
$this->_commandOptions['noRegenUrlKey'] = false;
263263
}
264264

265265
/**

Console/Command/RegenerateUrlRewritesCategoryAbstract.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ protected function _categoryProcess($category, $storeId = 0)
7373
}
7474
$category->setStoreId($storeId);
7575

76-
if(!$this->_commandOptions[SELF::INPUT_KEY_NO_REGEN_URL_KEY]) {
77-
$category->setData('url_key', null);
78-
79-
// URL Key needs to be regenerated before url_path, otherwise it may discord
76+
if (!$this->_commandOptions['noRegenUrlKey']) {
8077
$category->setUrlKey($this->_categoryUrlPathGenerator->getUrlKey($category));
8178
$category->getResource()->saveAttribute($category, 'url_key');
8279
}

Console/Command/RegenerateUrlRewritesProductAbstract.php

+4-13
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,18 @@ protected function _productProcess($product, $storeId)
7777
$product->setData('url_path', null)
7878
->setStoreId($storeId);
7979

80-
if(!$this->_commandOptions[SELF::INPUT_KEY_NO_REGEN_URL_KEY]) {
81-
$product->setData('url_key', null);
82-
80+
if (!$this->_commandOptions['noRegenUrlKey']) {
8381
$generatedKey = $this->_productUrlPathGenerator->getUrlKey($product);
8482

83+
$product->setData('url_key', $generatedKey);
84+
8585
$this->_getProductAction()->updateAttributes(
8686
[$product->getId()],
87-
['url_key' => $generatedKey],
87+
['url_path' => null, 'url_key' => $generatedKey],
8888
$storeId
8989
);
90-
91-
$product->setData('url_key', $generatedKey);
9290
}
9391

94-
$this->_getProductAction()->updateAttributes(
95-
[$product->getId()],
96-
['url_path' => null],
97-
$storeId
98-
);
99-
100-
10192
$productUrlRewriteResult = $this->_getProductUrlRewriteGenerator()->generate($product);
10293

10394
$productUrlRewriteResult = $this->_sanitizeProductUrlRewrites($productUrlRewriteResult);

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ or
7575
* to save a current URL rewrites (you want to get a new URL rewites and save current) use option `--save-old-urls`:
7676
>`$> php bin/magento ok:urlrewrites:regenerate --save-old-urls`
7777
78+
* to prevent regeneration of "url_key" values (use current "url_key" values) use option `--no-regen-url-key`:
79+
>`$> php bin/magento ok:urlrewrites:regenerate --no-regen-url-key`
80+
7881
* do not run full reindex at the end of URL rewrites generation use option `--no-reindex`:
7982
>`$> php bin/magento ok:urlrewrites:regenerate --no-reindex`
8083
@@ -88,7 +91,7 @@ or
8891
>`$> php bin/magento ok:urlrewrites:regenerate --no-progress`
8992
9093
### YOU CAN COMBINE OPTIONS
91-
>`$> php bin/magento ok:urlrewrites:regenerate --store-id=2 --save-old-urls --no-reindex`
94+
>`$> php bin/magento ok:urlrewrites:regenerate --store-id=2 --save-old-urls --no-regen-url-key --no-reindex`
9295
9396
### YOU CAN NOT COMBINE THIS OPTIONS TOGETHER
9497
* `--entity-type=product` and `--category-id`/`--categories-range`

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Add into Magento 2 a CLI feature which allow to regenerate a Url rewrites of products and categories",
44
"keywords": ["magento", "magento2 extension", "magento 2 extension", "extension", "module", "magento2 module", "magento 2 module"],
55
"type": "magento2-module",
6-
"version": "1.4.2",
6+
"version": "1.4.3",
77
"homepage": "https://github.com/olegkoval/magento2-regenerate_url_rewrites",
88
"authors": [
99
{

etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
-->
1212
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
13-
<module name="OlegKoval_RegenerateUrlRewrites" setup_version="1.4.2">
13+
<module name="OlegKoval_RegenerateUrlRewrites" setup_version="1.4.3">
1414
<sequence>
1515
<module name="Magento_Store"/>
1616
<module name="Magento_Catalog"/>

0 commit comments

Comments
 (0)