From 0fcbb409e360437e3e94d1526bd66f28fcc9827e Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 6 Dec 2013 12:26:39 +0100 Subject: [PATCH] Factorized URL desactivation in UrlRewritingTrait::markRewritenUrlObsolete() --- core/lib/Thelia/Model/Category.php | 7 +------ core/lib/Thelia/Model/Content.php | 7 +------ core/lib/Thelia/Model/Folder.php | 7 +------ core/lib/Thelia/Model/Product.php | 7 +------ core/lib/Thelia/Model/Tools/UrlRewritingTrait.php | 13 +++++++++++++ 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 0cade8216..8b8b53e4f 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -115,12 +115,7 @@ class Category extends BaseCategory */ public function postDelete(ConnectionInterface $con = null) { - RewritingUrlQuery::create() - ->filterByView($this->getRewrittenUrlViewName()) - ->filterByViewId($this->getId()) - ->update(array( - "View" => ConfigQuery::getObsoleteRewrittenUrlView() - )); + $this->markRewritenUrlObsolete(); $this->dispatchEvent(TheliaEvents::AFTER_DELETECATEGORY, new CategoryEvent($this)); } diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 1c1c8c0f6..3a002e6d1 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -148,12 +148,7 @@ class Content extends BaseContent public function postDelete(ConnectionInterface $con = null) { - RewritingUrlQuery::create() - ->filterByView($this->getRewrittenUrlViewName()) - ->filterByViewId($this->getId()) - ->update(array( - "View" => ConfigQuery::getObsoleteRewrittenUrlView() - )); + $this->markRewritenUrlObsolete(); $this->dispatchEvent(TheliaEvents::AFTER_DELETECONTENT, new ContentEvent($this)); } diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index 0b9edafd6..9249c94e2 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -100,12 +100,7 @@ class Folder extends BaseFolder public function postDelete(ConnectionInterface $con = null) { - RewritingUrlQuery::create() - ->filterByView($this->getRewrittenUrlViewName()) - ->filterByViewId($this->getId()) - ->update(array( - "View" => ConfigQuery::getObsoleteRewrittenUrlView() - )); + $this->markRewritenUrlObsolete(); $this->dispatchEvent(TheliaEvents::AFTER_DELETEFOLDER, new FolderEvent($this)); } diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 1f5358cbb..12b98c890 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -263,12 +263,7 @@ class Product extends BaseProduct */ public function postDelete(ConnectionInterface $con = null) { - RewritingUrlQuery::create() - ->filterByView($this->getRewrittenUrlViewName()) - ->filterByViewId($this->getId()) - ->update(array( - "View" => ConfigQuery::getObsoleteRewrittenUrlView() - )); + $this->markRewritenUrlObsolete(); $this->dispatchEvent(TheliaEvents::AFTER_DELETEPRODUCT, new ProductEvent($this)); } diff --git a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php index d16ceaf5f..bcbbb9afd 100644 --- a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php +++ b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php @@ -29,6 +29,7 @@ use Thelia\Exception\UrlRewritingException; use Thelia\Model\RewritingUrlQuery; use Thelia\Model\RewritingUrl; use Thelia\Tools\URL; +use Thelia\Model\ConfigQuery; /** * A trait for managing Rewritten URLs from model classes */ @@ -136,6 +137,18 @@ trait UrlRewritingTrait { return $url; } + /** + * Mark the current URL as obseolete + */ + public function markRewritenUrlObsolete() { + RewritingUrlQuery::create() + ->filterByView($this->getRewrittenUrlViewName()) + ->filterByViewId($this->getId()) + ->update(array( + "View" => ConfigQuery::getObsoleteRewrittenUrlView() + )); + } + /** * Set the rewritten URL for the given locale *