diff --git a/administrator/components/com_content/models/article.php b/administrator/components/com_content/models/article.php index b6dba4d0cfefe..3f4ea3917c7e9 100644 --- a/administrator/components/com_content/models/article.php +++ b/administrator/components/com_content/models/article.php @@ -67,6 +67,12 @@ protected function batchCopy($value, $pks, $contexts) return false; } + JPluginHelper::importPlugin('system'); + $dispatcher = JEventDispatcher::getInstance(); + + // Register FieldsHelper + JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); + // Parent exists so we let's proceed while (!empty($pks)) { @@ -93,6 +99,19 @@ protected function batchCopy($value, $pks, $contexts) } } + $fields = FieldsHelper::getFields('com_content.article', $this->table, true); + $fieldsData = array(); + + if (!empty($fields)) + { + $fieldsData['com_fields'] = array(); + + foreach ($fields as $field) + { + $fieldsData['com_fields'][$field->name] = $field->rawvalue; + } + } + // Alter the title & alias $data = $this->generateNewTitle($categoryId, $this->table->alias, $this->table->title); $this->table->title = $data['0']; @@ -150,6 +169,9 @@ protected function batchCopy($value, $pks, $contexts) $db->setQuery($query); $db->execute(); } + + // Run event for copied article + $dispatcher->trigger('onContentAfterSave', array('com_content.article', &$this->table, true, $fieldsData)); } // Clean the cache @@ -158,6 +180,117 @@ protected function batchCopy($value, $pks, $contexts) return $newIds; } + /** + * Batch move categories to a new category. + * + * @param integer $value The new category ID. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return boolean True on success. + * + * @since __DEPLOY_VERSION__ + */ + protected function batchMove($value, $pks, $contexts) + { + if (empty($this->batchSet)) + { + // Set some needed variables. + $this->user = JFactory::getUser(); + $this->table = $this->getTable(); + $this->tableClassName = get_class($this->table); + $this->contentType = new JUcmType; + $this->type = $this->contentType->getTypeByTable($this->tableClassName); + } + + $categoryId = (int) $value; + + if (!$this->checkCategoryId($categoryId)) + { + return false; + } + + JPluginHelper::importPlugin('system'); + $dispatcher = JEventDispatcher::getInstance(); + + // Register FieldsHelper + JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); + + // Parent exists so we proceed + foreach ($pks as $pk) + { + if (!$this->user->authorise('core.edit', $contexts[$pk])) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); + + return false; + } + + // Check that the row actually exists + if (!$this->table->load($pk)) + { + if ($error = $this->table->getError()) + { + // Fatal error + $this->setError($error); + + return false; + } + else + { + // Not fatal error + $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); + continue; + } + } + + $fields = FieldsHelper::getFields('com_content.article', $this->table, true); + $fieldsData = array(); + + if (!empty($fields)) + { + $fieldsData['com_fields'] = array(); + + foreach ($fields as $field) + { + $fieldsData['com_fields'][$field->name] = $field->rawvalue; + } + } + + // Set the new category ID + $this->table->catid = $categoryId; + + // Check the row. + if (!$this->table->check()) + { + $this->setError($this->table->getError()); + + return false; + } + + if (!empty($this->type)) + { + $this->createTagsHelper($this->tagsObserver, $this->type, $pk, $this->typeAlias, $this->table); + } + + // Store the row. + if (!$this->table->store()) + { + $this->setError($this->table->getError()); + + return false; + } + + // Run event for moved article + $dispatcher->trigger('onContentAfterSave', array('com_content.article', &$this->table, false, $fieldsData)); + } + + // Clean the cache + $this->cleanCache(); + + return true; + } + /** * Method to test whether a record can be deleted. *