From 7754b493b85a76cae24eab59ce7d16ee3adb1153 Mon Sep 17 00:00:00 2001 From: SharkyKZ Date: Tue, 18 Jun 2019 17:53:07 +0300 Subject: [PATCH 1/4] [com_contact] Title not incremented during batch copy --- .../components/com_contact/tables/contact.php | 2 ++ libraries/src/MVC/Model/AdminModel.php | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/administrator/components/com_contact/tables/contact.php b/administrator/components/com_contact/tables/contact.php index af11346448e3a..911a871e49379 100644 --- a/administrator/components/com_contact/tables/contact.php +++ b/administrator/components/com_contact/tables/contact.php @@ -38,6 +38,8 @@ public function __construct(&$db) { parent::__construct('#__contact_details', 'id', $db); + $this->setColumnAlias('title', 'name'); + JTableObserverTags::createObserver($this, array('typeAlias' => 'com_contact.contact')); JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_contact.contact')); } diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 935156c4d9e41..4bb17b2882b3c 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -913,9 +913,11 @@ public function delete(&$pks) protected function generateNewTitle($category_id, $alias, $title) { // Alter the title & alias - $table = $this->getTable(); + $table = $this->getTable(); + $aliasField = $table->getColumnAlias('alias'); + $catidField = $table->getColumnAlias('catid'); - while ($table->load(array('alias' => $alias, 'catid' => $category_id))) + while ($table->load(array($aliasField => $alias, $catidField => $category_id))) { $title = StringHelper::increment($title); $alias = StringHelper::increment($alias, 'dash'); @@ -1531,9 +1533,11 @@ protected function checkCategoryId($categoryId) public function generateTitle($categoryId, $table) { // Alter the title & alias - $data = $this->generateNewTitle($categoryId, $table->alias, $table->title); - $table->title = $data['0']; - $table->alias = $data['1']; + $titleField = $table->getColumnAlias('title'); + $aliasField = $table->getColumnAlias('alias'); + $data = $this->generateNewTitle($categoryId, $table->$aliasField, $table->$titleField); + $table->$titleField = $data['0']; + $table->$aliasField = $data['1']; } /** From e62e3bd45a00332190489a9948a257a01ae96138 Mon Sep 17 00:00:00 2001 From: SharkyKZ Date: Tue, 18 Jun 2019 18:27:42 +0300 Subject: [PATCH 2/4] Newsfeeds --- administrator/components/com_newsfeeds/tables/newsfeed.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/administrator/components/com_newsfeeds/tables/newsfeed.php b/administrator/components/com_newsfeeds/tables/newsfeed.php index af9e65206d20f..130f452cd3b4f 100644 --- a/administrator/components/com_newsfeeds/tables/newsfeed.php +++ b/administrator/components/com_newsfeeds/tables/newsfeed.php @@ -35,6 +35,8 @@ public function __construct(&$db) { parent::__construct('#__newsfeeds', 'id', $db); + $this->setColumnAlias('title', 'name'); + JTableObserverTags::createObserver($this, array('typeAlias' => 'com_newsfeeds.newsfeed')); JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_newsfeeds.newsfeed')); } From 9c794ee3ad4e87404fbc917260d8fe72bd709438 Mon Sep 17 00:00:00 2001 From: SharkyKZ Date: Tue, 18 Jun 2019 18:36:59 +0300 Subject: [PATCH 3/4] Increment only matching titles --- libraries/src/MVC/Model/AdminModel.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 4bb17b2882b3c..88972aec460e7 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -916,10 +916,15 @@ protected function generateNewTitle($category_id, $alias, $title) $table = $this->getTable(); $aliasField = $table->getColumnAlias('alias'); $catidField = $table->getColumnAlias('catid'); + $titleField = $table->getColumnAlias('title'); while ($table->load(array($aliasField => $alias, $catidField => $category_id))) { - $title = StringHelper::increment($title); + if ($title === $table->$titleField) + { + $title = StringHelper::increment($title); + } + $alias = StringHelper::increment($alias, 'dash'); } From 13bc80c7c6ffbb70cd1db4c24393171903c4a628 Mon Sep 17 00:00:00 2001 From: SharkyKZ Date: Tue, 18 Jun 2019 18:38:07 +0300 Subject: [PATCH 4/4] Remove methods --- .../components/com_contact/models/contact.php | 29 ------------------- .../com_newsfeeds/models/newsfeed.php | 29 ------------------- 2 files changed, 58 deletions(-) diff --git a/administrator/components/com_contact/models/contact.php b/administrator/components/com_contact/models/contact.php index c6e1393768866..74d0b80fa2621 100644 --- a/administrator/components/com_contact/models/contact.php +++ b/administrator/components/com_contact/models/contact.php @@ -526,35 +526,6 @@ public function featured($pks, $value = 0) return true; } - /** - * Method to change the title & alias. - * - * @param integer $category_id The id of the parent. - * @param string $alias The alias. - * @param string $name The title. - * - * @return array Contains the modified title and alias. - * - * @since 3.1 - */ - protected function generateNewTitle($category_id, $alias, $name) - { - // Alter the title & alias - $table = $this->getTable(); - - while ($table->load(array('alias' => $alias, 'catid' => $category_id))) - { - if ($name == $table->name) - { - $name = StringHelper::increment($name); - } - - $alias = StringHelper::increment($alias, 'dash'); - } - - return array($name, $alias); - } - /** * Is the user allowed to create an on the fly category? * diff --git a/administrator/components/com_newsfeeds/models/newsfeed.php b/administrator/components/com_newsfeeds/models/newsfeed.php index d977387387e4c..9b4fba9d927fa 100644 --- a/administrator/components/com_newsfeeds/models/newsfeed.php +++ b/administrator/components/com_newsfeeds/models/newsfeed.php @@ -450,35 +450,6 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') parent::preprocessForm($form, $data, $group); } - /** - * Method to change the title & alias. - * - * @param integer $category_id The id of the parent. - * @param string $alias The alias. - * @param string $name The title. - * - * @return array Contains the modified title and alias. - * - * @since 3.1 - */ - protected function generateNewTitle($category_id, $alias, $name) - { - // Alter the title & alias - $table = $this->getTable(); - - while ($table->load(array('alias' => $alias, 'catid' => $category_id))) - { - if ($name == $table->name) - { - $name = StringHelper::increment($name); - } - - $alias = StringHelper::increment($alias, 'dash'); - } - - return array($name, $alias); - } - /** * Is the user allowed to create an on the fly category? *