Skip to content

Commit

Permalink
Fix batch copy not copying fields
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Aug 18, 2018
1 parent fb60f8a commit 7ec4d5d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
28 changes: 25 additions & 3 deletions administrator/components/com_content/models/article.php
Expand Up @@ -48,14 +48,15 @@ class ContentModelArticle extends JModelAdmin
/**
* Function that can be overriden to do any data cleanup after batch copying data
*
* @param JTableInterface $table The table object containing the newly created item
* @param integer $newId The id of the new item
* @param \JTableInterface $table The table object containing the newly created item
* @param integer $newId The id of the new item
* @param integer $oldId The original item id
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
protected function cleanupPostBatchCopy(JTableInterface $table, $newId)
protected function cleanupPostBatchCopy(\JTableInterface $table, $newId, $oldId)
{
// Check if the article was featured and update the #__content_frontpage table
if ($table->featured == 1)
Expand All @@ -67,6 +68,27 @@ protected function cleanupPostBatchCopy(JTableInterface $table, $newId)
$db->setQuery($query);
$db->execute();
}

// Register FieldsHelper
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');

$oldItem = $this->getTable();
$oldItem->load($oldId);
$fields = FieldsHelper::getFields('com_content.article', $oldItem, true);

$fieldsData = array();

if (!empty($fields))
{
$fieldsData['com_fields'] = array();

foreach ($fields as $field)
{
$fieldsData['com_fields'][$field->name] = $field->rawvalue;
}
}

JEventDispatcher::getInstance()->trigger('onContentAfterSave', array('com_content.article', &$this->table, true, $fieldsData));
}

/**
Expand Down
9 changes: 5 additions & 4 deletions libraries/src/MVC/Model/AdminModel.php
Expand Up @@ -486,7 +486,7 @@ protected function batchCopy($value, $pks, $contexts)
// Get the new item ID
$newId = $this->table->get('id');

$this->cleanupPostBatchCopy($this->table, $newId);
$this->cleanupPostBatchCopy($this->table, $newId, $pk);

// Add the new ID to the array
$newIds[$pk] = $newId;
Expand All @@ -501,14 +501,15 @@ protected function batchCopy($value, $pks, $contexts)
/**
* Function that can be overriden to do any data cleanup after batch copying data
*
* @param JTableInterface $table The table object containing the newly created item
* @param integer $newId The id of the new item
* @param \JTableInterface $table The table object containing the newly created item
* @param integer $newId The id of the new item
* @param integer $oldId The original item id
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
protected function cleanupPostBatchCopy(\JTableInterface $table, $newId)
protected function cleanupPostBatchCopy(\JTableInterface $table, $newId, $oldId)
{
}

Expand Down

0 comments on commit 7ec4d5d

Please sign in to comment.