/** * Perform recount on statistics in smaller chunks. * * @return void * @throws Exception */ public function dorecount() { $ajax = $this->input->getWord('format', 'html') == 'json'; if (!JSession::checkToken('request')) { $this->setResponse(array('success' => false, 'header' => JText::_('COM_KUNENA_AJAX_ERROR'), 'message' => JText::_('COM_KUNENA_AJAX_DETAILS_BELOW'), 'error' => JText::_('COM_KUNENA_ERROR_TOKEN')), $ajax); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } $state = $this->app->getUserState('com_kunena.admin.recount', null); try { $this->checkTimeout(); while (1) { // Topic count per run. // TODO: count isn't accurate as it can overflow total. $count = mt_rand(4500, 5500); switch ($state->step) { case 0: if ($state->topics) { // Update topic statistics KunenaForumTopicHelper::recount(false, $state->start, $state->start + $count); $state->start += $count; $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_TOPICS_X', round(min(100 * $state->start / $state->maxId + 1, 100)) . '%'); } break; case 1: if ($state->usertopics) { // Update user's topic statistics KunenaForumTopicUserHelper::recount(false, $state->start, $state->start + $count); $state->start += $count; $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERTOPICS_X', round(min(100 * $state->start / $state->maxId + 1, 100)) . '%'); } break; case 2: if ($state->categories) { // Update category statistics KunenaForumCategoryHelper::recount(); KunenaForumCategoryHelper::fixAliases(); $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_CATEGORIES_X', '100%'); } break; case 3: if ($state->users) { // Update user statistics KunenaUserHelper::recount(); $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERS_X', '100%'); } break; case 4: if ($state->polls) { // Update user statistics KunenaForumTopicPollHelper::recount(); $msg = JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_POLLS_X', '100%'); } break; default: $header = JText::_('COM_KUNENA_RECOUNTFORUMS_DONE'); $msg = JText::_('COM_KUNENA_AJAX_REQUESTED_RECOUNTED'); $this->app->setUserState('com_kunena.admin.recount', null); $this->setResponse(array('success' => true, 'status' => '100%', 'header' => $header, 'message' => $msg), $ajax); $this->setRedirect(KunenaRoute::_($this->baseurl, false), $header); return; } $state->current = min($state->current + $count, $state->total); if (!$state->start || $state->start > $state->maxId) { $state->step++; $state->start = 0; } if ($this->checkTimeout()) { break; } } $state->reload++; $this->app->setUserState('com_kunena.admin.recount', $state); } catch (Exception $e) { if (!$ajax) { throw $e; } $this->setResponse(array('success' => false, 'status' => sprintf("%2.1f%%", 99 * $state->current / ($state->total + 1)), 'header' => JText::_('COM_KUNENA_AJAX_ERROR'), 'message' => JText::_('COM_KUNENA_AJAX_DETAILS_BELOW'), 'error' => $e->getMessage()), $ajax); } $token = JSession::getFormToken() . '=1'; $redirect = KunenaRoute::_("{$this->baseurl}&task=dorecount&i={$state->reload}&{$token}", false); $this->setResponse(array('success' => true, 'status' => sprintf("%2.1f%%", 99 * $state->current / ($state->total + 1)), 'header' => JText::_('COM_KUNENA_AJAX_RECOUNT_WAIT'), 'message' => $msg, 'href' => $redirect), $ajax); }
public function getPoll() { static $poll = null; if (!$poll) { $poll = KunenaForumTopicPollHelper::get($this->poll_id); $poll->threadid = $this->id; } return $poll; }
/** * @return KunenaForumTopicPoll */ public function getPoll() { $poll = KunenaForumTopicPollHelper::get($this->poll_id); $poll->threadid = $this->id; return $poll; }
/** * Returns KunenaForumTopicPoll object. * * @param mixed $identifier Poll to load - Can be only an integer. * @param bool $reset * * @return KunenaForumTopicPoll */ static public function getInstance($identifier = null, $reset = false) { return KunenaForumTopicPollHelper::get($identifier, $reset); }