From c72d6f29333adfb8fcf6d9329852c4b4a0154a2d Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Sat, 27 Apr 2019 11:41:02 +0200 Subject: [PATCH 1/9] copy permission too --- libraries/src/MVC/Model/AdminModel.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 935156c4d9e41..58405005deef3 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,7 @@ protected function batchCopy($value, $pks, $contexts) } } + $oldAssetId = $this->table->asset_id; $this->generateTitle($categoryId, $this->table); // Reset the ID because we are making a copy @@ -487,6 +489,18 @@ protected function batchCopy($value, $pks, $contexts) // Get the new item ID $newId = $this->table->get('id'); + // 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 From e2f655565662bb43c432d2bac8e19eeb3cd3da8f Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Wed, 5 Jun 2019 19:59:32 +0200 Subject: [PATCH 2/9] cs --- libraries/src/MVC/Model/AdminModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 58405005deef3..e3b2e7db759c7 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -498,7 +498,7 @@ protected function batchCopy($value, $pks, $contexts) ) ->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); From d11936d4ab957cfd0b65689780e2e62762170b17 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 10 Jun 2019 12:25:47 +0200 Subject: [PATCH 3/9] sanity check --- libraries/src/MVC/Model/AdminModel.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index e3b2e7db759c7..cbfdb1fd1b0d2 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -489,17 +489,20 @@ protected function batchCopy($value, $pks, $contexts) // Get the new item ID $newId = $this->table->get('id'); - // 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(); + if ($this->table->hasField($this->table->getColumnAlias('asset_id'))) + { + // 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); From c0fbbeb1a9c681ac4fe8ff671da9f30d8cfd34dd Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 10 Jun 2019 12:47:07 +0200 Subject: [PATCH 4/9] backport --- libraries/src/Table/Table.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libraries/src/Table/Table.php b/libraries/src/Table/Table.php index 3eed88e1598e9..9484f89297949 100644 --- a/libraries/src/Table/Table.php +++ b/libraries/src/Table/Table.php @@ -1722,4 +1722,19 @@ 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); + } } From 7b6861a855856c086a8951e93302973f95f32ecb Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 10 Jun 2019 14:21:41 +0200 Subject: [PATCH 5/9] Update libraries/src/Table/Table.php Co-Authored-By: Quy --- libraries/src/Table/Table.php | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/src/Table/Table.php b/libraries/src/Table/Table.php index 9484f89297949..074dac8f0ca12 100644 --- a/libraries/src/Table/Table.php +++ b/libraries/src/Table/Table.php @@ -1735,6 +1735,7 @@ protected function _unlock() public function hasField($key) { $key = $this->getColumnAlias($key); + return property_exists($this, $key); } } From 7f8bad80600699956e95eb67dacefd5711521b98 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 11 Jun 2019 09:28:58 +0200 Subject: [PATCH 6/9] no asset fix --- libraries/src/MVC/Model/AdminModel.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index cbfdb1fd1b0d2..8568f9d9a5ab6 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -436,7 +436,15 @@ protected function batchCopy($value, $pks, $contexts) } } - $oldAssetId = $this->table->asset_id; + // Check for asset_id + $hasAsset = false; + + if ($this->table->hasField($this->table->getColumnAlias('asset_id'))) + { + $oldAssetId = $this->table->asset_id; + $hasAsset = true; + } + $this->generateTitle($categoryId, $this->table); // Reset the ID because we are making a copy @@ -489,7 +497,7 @@ protected function batchCopy($value, $pks, $contexts) // Get the new item ID $newId = $this->table->get('id'); - if ($this->table->hasField($this->table->getColumnAlias('asset_id'))) + if ($hasAsset) { // Copy rules $query = $db->getQuery(true); From 1c47a41907e80e0dd6e3b825474e7a7e9e732f40 Mon Sep 17 00:00:00 2001 From: Quy Date: Sun, 16 Jun 2019 19:09:42 -0700 Subject: [PATCH 7/9] Improve code --- libraries/src/MVC/Model/AdminModel.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 8568f9d9a5ab6..21d834982983c 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -436,15 +436,6 @@ protected function batchCopy($value, $pks, $contexts) } } - // Check for asset_id - $hasAsset = false; - - if ($this->table->hasField($this->table->getColumnAlias('asset_id'))) - { - $oldAssetId = $this->table->asset_id; - $hasAsset = true; - } - $this->generateTitle($categoryId, $this->table); // Reset the ID because we are making a copy @@ -497,8 +488,11 @@ protected function batchCopy($value, $pks, $contexts) // Get the new item ID $newId = $this->table->get('id'); - if ($hasAsset) + // Check for asset_id + if ($this->table->hasField($this->table->getColumnAlias('asset_id'))) { + $oldAssetId = $this->table->asset_id; + // Copy rules $query = $db->getQuery(true); $query->clear() From 69197d8b5d4ccb5b13f274c4cd95e2ac0e7a45ee Mon Sep 17 00:00:00 2001 From: Quy Date: Mon, 17 Jun 2019 10:13:13 -0700 Subject: [PATCH 8/9] Redo previous fix --- libraries/src/MVC/Model/AdminModel.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 21d834982983c..8cc7c075f883e 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -436,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 @@ -488,11 +494,8 @@ protected function batchCopy($value, $pks, $contexts) // Get the new item ID $newId = $this->table->get('id'); - // Check for asset_id - if ($this->table->hasField($this->table->getColumnAlias('asset_id'))) + if (!empty($oldAssetId)) { - $oldAssetId = $this->table->asset_id; - // Copy rules $query = $db->getQuery(true); $query->clear() From 7fa45d3623fff58777348cb8d39715705f7e9d6e Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 4 Aug 2019 13:14:09 +0200 Subject: [PATCH 9/9] Fix PHPCS --- libraries/src/MVC/Model/AdminModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 4568e8989722e..7c231b5a7f4e0 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -436,9 +436,9 @@ protected function batchCopy($value, $pks, $contexts) } } - // Check for asset_id + // Check for asset_id if ($this->table->hasField($this->table->getColumnAlias('asset_id'))) - { + { $oldAssetId = $this->table->asset_id; }