Skip to content

Commit

Permalink
Batch copy: copy permission too (#24736)
Browse files Browse the repository at this point in the history
  • Loading branch information
alikon authored and HLeithner committed Aug 8, 2019
1 parent 666afd9 commit 107ddfe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libraries/src/MVC/Model/AdminModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ protected function batchCopy($value, $pks, $contexts)
}

$newIds = array();
$db = $this->getDbo();

// Parent exists so let's proceed
while (!empty($pks))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions libraries/src/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 107ddfe

Please sign in to comment.