From eb3c321b1079d8454c2b6b3ed088131e36746711 Mon Sep 17 00:00:00 2001 From: SharkyKZ Date: Sun, 23 Jun 2019 18:57:09 +0300 Subject: [PATCH 1/2] Contact and Newsfeed title not incremented during batch copy (#25259) --- .../components/com_contact/models/contact.php | 29 ------------------- .../components/com_contact/tables/contact.php | 2 ++ .../com_newsfeeds/models/newsfeed.php | 29 ------------------- .../com_newsfeeds/tables/newsfeed.php | 2 ++ libraries/src/MVC/Model/AdminModel.php | 21 ++++++++++---- 5 files changed, 19 insertions(+), 64 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_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/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? * 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')); } diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 935156c4d9e41..88972aec460e7 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -913,11 +913,18 @@ 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'); + $titleField = $table->getColumnAlias('title'); - while ($table->load(array('alias' => $alias, 'catid' => $category_id))) + 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'); } @@ -1531,9 +1538,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 e48e9f1727ddf4563bcbd0a772d22e6f9b270e61 Mon Sep 17 00:00:00 2001 From: Federico Liva Date: Sun, 23 Jun 2019 17:58:06 +0200 Subject: [PATCH 2/2] Improved PHPDoc for JDatabaseDriver::updateObject (#25134) The $key parameter can be either an array or a string but from PHPDoc it was only an array --- libraries/joomla/database/driver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/joomla/database/driver.php b/libraries/joomla/database/driver.php index 59399090a7b93..a350000cfccf8 100644 --- a/libraries/joomla/database/driver.php +++ b/libraries/joomla/database/driver.php @@ -2203,10 +2203,10 @@ public function truncateTable($table) /** * Updates a row in a table based on an object's properties. * - * @param string $table The name of the database table to update. - * @param object &$object A reference to an object whose public properties match the table fields. - * @param array $key The name of the primary key. - * @param boolean $nulls True to update null fields or false to ignore them. + * @param string $table The name of the database table to update. + * @param object &$object A reference to an object whose public properties match the table fields. + * @param array|string $key The name of the primary key. + * @param boolean $nulls True to update null fields or false to ignore them. * * @return boolean True on success. *