Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch copy: copy permission too #24736

Merged
merged 22 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just move this down. Put $oldAssetId directly in the query and this if statement just down there

{
$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
Copy link
Contributor

@Quy Quy Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this point $this->table->asset_id has incremented. Thus the old value must be stored before and not after this point. The PR works as it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok maybe I missed something in the code.

$newId = $this->table->get('id');

if (!empty($oldAssetId))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!empty($oldAssetId))
if ($this->table->hasField($this->table->getColumnAlias('asset_id')) && !empty($this->table->asset_id))

{
// Copy rules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copy rules
// Copy rules
$oldAssetId = $this->table->asset_id;

$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);
}
}