From 0bc385d7e1ddf3d72c1143ff5d8f3d06a5df8dab Mon Sep 17 00:00:00 2001 From: George Wilson Date: Sun, 15 Jan 2017 21:09:47 +0000 Subject: [PATCH] Delete UCM content entries when Joomla articles are deleted (#13592) --- libraries/cms/helper/tags.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/libraries/cms/helper/tags.php b/libraries/cms/helper/tags.php index 7f2ae907228e3..cabd04eb62e1a 100644 --- a/libraries/cms/helper/tags.php +++ b/libraries/cms/helper/tags.php @@ -362,22 +362,37 @@ public function createTagsFromMetadata($metadata) * Method to delete the tag mappings and #__ucm_content record for for an item * * @param JTableInterface $table JTable object of content table where delete occurred - * @param integer $contentItemId ID of the content item. + * @param integer|array $contentItemId ID of the content item. Or an array of key/value pairs with array key + * being a primary key name and value being the content item ID. Note + * multiple primary keys are not supported * * @return boolean true on success, false on failure * * @since 3.1 + * @throws InvalidArgumentException */ public function deleteTagData(JTableInterface $table, $contentItemId) { - $result = $this->unTagItem($contentItemId, $table); + $key = $table->getKeyName(); - /** - * @var JTableCorecontent $ucmContentTable - */ + if (!is_array($contentItemId)) + { + $contentItemId = array($key => $contentItemId); + } + + // If we have multiple items for the content item primary key we currently don't support this so + // throw an InvalidArgumentException for now + if (count($contentItemId) != 1) + { + throw new InvalidArgumentException('Multiple primary keys are not supported as a content item id'); + } + + $result = $this->unTagItem($contentItemId[$key], $table); + + /** @var JTableCorecontent $ucmContentTable */ $ucmContentTable = JTable::getInstance('Corecontent'); - return $result && $ucmContentTable->deleteByContentId($contentItemId, $this->typeAlias); + return $result && $ucmContentTable->deleteByContentId($contentItemId[$key], $this->typeAlias); } /**