Example #1
0
 public function stepFinish()
 {
     KunenaForum::setup();
     $entryfiles = array(array(KPATH_ADMIN, 'api', 'php'), array(KPATH_ADMIN, 'admin.kunena', 'php'), array(KPATH_SITE, 'router', 'php'), array(KPATH_SITE, 'kunena', 'php'));
     $lang = JFactory::getLanguage();
     $lang->load('com_kunena', JPATH_SITE) || $lang->load('com_kunena', KPATH_SITE);
     $this->createMenu(false);
     // Fix broken category aliases (workaround for < 2.0-DEV12 bug)
     $count = KunenaForumCategoryHelper::fixAliases();
     $md5 = md5_file(KPATH_ADMIN . '/api.new.php');
     foreach ($entryfiles as $fileparts) {
         list($path, $filename, $ext) = $fileparts;
         if (is_file("{$path}/{$filename}.new.{$ext}")) {
             $success = JFile::delete("{$path}/{$filename}.{$ext}");
             if (!$success) {
                 $this->addStatus(JText::_('COM_KUNENA_INSTALL_DELETE_STATUS_FAIL') . " {$filename}.{$ext}", false, '');
             }
             $success = JFile::move("{$path}/{$filename}.new.{$ext}", "{$path}/{$filename}.{$ext}");
             if (!$success) {
                 $this->addStatus(JText::_('COM_KUNENA_INSTALL_RENAMING_FAIL') . " {$filename}.new.{$ext}", false, '');
             }
         }
     }
     // Clean cache, just in case
     KunenaMenuHelper::cleanCache();
     JFactory::getCache('com_kunena')->clean();
     // Test if api file has been fully copied
     $this->waitFile(KPATH_ADMIN . "/api.php", $md5);
     if (!$this->getInstallError()) {
         $this->updateVersionState('');
         $this->addStatus(JText::_('COM_KUNENA_INSTALL_SUCCESS'), true, '');
         $this->setStep($this->getStep() + 1);
     }
 }
Example #2
0
 public function stepFinish()
 {
     KunenaForum::setup();
     $lang = JFactory::getLanguage();
     $lang->load('com_kunena', JPATH_SITE) || $lang->load('com_kunena', KUNENA_INSTALLER_SITEPATH);
     $this->createMenu(false);
     // Fix broken category aliases (workaround for < 2.0-DEV12 bug)
     KunenaForumCategoryHelper::fixAliases();
     // Clean cache, just in case
     KunenaMenuHelper::cleanCache();
     /** @var JCache|JCacheController $cache */
     $cache = JFactory::getCache();
     $cache->clean('com_kunena');
     // Delete installer file (only if not using GIT build).
     if (!KunenaForum::isDev()) {
         JFile::delete(KPATH_ADMIN . '/install.php');
     }
     if (!$this->getInstallError()) {
         $this->updateVersionState('');
         $this->addStatus(JText::_('COM_KUNENA_INSTALL_SUCCESS'), true, '');
         $this->setStep($this->getStep() + 1);
     }
 }
Example #3
0
 /**
  * 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);
 }
Example #4
0
 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(4500, 5500);
         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();
                     KunenaForumCategoryHelper::fixAliases();
                     //$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));
 }