本文整理汇总了PHP中KunenaForumTopicHelper::recount方法的典型用法代码示例。如果您正苦于以下问题:PHP KunenaForumTopicHelper::recount方法的具体用法?PHP KunenaForumTopicHelper::recount怎么用?PHP KunenaForumTopicHelper::recount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KunenaForumTopicHelper
的用法示例。
在下文中一共展示了KunenaForumTopicHelper::recount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recount
function recount() {
$app = JFactory::getApplication ();
$state = $app->getUserState ( 'com_kunena.admin.recount', null );
if ($state === null) {
// First run
$query = "SELECT MAX(id) FROM #__kunena_messages";
$db = JFactory::getDBO();
$db->setQuery ( $query );
$state = new StdClass();
$state->step = 0;
$state->maxId = (int) $db->loadResult ();
$state->start = 0;
}
$this->checkTimeout();
while (1) {
$count = mt_rand(95000, 105000);
switch ($state->step) {
case 0:
// Update topic statistics
kimport('kunena.forum.topic.helper');
KunenaForumTopicHelper::recount(false, $state->start, $state->start+$count);
$state->start += $count;
//$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_TOPICS', min($state->start, $state->maxId), $state->maxId) );
break;
case 1:
// Update usertopic statistics
kimport('kunena.forum.topic.user.helper');
KunenaForumTopicUserHelper::recount(false, $state->start, $state->start+$count);
$state->start += $count;
//$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERTOPICS', min($state->start, $state->maxId), $state->maxId) );
break;
case 2:
// Update user statistics
kimport('kunena.user.helper');
KunenaUserHelper::recount();
//$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USER') );
break;
case 3:
// Update category statistics
kimport('kunena.forum.category.helper');
KunenaForumCategoryHelper::recount();
//$app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_CATEGORY') );
break;
default:
$app->setUserState ( 'com_kunena.admin.recount', null );
$app->enqueueMessage (JText::_('COM_KUNENA_RECOUNTFORUMS_DONE'));
$this->setRedirect(KunenaRoute::_('index.php?option=com_kunena', false));
return;
}
if (!$state->start || $state->start > $state->maxId) {
$state->step++;
$state->start = 0;
}
if ($this->checkTimeout()) break;
}
$app->setUserState ( 'com_kunena.admin.recount', $state );
$this->setRedirect(KunenaRoute::_('index.php?option=com_kunena&view=recount&task=recount', false));
}
示例2: recountCategories
function recountCategories()
{
$app = JFactory::getApplication();
$state = $app->getUserState('com_kunena.install.recount', null);
// Only perform this stage if database needs recounting (upgrade from older version)
$version = $this->getVersion();
if (version_compare($version->version, '2.0.0-DEV', ">")) {
return true;
}
if ($state === null) {
// First run
$query = "SELECT MAX(id) FROM #__kunena_messages";
$this->db->setQuery($query);
$state = new StdClass();
$state->step = 0;
$state->maxId = (int) $this->db->loadResult();
$state->start = 0;
}
while (1) {
$count = mt_rand(95000, 105000);
switch ($state->step) {
case 0:
// Update topic statistics
KunenaForumTopicHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
$this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_TOPICS', min($state->start, $state->maxId), $state->maxId), true, '', 'recount');
break;
case 1:
// Update usertopic statistics
KunenaForumTopicUserHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
$this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_USERTOPICS', min($state->start, $state->maxId), $state->maxId), true, '', 'recount');
break;
case 2:
// Update user statistics
KunenaUserHelper::recount();
$this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_USER'), true, '', 'recount');
break;
case 3:
// Update category statistics
KunenaForumCategoryHelper::recount();
$this->addStatus(JText::sprintf('COM_KUNENA_MIGRATE_RECOUNT_CATEGORY'), true, '', 'recount');
break;
default:
$app->setUserState('com_kunena.install.recount', null);
$this->addStatus(JText::_('COM_KUNENA_MIGRATE_RECOUNT_DONE'), true, '', 'recount');
return true;
}
if (!$state->start || $state->start > $state->maxId) {
$state->step++;
$state->start = 0;
}
if ($this->checkTimeout()) {
break;
}
}
$app->setUserState('com_kunena.install.recount', $state);
return false;
}
示例3: dorecount
/**
* 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);
}
示例4: restore
function restore()
{
if (!JSession::checkToken('post')) {
$this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
$this->app->redirect(KunenaRoute::_($this->baseurl, false));
}
$cid = JRequest::getVar('cid', array(), 'post', 'array');
// Array of integers
JArrayHelper::toInteger($cid);
$type = JRequest::getCmd('type', 'topics', 'post');
if (empty($cid)) {
$this->app->enqueueMessage(JText::_('COM_KUNENA_A_NO_MESSAGES_SELECTED'), 'notice');
$this->app->redirect(KunenaRoute::_($this->baseurl, false));
}
$nb_items = 0;
if ($type == 'messages') {
$messages = KunenaForumMessageHelper::getMessages($cid, 'none');
foreach ($messages as $target) {
if ($target->publish(KunenaForum::PUBLISHED)) {
$nb_items++;
} else {
$this->app->enqueueMessage($target->getError(), 'notice');
}
}
} elseif ($type == 'topics') {
$topics = KunenaForumTopicHelper::getTopics($cid, 'none');
foreach ($topics as $target) {
if ($target->publish(KunenaForum::PUBLISHED)) {
$nb_items++;
} else {
$this->app->enqueueMessage($target->getError(), 'notice');
}
}
} else {
// Error...
}
if ($nb_items > 0) {
$this->app->enqueueMessage(JText::sprintf('COM_KUNENA_TRASH_ITEMS_RESTORE_DONE', $nb_items));
}
KunenaUserHelper::recount();
KunenaForumTopicHelper::recount();
KunenaForumCategoryHelper::recount();
$this->app->redirect(KunenaRoute::_($this->baseurl, false));
}
示例5: recount
function recount()
{
$state = $this->app->getUserState('com_kunena.admin.recount', null);
if ($state === null) {
// First run: get last message id (if topics were created with <K2.0)
$query = "SELECT MAX(id) FROM #__kunena_messages";
$db = JFactory::getDBO();
$db->setQuery($query);
$state = new StdClass();
$state->step = 0;
$state->maxId = (int) $db->loadResult();
$state->start = 0;
$state->reload = 0;
$state->topics = JRequest::getBool('topics', false);
$state->usertopics = JRequest::getBool('usertopics', false);
$state->categories = JRequest::getBool('categories', false);
$state->users = JRequest::getBool('users', false);
}
$this->checkTimeout();
while (1) {
$count = mt_rand(95000, 105000);
switch ($state->step) {
case 0:
if ($state->topics) {
// Update topic statistics
KunenaForumTopicHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
//$this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_TOPICS', min($state->start, $state->maxId), $state->maxId) );
}
break;
case 1:
if ($state->usertopics) {
// Update usertopic statistics
KunenaForumTopicUserHelper::recount(false, $state->start, $state->start + $count);
$state->start += $count;
//$this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USERTOPICS', min($state->start, $state->maxId), $state->maxId) );
}
break;
case 2:
if ($state->categories) {
// Update category statistics
KunenaForumCategoryHelper::recount();
//$this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_CATEGORY') );
}
break;
case 3:
if ($state->users) {
// Update user statistics
KunenaUserHelper::recount();
//$this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_ADMIN_RECOUNT_USER') );
}
break;
default:
$this->app->setUserState('com_kunena.admin.recount', null);
$this->app->enqueueMessage(JText::_('COM_KUNENA_RECOUNTFORUMS_DONE'));
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
return;
}
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);
$this->setRedirect(KunenaRoute::_("{$this->baseurl}&task=recount&i={$state->reload}", false));
}
示例6: restore
function restore() {
$app = JFactory::getApplication ();
if (! JRequest::checkToken ()) {
$app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
$app->redirect ( KunenaRoute::_($this->baseurl, false) );
}
$kunena_db = JFactory::getDBO ();
$cid = JRequest::getVar ( 'cid', array (), 'post', 'array' );
$topics = JRequest::getInt ( 'topics', 0, 'post' );
$messages = JRequest::getInt ( 'messages', 0, 'post' );
if (empty ( $cid )) {
$app->enqueueMessage ( JText::_ ( 'COM_KUNENA_A_NO_MESSAGES_SELECTED' ), 'notice' );
$app->redirect ( KunenaRoute::_($this->baseurl, false) );
}
$msg = JText::_('COM_KUNENA_TRASH_RESTORE_DONE');
if ( $messages ) {
$messages = KunenaForumMessageHelper::getMessages($cid);
foreach ( $messages as $target ) {
if ( $target->authorise('undelete') && $target->publish(KunenaForum::PUBLISHED) ) {
$app->enqueueMessage ( $msg );
} else {
$app->enqueueMessage ( $target->getError(), 'notice' );
}
}
} elseif ( $topics ) {
$topics = KunenaForumTopicHelper::getTopics($cid);
foreach ( $topics as $target ) {
if ( $target->authorise('undelete') && $target->publish(KunenaForum::PUBLISHED) ) {
$app->enqueueMessage ( $msg );
} else {
$app->enqueueMessage ( $target->getError(), 'notice' );
}
}
} else {
// error
}
KunenaUserHelper::recount();
KunenaForumTopicHelper::recount();
KunenaForumCategoryHelper::recount ();
$app->redirect(KunenaRoute::_($this->baseurl, false));
}