Bonjour,
J'ai une erreur à la ligne 154 mais je ne sais pas quoi...
Voilà la ligne:
if (XenForo_Application::getOptions()->descriptionRequired && empty($this->get('tag_line')) && XenForo_Visitor::getInstance()->is_admin && XenForo_Visitor::getInstance()->is_moderator && XenForo_Visitor::getInstance()->is_staff)
Voilà l'erreur:
ErrorException: Fatal Error: Can't use method return value in write context ***/***/***/***/***.php:154
Voilà mon code:
Merci de votre aide !
Kroko11
J'ai une erreur à la ligne 154 mais je ne sais pas quoi...
Voilà la ligne:
if (XenForo_Application::getOptions()->descriptionRequired && empty($this->get('tag_line')) && XenForo_Visitor::getInstance()->is_admin && XenForo_Visitor::getInstance()->is_moderator && XenForo_Visitor::getInstance()->is_staff)
Voilà l'erreur:
ErrorException: Fatal Error: Can't use method return value in write context ***/***/***/***/***.php:154
Voilà mon code:
Code:
<?php
class Faqe_Articles_DataWriter_Articles extends XenForo_DataWriter
{
/**
* Constants to store the extra data fields for item DW in _postSave.
*
* @var string
*/
const DATA_ATTACHMENT_HASH = 'attachmentHash';
const OPTION_MAX_TAGGED_USERS = 'maxTaggedUsers';
const DATA_DELETE_REASON = 'deleteReason';
const DATA_THREAD_WATCH_DEFAULT = 'watchDefault';
const OPTION_CREATE_THREAD_NODE_ID = 'createThreadNodeId';
const OPTION_CREATE_THREAD_PREFIX_ID = 'createThreadNodeId';
const OPTION_DELETE_THREAD_TITLE_TEMPLATE = 'deleteThreadTitleTemplate';
const OPTION_DELETE_THREAD_ACTION = 'deleteThreadAction';
const OPTION_DELETE_ADD_POST = 'deleteAddPost';
/**
* Title of the phrase that will be created when a call to set the
* existing data fails (when the data doesn't exist).
*
* @var string
*/
protected $_existingDataErrorPhrase = 'faqe_requested_article_not_found';
/**
* Processes users that are tagged in an article message.
* @var array
*/
protected $_taggedUsers = array();
/**
* Gets the fields that are defined for the table. See parent for explanation.
*
* @return array
*/
protected function _getFields()
{
return array(
'xf_articles' => array(
'article_id' => array('type' => self::TYPE_UINT, 'autoIncrement' => true),
'article_category_id' => array('type' => self::TYPE_UINT, 'required' => true, 'verification' => array('$this', '_validateCategoryId')),
'discussion_thread_id' => array('type' => self::TYPE_UINT, 'default' => 0),
'user_id' => array('type' => self::TYPE_UINT, 'required' => true),
'username' => array('type' => self::TYPE_STRING, 'required' => true, 'maxLength' => 50),
'article_state' => array('type' => self::TYPE_STRING, 'default' => 'visible', 'allowedValues' => array('visible', 'moderated', 'deleted')),
'title' => array('type' => self::TYPE_STRING,'maxLength' => 150, 'required' => true, 'requiredError' => 'please_enter_valid_title'),
'tag_line' => array('type' => self::TYPE_STRING, 'maxLength' => 100),
'message' => array('type' => self::TYPE_STRING,'required' => true,'requiredError' => 'please_enter_valid_message'),
'start_date' => array('type' => self::TYPE_UINT, 'default' => XenForo_Application::$time),
'view_count' => array('type' => self::TYPE_UINT, 'default' => 0),
'comment_count' => array('type' => self::TYPE_UINT_FORCED, 'default' => 0),
'attach_count' => array('type' => self::TYPE_UINT, 'required' => false, 'default' => 0),
'likes' => array('type' => self::TYPE_UINT_FORCED, 'default' => 0),
'like_users' => array('type' => self::TYPE_SERIALIZED, 'default' => 'a:0:{}'),
'last_message_user_id' => array('type' => self::TYPE_UINT, 'default' => 0),
'last_message_username' => array('type' => self::TYPE_STRING, 'default' => '', 'maxLength' => 50),
'last_message_date' => array('type' => self::TYPE_UINT, 'default' => XenForo_Application::$time),
'last_update' => array('type' => self::TYPE_UINT, 'default' => XenForo_Application::$time),
'featured' => array('type' => self::TYPE_UINT, 'required' => false, 'default' => 0),
'warning_id' => array('type' => self::TYPE_UINT, 'default' => 0),
'warning_message' => array('type' => self::TYPE_STRING, 'default' => ''),
'prefix_id' => array('type' => self::TYPE_UINT, 'default' => 0),
'tags' => array('type' => self::TYPE_SERIALIZED, 'default' => 'a:0:{}'),
'icon_date' => array('type' => self::TYPE_UINT, 'default' => 0),
'rating_count' => array('type' => self::TYPE_UINT_FORCED, 'default' => 0),
'rating_sum' => array('type' => self::TYPE_UINT_FORCED, 'default' => 0),
'rating_avg' => array('type' => self::TYPE_FLOAT, 'default' => 0),
)
);
}
/**
* Gets the actual existing data out of data that was passed in. See parent for explanation.
*
* @param mixed
*
* @return array|false
*/
protected function _getExistingData($data)
{
if (!$id = $this->_getExistingPrimaryKey($data))
{
return false;
}
return array('xf_articles' => $this->_getArticleModel()->getArticleById($id));
}
/**
* Gets SQL condition to update the existing record.
*
* @return string
*/
protected function _getUpdateCondition($tableName)
{
return 'article_id = ' . $this->_db->quote($this->getExisting('article_id'));
}
/**
* Gets the default set of options for this data writer.
*
* @return array
*/
protected function _getDefaultOptions()
{
$options = XenForo_Application::getOptions();
return array(
self::OPTION_MAX_TAGGED_USERS => 0,
self::OPTION_CREATE_THREAD_NODE_ID => null,
self::OPTION_CREATE_THREAD_PREFIX_ID => null,
self::OPTION_DELETE_THREAD_ACTION => $options->get('articleDeleteThreadAction', 'action'),
self::OPTION_DELETE_THREAD_TITLE_TEMPLATE => $options->get('articleDeleteThreadAction', 'update_title') ? $options->get('articleDeleteThreadAction', 'title_template') : '',
self::OPTION_DELETE_ADD_POST => $options->get('articleDeleteThreadAction', 'add_post')
);
}
protected function _validateCategoryId(&$id)
{
$category = $this->_getCategoryModel()->getCategoryById($id);
if (!$category)
{
$this->error(new XenForo_Phrase('requested_category_not_found'), 'article_category_id');
return false;
}
return true;
}
/**
* Pre-save handling.
*/
protected function _preSave()
{
if ($this->get('article_state') === null)
{
$this->set('article_state', 'visible');
}
if ($this->get('prefix_id') && $this->isChanged('article_category_id'))
{
if (!$this->_getPrefixModel()->getPrefixIfInCategory($this->get('prefix_id'), $this->get('article_category_id')))
{
$this->set('prefix_id', 0); // invalid prefix
}
}
if (XenForo_Application::getOptions()->descriptionRequired && empty($this->get('tag_line')) && XenForo_Visitor::getInstance()->is_admin && XenForo_Visitor::getInstance()->is_moderator && XenForo_Visitor::getInstance()->is_staff)
{
$this->error(new XenForo_Phrase('faqe_please_enter_valid_tag_line'));
}
if ($this->isInsert())
{
$this->updateRating(
intval($this->get('rating_sum')), intval($this->get('rating_count'))
);
}
$this->processTaggedUsers();
}
/**
* Post-save handling.
*/
protected function _postSave()
{
if ($this->isInsert())
{
$this->_getNewsFeedModel()->publish(
$this->get('user_id'),
$this->get('username'),
'articles',
$this->get('article_id'),
'insert'
);
$ipId = XenForo_Model_Ip::log(
$this->get('user_id'), 'xf_articles', $this->get('article_id'), 'insert'
);
$this->_db->update('xf_articles', array(
'ip_id' => $ipId
), 'article_id = ' . $this->get('article_id'));
}
$postSaveChanges = array();
if ($this->isUpdate() && $this->isChanged('title'))
{
$threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
if ($threadDw->setExistingData($this->get('discussion_thread_id')))
{
$threadTitle = $this->_stripTemplateComponents($threadDw->get('title'), $this->getOption(self::OPTION_DELETE_THREAD_TITLE_TEMPLATE));
if ($threadTitle == $this->getExisting('title'))
{
$threadDw->set('title', $this->_getThreadTitle());
$threadDw->save();
}
}
}
$removed = false;
if ($this->isChanged('article_state'))
{
if ($this->get('article_state') == 'visible')
{
$this->_articleMadeVisible($postSaveChanges);
}
else if ($this->isUpdate() && $this->getExisting('article_state') == 'visible')
{
$this->_articleRemoved();
$removed = true;
}
$this->_updateDeletionLog();
$this->_updateModerationQueue();
}
if ($postSaveChanges)
{
$this->_db->update('xf_articles', $postSaveChanges,
'article_id = ' . $this->_db->quote($this->get('article_id'))
);
}
$catDw = $this->_getCategoryDwForUpdate();
if ($catDw && !$removed)
{
// will already be called for removal
$catDw->articleUpdate($this);
$catDw->save();
}
if ($this->isUpdate() && $this->isChanged('user_id'))
{
if ($this->get('user_id') && $this->get('article_state') == 'visible' && !$this->isChanged('article_state'))
{
$this->_db->query('
UPDATE xf_user
SET article_count = article_count + 1
WHERE user_id = ?
', $this->get('user_id'));
}
if ($this->getExisting('user_id') && $this->getExisting('article_state') == 'visible')
{
$this->_db->query('
UPDATE xf_user
SET article_count = IF(article_count > 0, article_count - 1, 0)
WHERE user_id = ?
', $this->getExisting('user_id'));
}
}
$this->_indexForSearch();
$attachmentHash = $this->getExtraData(self::DATA_ATTACHMENT_HASH);
if ($attachmentHash)
{
$this->_associateAttachments($attachmentHash);
}
}
protected function _stripTemplateComponents($string, $template)
{
if (!$template) {
return $string;
}
$template = str_replace('\{title\}', '(.*)', preg_quote($template, '/'));
if (preg_match('/^' . $template . '$/', $string, $match)) {
return $match[1];
}
return $string;
}
/**
* Post-delete handling
*/
protected function _postDelete()
{
$this->_deleteAttachments();
$idQuoted = $this->_db->quote($this->get('article_id'));
$this->_db->delete('xf_article_watch', 'article_id = ' . $idQuoted);
if ($this->getExisting('article_state') == 'visible')
{
$this->_articleRemoved();
}
$this->_updateDeletionLog(true);
$this->getModelFromCache('XenForo_Model_ModerationQueue')->deleteFromModerationQueue(
'articles', $this->get('article_id')
);
$filePath = $this->_getArticleModel()->getArticleIconFilePath($this->get('article_id'));
@unlink($filePath);
}
protected function _getThreadTitle()
{
$title = $this->get('title');
if ($this->get('article_state') != 'visible' && $this->getOption(self::OPTION_DELETE_THREAD_TITLE_TEMPLATE))
{
$title = str_replace(
'{title}', $this->get('title'),
$this->getOption(self::OPTION_DELETE_THREAD_TITLE_TEMPLATE)
);
}
return $title;
}
protected function _insertDiscussionThread($nodeId, $prefixId = 0)
{
if (!$nodeId)
{
return false;
}
$forum = $this->getModelFromCache('XenForo_Model_Forum')->getForumById($nodeId);
if (!$forum)
{
return false;
}
$threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
$threadDw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
$threadDw->bulkSet(array(
'node_id' => $nodeId,
'title' => $this->_getThreadTitle(),
'user_id' => $this->get('user_id'),
'username' => $this->get('username'),
'discussion_type' => 'article',
'prefix_id' => $prefixId
));
$threadDw->set('discussion_state', $this->getModelFromCache('XenForo_Model_Post')->getPostInsertMessageState(array(), $forum));
$threadDw->setOption(XenForo_DataWriter_Discussion::OPTION_PUBLISH_FEED, false);
$messageText = $this->get('message');
$parser = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_AutoLink', false));
$snippet = $parser->render(XenForo_Helper_String::wholeWordTrim($messageText, 500));
$message = new XenForo_Phrase('faqe_message_create_automatically_article_thread', array(
'title' => $this->get('title'),
'tagLine' => $this->get('tag_line'),
'username' => $this->get('username'),
'userId' => $this->get('user_id'),
'snippet' => $snippet,
'articleLink' => XenForo_Link::buildPublicLink('canonical:articles', $this->getMergedData())
), false);
$postWriter = $threadDw->getFirstMessageDw();
$postWriter->set('message', $message->render());
$postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $forum);
$postWriter->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_PUBLISH_FEED, false);
if (!$threadDw->save())
{
return false;
}
$this->set('discussion_thread_id',
$threadDw->get('thread_id'), '', array('setAfterPreSave' => true)
);
$postSaveChanges['discussion_thread_id'] = $threadDw->get('thread_id');
$this->getModelFromCache('XenForo_Model_Thread')->markThreadRead(
$threadDw->getMergedData(), $forum, XenForo_Application::$time
);
$this->getModelFromCache('XenForo_Model_ThreadWatch')->setThreadWatchStateWithUserDefault(
$this->get('user_id'), $threadDw->get('thread_id'),
$this->getExtraData(self::DATA_THREAD_WATCH_DEFAULT)
);
return $threadDw->get('thread_id');
}
protected function _articleRemoved()
{
if ($this->get('discussion_thread_id'))
{
$threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
if ($threadDw->setExistingData($this->get('discussion_thread_id')))
{
switch ($this->getOption(self::OPTION_DELETE_THREAD_ACTION))
{
case 'delete':
$threadDw->set('discussion_state', 'deleted');
break;
case 'close':
$threadDw->set('discussion_open', 0);
break;
}
if ($this->getOption(self::OPTION_DELETE_THREAD_TITLE_TEMPLATE))
{
$threadTitle = str_replace(
'{title}', $threadDw->get('title'),
$this->getOption(self::OPTION_DELETE_THREAD_TITLE_TEMPLATE)
);
$threadDw->set('title', $threadTitle);
}
$threadDw->save();
if ($this->getOption(self::OPTION_DELETE_ADD_POST))
{
$forum = $this->getModelFromCache('XenForo_Model_Forum')->getForumById($threadDw->get('node_id'));
if ($forum)
{
$messageState = $this->getModelFromCache('XenForo_Model_Post')->getPostInsertMessageState(
$threadDw->getMergedData(), $forum
);
}
else
{
$messageState = 'visible';
}
$message = new XenForo_Phrase('faqe_article_message_delete_article', array(
'title' => $this->get('title'),
'tagLine' => $this->get('tag_line'),
'username' => $this->get('username'),
'userId' => $this->get('user_id'),
'articleLink' => XenForo_Link::buildPublicLink('canonical:articles', $this->getMergedData())
), false);
$writer = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post');
$writer->bulkSet(array(
'user_id' => $this->get('user_id'),
'username' => $this->get('username'),
'message_state' => $messageState,
'thread_id' => $threadDw->get('thread_id'),
'message' => strval($message)
));
$writer->save();
}
}
}
if ($this->get('user_id'))
{
$this->_db->query('
UPDATE xf_user
SET article_count = IF(article_count > 0, article_count - 1, 0)
WHERE user_id = ?
', $this->get('user_id'));
}
$catDw = $this->_getCategoryDwForUpdate();
if ($catDw)
{
$catDw->articleRemoved($this);
$catDw->save();
}
}
protected function _articleMadeVisible(array &$postSaveChanges)
{
if (!$this->get('discussion_thread_id'))
{
$catDw = $this->_getCategoryDwForUpdate();
$nodeId = $this->getOption(self::OPTION_CREATE_THREAD_NODE_ID);
if ($nodeId === null)
{
$nodeId = $catDw->get('thread_node_id');
}
$prefixId = $this->getOption(self::OPTION_CREATE_THREAD_PREFIX_ID);
if ($prefixId === null)
{
$prefixId = $catDw->get('thread_prefix_id');
}
$threadId = $this->_insertDiscussionThread($nodeId, $prefixId);
if ($threadId)
{
$this->set('discussion_thread_id',
$threadId, '', array('setAfterPreSave' => true)
);
$postSaveChanges['discussion_thread_id'] = $threadId;
}
} else {
$threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
if ($threadDw->setExistingData($this->get('discussion_thread_id')))
{
switch ($this->getOption(self::OPTION_DELETE_THREAD_ACTION))
{
case 'delete':
$threadDw->set('discussion_state', 'visible');
break;
case 'close':
$threadDw->set('discussion_open', 1);
break;
}
$title = $this->_stripTemplateComponents($threadDw->get('title'), $this->getOption(self::OPTION_DELETE_THREAD_TITLE_TEMPLATE));
$threadDw->set('title', $title);
$threadDw->save();
}
}
if ($this->get('user_id') && $this->get('article_state') == 'visible')
{
$this->_db->query('
UPDATE xf_user
SET article_count = article_count + 1
WHERE user_id = ?
', $this->get('user_id'));
}
}
/**
* Update xf_article_rating table to reflect the new rating.
*
* @param integer $rating
*/
public function updateRating($adjustSum = null, $adjustCount = null)
{
if ($adjustSum === null && $adjustCount === null)
{
$rating = $this->_db->fetchRow('
SELECT COUNT(*) AS total, SUM(rating) AS sum
FROM xf_article_rating
WHERE article_id = ?
', $this->get('article_id'));
$this->set('rating_sum', $rating['sum']);
$this->set('rating_count', $rating['total']);
}
else
{
if ($adjustSum !== null)
{
$this->set('rating_sum', $this->get('rating_sum') + $adjustSum);
}
if ($adjustCount !== null)
{
$this->set('rating_count', $this->get('rating_count') + $adjustCount);
}
}
if ($this->get('rating_count'))
{
$this->set('rating_avg', $this->get('rating_sum') / $this->get('rating_count'));
}
else
{
$this->set('rating_avg', 0);
}
}
protected function _updateDeletionLog($hardDelete = false)
{
if ($hardDelete
|| ($this->isChanged('article_state') && $this->getExisting('article_state') == 'deleted')
)
{
$this->getModelFromCache('XenForo_Model_DeletionLog')->removeDeletionLog(
'articles', $this->get('article_id')
);
}
if ($this->isChanged('article_state') && $this->get('article_state') == 'deleted')
{
$reason = $this->getExtraData(self::DATA_DELETE_REASON);
$this->getModelFromCache('XenForo_Model_DeletionLog')->logDeletion(
'articles', $this->get('article_id'), $reason
);
}
}
protected function _updateModerationQueue()
{
if (!$this->isChanged('article_state'))
{
return;
}
if ($this->get('article_state') == 'moderated')
{
$this->getModelFromCache('XenForo_Model_ModerationQueue')->insertIntoModerationQueue(
'articles', $this->get('article_id'), $this->get('start_date')
);
}
else if ($this->getExisting('article_state') == 'moderated')
{
$this->getModelFromCache('XenForo_Model_ModerationQueue')->deleteFromModerationQueue(
'articles', $this->get('article_id')
);
}
}
/**
* Updates the search index for this article item.
*/
protected function _indexForSearch()
{
if ($this->get('article_state') == 'visible')
{
if ($this->getExisting('article_state') != 'visible' || $this->isChanged('message'))
{
$this->_insertOrUpdateSearchIndex();
}
}
else if ($this->isUpdate() && $this->get('article_state') != 'visible' && $this->getExisting('article_state') == 'visible')
{
$this->_deleteFromSearchIndex();
}
}
/**
* Inserts a record in the search index for this article item.
*/
protected function _insertOrUpdateSearchIndex()
{
$searchHandler = new Faqe_Articles_Search_DataHandler_Articles();
if (!$searchHandler)
{
return;
}
$indexer = new XenForo_Search_Indexer();
$searchHandler->insertIntoIndex($indexer, $this->getMergedData());
}
/**
* Deletes this article item from the search index.
*/
protected function _deleteFromSearchIndex()
{
$searchHandler = new Faqe_Articles_Search_DataHandler_Articles();
if (!$searchHandler)
{
return;
}
$index = new XenForo_Search_Indexer();
$searchHandler->deleteFromIndex($index, $this->getMergedData());
}
protected function _associateAttachments($attachmentHash)
{
$rows = $this->_db->update('xf_attachment', array(
'content_type' => 'articles',
'content_id' => $this->get('article_id'),
'temp_hash' => '',
'unassociated' => 0
), 'temp_hash = ' . $this->_db->quote($attachmentHash));
if ($rows)
{
$attachmentCount = $this->get('attach_count') + $rows;
$this->set('attach_count', $attachmentCount, '', array('setAfterPreSave' => true));
$this->_db->update('xf_articles', array(
'attach_count' => $attachmentCount),
'article_id = ' . $this->get('article_id')
);
}
}
protected function _deleteAttachments()
{
$this->getModelFromCache('XenForo_Model_Attachment')->deleteAttachmentsFromContentIds('articles', array($this->get('article_id')));
}
protected function processTaggedUsers()
{
/* @var $taggingModel XenForo_Model_UserTagging */
$taggingModel = $this->getModelFromCache('XenForo_Model_UserTagging');
$this->_taggedUsers = $taggingModel->getTaggedUsersInMessage(
$this->get('message'), $newMessage, 'bb'
);
$this->set('message', $newMessage);
}
/**
* @see XenForo_DataWriter::_postSaveAfterTransaction()
*/
protected function _postSaveAfterTransaction()
{
parent::_postSaveAfterTransaction();
$this->notifyTaggedUsers();
}
protected function notifyTaggedUsers()
{
if ($this->isChanged('article_state') && $this->get('article_state') == 'moderated')
{
return;
}
if (!$this->isInsert())
{
return;
}
if ($this->_taggedUsers)
{
$entryModel = XenForo_Model::create('Faqe_Articles_Model_Articles');
$entry = $this->getMergedData();
$entryModel->alertTaggedMembers($entry, $this->_taggedUsers);
}
}
/**
* @return Faqe_Articles_DataWriter_Category|false
*/
protected function _getCategoryDwForUpdate()
{
$dw = XenForo_DataWriter::create('Faqe_Articles_DataWriter_Category', XenForo_DataWriter::ERROR_SILENT);
if ($dw->setExistingData($this->get('article_category_id')))
{
return $dw;
}
else
{
return false;
}
}
/**
* @return Faqe_Articles_Model_Articles
*/
protected function _getArticleModel()
{
return $this->getModelFromCache('Faqe_Articles_Model_Articles');
}
/**
* @return Faqe_Articles_Model_Category
*/
protected function _getCategoryModel()
{
return $this->getModelFromCache('Faqe_Articles_Model_Category');
}
/**
* @return Faqe_Articles_Model_Prefix
*/
protected function _getPrefixModel()
{
return $this->getModelFromCache('Faqe_Articles_Model_Prefix');
}
}
Merci de votre aide !
Kroko11