From 6baaaed7ec28f5389bca966a9957b08de6959382 Mon Sep 17 00:00:00 2001 From: ralbin Date: Tue, 27 Nov 2018 09:37:41 -0600 Subject: [PATCH 1/3] Adding updated readme instructions on how to use product ID range and updated Product model to accept a range of IDs to update --- Model/UrlRewrite/Entity/Product.php | 23 +++++++++++++++++++++-- README.md | 6 ++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Model/UrlRewrite/Entity/Product.php b/Model/UrlRewrite/Entity/Product.php index 67b8a6e..3aab69b 100644 --- a/Model/UrlRewrite/Entity/Product.php +++ b/Model/UrlRewrite/Entity/Product.php @@ -42,9 +42,27 @@ public function rebuild(int $storeId, array $arguments = []) $this->productCollection->clear(); $this->productCollection->setStoreId($storeId); $this->productCollection->addAttributeToSelect(['url_path', 'url_key']); - + // do we have any arguments for this if ($arguments) { - $this->productCollection->addFieldToFilter('entity_id', ['in' => $arguments]); + // Are we trying to do a range from x to y? + if(strstr((string)$arguments[0], '-')) + { + $range = (string)$arguments[0]; + $parts = explode("-", $range); + $from_id = (int)$parts[0]; + $to_id = (int)$parts[1]; + // make sure we have two valid IDs + if($from_id && $to_id) + { + $this->productCollection->addFieldToFilter('entity_id', ['from' => $from_id, 'to' => $to_id]); + }else{ + // there was invalid values + return false; + } + }else { + // do all products as they are sent in as a csv ( example 1,2,19,234 + $this->productCollection->addFieldToFilter('entity_id', ['in' => $arguments]); + } } $this->urlRewrite @@ -54,4 +72,5 @@ public function rebuild(int $storeId, array $arguments = []) ->setCollection($this->productCollection) ->rebuild(); } + } diff --git a/README.md b/README.md index e9fea7b..a31ce6a 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,12 @@ Rebuild only products ```php bin/magento urlrewrite:rebuild products +``` + + or products by IDs as an ID range this example is IDs from 16 to 69 + +```php +bin/magento urlrewrite:rebuild products -p=16-69 ``` Rebuild only cms-pages From 33830dc3d989bb47efb71476d9684d8698684345 Mon Sep 17 00:00:00 2001 From: Russell Albin Date: Thu, 29 Nov 2018 10:19:49 -0600 Subject: [PATCH 2/3] Update Product.php Removed else --- Model/UrlRewrite/Entity/Product.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Model/UrlRewrite/Entity/Product.php b/Model/UrlRewrite/Entity/Product.php index 3aab69b..f6e33b0 100644 --- a/Model/UrlRewrite/Entity/Product.php +++ b/Model/UrlRewrite/Entity/Product.php @@ -59,9 +59,6 @@ public function rebuild(int $storeId, array $arguments = []) // there was invalid values return false; } - }else { - // do all products as they are sent in as a csv ( example 1,2,19,234 - $this->productCollection->addFieldToFilter('entity_id', ['in' => $arguments]); } } From b86e9ad079b7021ea6fdb5bdd74c272bc794fa3b Mon Sep 17 00:00:00 2001 From: Russell Albin Date: Fri, 30 Nov 2018 15:00:24 -0600 Subject: [PATCH 3/3] Update Product.php Removing an else that the code validation said was not needed. --- Model/UrlRewrite/Entity/Product.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Model/UrlRewrite/Entity/Product.php b/Model/UrlRewrite/Entity/Product.php index f6e33b0..4ff01a2 100644 --- a/Model/UrlRewrite/Entity/Product.php +++ b/Model/UrlRewrite/Entity/Product.php @@ -55,9 +55,6 @@ public function rebuild(int $storeId, array $arguments = []) if($from_id && $to_id) { $this->productCollection->addFieldToFilter('entity_id', ['from' => $from_id, 'to' => $to_id]); - }else{ - // there was invalid values - return false; } } }