/** * @static * @param $body * @param $page * @param $user * @param string $metaTitle * @param bool|WallMessage $parent * @param array $relatedTopics * @param bool $notify * @param bool $notifyEveryone * @return WallMessage|Bool */ public static function buildNewMessageAndPost($body, $page, $user, $metaTitle = '', $parent = false, $relatedTopics = array(), $notify = true, $notifyEveryone = false) { wfProfileIn(__METHOD__); if ($page instanceof Title) { $userPageTitle = $page; } else { $userPageTitle = F::build('Title', array($page, NS_USER_WALL), 'newFromText'); } // create wall page by bot if not exist if (!$userPageTitle->exists()) { $userPageTitle = self::addMessageWall($userPageTitle); } if (empty($userPageTitle)) { wfProfileOut(__METHOD__); return false; } if ($parent === false) { $metaData = array('title' => $metaTitle); if ($notifyEveryone) { $metaData['notify_everyone'] = time(); } if (!empty($relatedTopics)) { $metaData['related_topics'] = implode('|', $relatedTopics); } $acStatus = F::build('ArticleComment', array($body, $user, $userPageTitle, false, $metaData), 'doPost'); } else { if (!$parent->canReply()) { wfProfileOut(__METHOD__); return false; } $acStatus = F::build('ArticleComment', array($body, $user, $userPageTitle, $parent->getTitle()->getArticleId(), null), 'doPost'); } if ($acStatus === false) { wfProfileOut(__METHOD__); return false; } $ac = ArticleComment::newFromId($acStatus[1]->getId()); if (empty($ac)) { wfProfileOut(__METHOD__); return false; } // after successful posting invalidate Wall cache /** * @var $class WallMessage */ $class = F::build('WallMessage', array($ac->getTitle(), $ac)); if ($parent === false) { //$db = DB_SLAVE $class->storeRelatedTopicsInDB($relatedTopics); $class->setOrderId(1); $class->getWall()->invalidateCache(); } else { $count = $parent->getOrderId(true); //this is not work perfect with transations if (is_numeric($count)) { $count++; $parent->setOrderId($count); $class->setOrderId($count); } // after successful posting invalidate Thread cache $class->getThread()->invalidateCache(); } //Build data for sweet url ? id#number_of_comment //notify if ($notify) { $class->sendNotificationAboutLastRev(); } if ($parent === false && $notifyEveryone) { $class->notifyEveryone(); } $class->addWatch($user); wfRunHooks('AfterBuildNewMessageAndPost', array(&$class)); wfProfileOut(__METHOD__); return $class; }