diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 88972aec460e7..7c231b5a7f4e0 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -408,6 +408,7 @@ protected function batchCopy($value, $pks, $contexts) } $newIds = array(); + $db = $this->getDbo(); // Parent exists so let's proceed while (!empty($pks)) @@ -435,6 +436,12 @@ protected function batchCopy($value, $pks, $contexts) } } + // Check for asset_id + if ($this->table->hasField($this->table->getColumnAlias('asset_id'))) + { + $oldAssetId = $this->table->asset_id; + } + $this->generateTitle($categoryId, $this->table); // Reset the ID because we are making a copy @@ -487,6 +494,21 @@ protected function batchCopy($value, $pks, $contexts) // Get the new item ID $newId = $this->table->get('id'); + if (!empty($oldAssetId)) + { + // Copy rules + $query = $db->getQuery(true); + $query->clear() + ->update($db->quoteName('#__assets', 't')) + ->join('INNER', $db->quoteName('#__assets', 's') . + ' ON ' . $db->quoteName('s.id') . ' = ' . $oldAssetId + ) + ->set($db->quoteName('t.rules') . ' = ' . $db->quoteName('s.rules')) + ->where($db->quoteName('t.id') . ' = ' . $this->table->asset_id); + + $db->setQuery($query)->execute(); + } + $this->cleanupPostBatchCopy($this->table, $newId, $pk); // Add the new ID to the array diff --git a/libraries/src/Table/Table.php b/libraries/src/Table/Table.php index 3eed88e1598e9..074dac8f0ca12 100644 --- a/libraries/src/Table/Table.php +++ b/libraries/src/Table/Table.php @@ -1722,4 +1722,20 @@ protected function _unlock() return true; } + + /** + * Check if the record has a property (applying a column alias if it exists) + * + * @param string $key key to be checked + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public function hasField($key) + { + $key = $this->getColumnAlias($key); + + return property_exists($this, $key); + } }