Commit 990a0f4a by Scott

Merge branch 'pr/594' into dev

parents a1da5148 baaebd15
...@@ -11,3 +11,4 @@ qa-cache/*/ ...@@ -11,3 +11,4 @@ qa-cache/*/
ehthumbs.db ehthumbs.db
Thumbs.db Thumbs.db
.idea/ .idea/
/nbproject/private/
\ No newline at end of file
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/AbstractFinalStep.php
Description: Base class for final step classes in the recalc processes.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
abstract class Q2A_Recalc_AbstractFinalStep extends Q2A_Recalc_AbstractStep
{
protected $isFinalStep = true;
public function doStep()
{
throw new Exception('Do not process the completion step.');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/AbstractStep.php
Description: Base class for step classes in the recal processes.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
require_once QA_INCLUDE_DIR . 'app/format.php'; //required for qa_number_format()
abstract class Q2A_Recalc_AbstractStep
{
protected $state;
protected $isFinalStep = false;
public function __construct(Q2A_Recalc_State $state)
{
$this->state = $state;
}
abstract public function doStep();
public function getMessage()
{
return '';
}
public function isFinalStep()
{
return $this->isFinalStep;
}
/**
* Return the translated language ID string replacing the progress and total in it.
* @access private
* @param string $langId Language string ID that contains 2 placeholders (^1 and ^2)
* @param int $progress Amount of processed elements
* @param int $total Total amount of elements
*
* @return string Returns the language string ID with their placeholders replaced with
* the formatted progress and total numbers
*/
protected function progressLang($langId, $progress, $total)
{
return strtr(qa_lang($langId), array(
'^1' => qa_format_number((int)$progress),
'^2' => qa_format_number((int)$total),
));
}
public static function factory(Q2A_Recalc_State $state)
{
$class = $state->getOperationClass();
if (class_exists($class)) {
return new $class($state);
}
return null;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/BlobsToDiskComplete.php
Description: Recalc class for the end of the blobs to disk process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_BlobsMoveComplete extends Q2A_Recalc_AbstractFinalStep
{
public function getMessage()
{
return qa_lang('admin/blobs_move_complete');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/BlobsToDB.php
Description: Recalc class for the start of the blobs to database process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_BlobsToDB extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('doblobstodb_move');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/BlobsToDBMove.php
Description: Recalc processing class for the blobs to database process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_BlobsToDBMove extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$blob = qa_db_get_next_blob_on_disk($this->state->next);
if (!isset($blob)) {
$this->state->transition('doblobstodb_complete');
return false;
}
require_once QA_INCLUDE_DIR . 'app/blobs.php';
require_once QA_INCLUDE_DIR . 'db/blobs.php';
$content = qa_read_blob_file($blob['blobid'], $blob['format']);
qa_db_blob_set_content($blob['blobid'], $content);
qa_delete_blob_file($blob['blobid'], $blob['format']);
$this->state->next = 1 + $blob['blobid'];
$this->state->done++;
return true;
}
public function getMessage()
{
return $this->progressLang('admin/blobs_move_moved', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/BlobsToDisk.php
Description: Recalc class for the start of the blobs to disk process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_BlobsToDisk extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('doblobstodisk_move');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/BlobsToDiskMove.php
Description: Recalc processing class for the blobs to disk process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_BlobsToDiskMove extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$blob = qa_db_get_next_blob_in_db($this->state->next);
if (!isset($blob)) {
$this->state->transition('doblobstodisk_complete');
return false;
}
require_once QA_INCLUDE_DIR . 'app/blobs.php';
require_once QA_INCLUDE_DIR . 'db/blobs.php';
if (qa_write_blob_file($blob['blobid'], $blob['content'], $blob['format'])) {
qa_db_blob_set_content($blob['blobid'], null);
}
$this->state->next = 1 + $blob['blobid'];
$this->state->done++;
return true;
}
public function getMessage()
{
return $this->progressLang('admin/blobs_move_moved', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/CacheClear.php
Description: Recalc class for the start of the cache clear process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_CacheClear extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('docacheclear_process');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/CacheClearComplete.php
Description: Recalc class for the end of the cache clear process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_CacheClearComplete extends Q2A_Recalc_AbstractFinalStep
{
public function getMessage()
{
return qa_lang('admin/caching_delete_complete');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/CacheClearProcess.php
Description: Recalc processing class for the cache clear process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_CacheClearProcess extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$cacheDriver = Q2A_Storage_CacheFactory::getCacheDriver();
$cacheStats = $cacheDriver->getStats();
$limit = min($cacheStats['files'], 20);
if (!($cacheStats['files'] > 0 && $this->state->next <= $this->state->length)) {
$this->state->transition('docacheclear_complete');
return false;
}
$deleted = $cacheDriver->clear($limit, $this->state->next, ($this->state->operation === 'docachetrim_process'));
$this->state->done += $deleted;
$this->state->next += $limit - $deleted; // skip files that weren't deleted on next iteration
return true;
}
public function getMessage()
{
return $this->progressLang('admin/caching_delete_progress', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/CacheTrim.php
Description: Recalc class for the start of the cache trim process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_CacheTrim extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('docachetrim_process');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/CacherTrimProcess.php
Description: Recalc processing class for the cache trim process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_CacheTrimProcess extends Q2A_Recalc_CacheClear_Process
{
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/DeleteHidden.php
Description: Recalc class for the start of the delete hidden process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_DeleteHidden extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('dodeletehidden_comments');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/DeleteHiddenAnswers.php
Description: Recalc processing class for the delete hidden process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_DeleteHiddenAnswers extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$posts = qa_db_posts_get_for_deleting('A', $this->state->next, 1);
if (!count($posts)) {
$this->state->transition('dodeletehidden_questions');
return false;
}
require_once QA_INCLUDE_DIR . 'app/posts.php';
$postid = $posts[0];
qa_post_delete($postid);
$this->state->next = 1 + $postid;
$this->state->done++;
return true;
}
public function getMessage()
{
return $this->progressLang('admin/hidden_answers_deleted', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/DeleteHiddenComments.php
Description: Recalc processing class for the delete hidden process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_DeleteHiddenComments extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$posts = qa_db_posts_get_for_deleting('C', $this->state->next, 1);
if (!count($posts)) {
$this->state->transition('dodeletehidden_answers');
return false;
}
require_once QA_INCLUDE_DIR . 'app/posts.php';
$postid = $posts[0];
qa_post_delete($postid);
$this->state->next = 1 + $postid;
$this->state->done++;
return true;
}
public function getMessage()
{
return $this->progressLang('admin/hidden_commenrs_deleted', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/DeleteHiddenComplete.php
Description: Recalc class for the end of the delete hidden process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_DeleteHiddenComplete extends Q2A_Recalc_AbstractFinalStep
{
public function getMessage()
{
return qa_lang('admin/delete_hidden_complete');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/DeleteHiddenQuestions.php
Description: Recalc processing class for the delete hidden process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_DeleteHiddenQuestions extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$posts = qa_db_posts_get_for_deleting('Q', $this->state->next, 1);
if (!count($posts)) {
$this->state->transition('dodeletehidden_complete');
return false;
}
require_once QA_INCLUDE_DIR . 'app/posts.php';
$postid = $posts[0];
qa_post_delete($postid);
$this->state->next = 1 + $postid;
$this->state->done++;
return true;
}
public function getMessage()
{
return $this->progressLang('admin/hidden_questions_deleted', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcCategories.php
Description: Recalc class for the start of the recalc categories process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcCategories extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('dorecalccategories_postcount');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcCategoriesBackPaths.php
Description: Recalc processing class for the recalc categories process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcCategoriesBackPaths extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$categoryids = qa_db_categories_get_for_recalcs($this->state->next, 10);
if (!count($categoryids)) {
$this->state->transition('dorecalccategories_complete');
return false;
}
$lastcategoryid = max($categoryids);
qa_db_categories_recalc_backpaths($this->state->next, $lastcategoryid);
$this->state->next = 1 + $lastcategoryid;
$this->state->done += count($categoryids);
return true;
}
public function getMessage()
{
return $this->progressLang('admin/recalc_categories_backpaths', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcCategoriesComplete.php
Description: Recalc class for the end of the recalc categories process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcCategoriesComplete extends Q2A_Recalc_AbstractFinalStep
{
public function getMessage()
{
return qa_lang('admin/recalc_categories_complete');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcCategoriesPostCount.php
Description: Recalc processing class for the recalc categories process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcCategoriesPostCount extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
qa_db_acount_update();
qa_db_ccount_update();
$this->state->transition('dorecalccategories_postupdate');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcCategoriesPostUpdate.php
Description: Recalc processing class for the recalc categories process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcCategoriesPostUpdate extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$postids = qa_db_posts_get_for_recategorizing($this->state->next, 100);
if (!count($postids)) {
$this->state->transition('dorecalccategories_recount');
return false;
}
$lastpostid = max($postids);
qa_db_posts_recalc_categoryid($this->state->next, $lastpostid);
qa_db_posts_calc_category_path($this->state->next, $lastpostid);
$this->state->next = 1 + $lastpostid;
$this->state->done += count($postids);
return true;
}
public function getMessage()
{
return $this->progressLang('admin/recalc_categories_updated', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcCategoriesRecount.php
Description: Recalc processing class for the recalc categories process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcCategoriesRecount extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$categoryids = qa_db_categories_get_for_recalcs($this->state->next, 10);
if (!count($categoryids)) {
$this->state->transition('dorecalccategories_backpaths');
return false;
}
$lastcategoryid = max($categoryids);
foreach ($categoryids as $categoryid) {
qa_db_ifcategory_qcount_update($categoryid);
}
$this->state->next = 1 + $lastcategoryid;
$this->state->done += count($categoryids);
return true;
}
public function getMessage()
{
return $this->progressLang('admin/recalc_categories_recounting', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcPoints.php
Description: Main recalculation class.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
/*
A full list of redundant (non-normal) information in the database that can be recalculated:
Recalculated in doreindexcontent:
================================
^titlewords (all): index of words in titles of posts
^contentwords (all): index of words in content of posts
^tagwords (all): index of words in tags of posts (a tag can contain multiple words)
^posttags (all): index tags of posts
^words (all): list of words used for indexes
^options (title=cache_*): cached values for various things (e.g. counting questions)
Recalculated in dorecountposts:
==============================
^posts (upvotes, downvotes, netvotes, hotness, acount, amaxvotes, flagcount): number of votes, hotness, answers, answer votes, flags
Recalculated in dorecalcpoints:
===============================
^userpoints (all except bonus): points calculation for all users
^options (title=cache_userpointscount):
Recalculated in dorecalccategories:
===================================
^posts (categoryid): assign to answers and comments based on their antecedent question
^posts (catidpath1, catidpath2, catidpath3): hierarchical path to category ids (requires QA_CATEGORY_DEPTH=4)
^categories (qcount): number of (visible) questions in each category
^categories (backpath): full (backwards) path of slugs to that category
Recalculated in dorebuildupdates:
=================================
^sharedevents (all): per-entity event streams (see big comment in /qa-include/db/favorites.php)
^userevents (all): per-subscriber event streams
[but these are not entirely redundant since they can contain historical information no longer in ^posts]
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
require_once QA_INCLUDE_DIR . 'db/recalc.php';
require_once QA_INCLUDE_DIR . 'db/post-create.php';
require_once QA_INCLUDE_DIR . 'db/points.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'db/admin.php';
require_once QA_INCLUDE_DIR . 'db/users.php';
require_once QA_INCLUDE_DIR . 'app/options.php';
require_once QA_INCLUDE_DIR . 'app/post-create.php';
require_once QA_INCLUDE_DIR . 'app/post-update.php';
class Q2A_Recalc_RecalcMain
{
protected $state;
/**
* Initialize the counts of resource usage.
*/
public function __construct($state)
{
$this->state = new Q2A_Recalc_State($state);
}
public function getState()
{
return $this->state->getState();
}
public function performStep()
{
$step = Q2A_Recalc_AbstractStep::factory($this->state);
if (!$step || $step->isFinalStep()) {
$this->state->setState();
return false;
}
$continue = $step->doStep();
if ($continue) {
$this->state->updateState();
}
return $continue && !$this->state->allDone();
}
/**
* Return a string which gives a user-viewable version of $state
* @return string
*/
public function getMessage()
{
$step = Q2A_Recalc_AbstractStep::factory($this->state);
return $step ? $step->getMessage() : '';
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcPoints.php
Description: Recalc class for the start of the recalc points process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcPoints extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('dorecalcpoints_usercount');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcPointsComplete.php
Description: Recalc class for the end of the recalc points process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcPointsComplete extends Q2A_Recalc_AbstractFinalStep
{
public function getMessage()
{
return qa_lang('admin/recalc_points_complete');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcPointsRecalc.php
Description: Recalc processing class for the recalc points process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcPointsRecalc extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$default_recalccount = 10;
$userids = qa_db_users_get_for_recalc_points($this->state->next, $default_recalccount + 1); // get one extra so we know where to start from next
$gotcount = count($userids);
$recalccount = min($default_recalccount, $gotcount); // can't recalc more than we got
if ($recalccount > 0) {
$lastuserid = $userids[$recalccount - 1];
qa_db_users_recalc_points($this->state->next, $lastuserid);
$this->state->done += $recalccount;
} else {
$lastuserid = $this->state->next; // for truncation
}
if ($gotcount > $recalccount) { // more left to do
$this->state->next = $userids[$recalccount]; // start next round at first one not recalculated
return true;
} else {
qa_db_truncate_userpoints($lastuserid);
qa_db_userpointscount_update(); // quick so just do it here
$this->state->transition('dorecalcpoints_complete');
return false;
}
}
public function getMessage()
{
return $this->progressLang('admin/recalc_points_recalced', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecalcPointsUserCount.php
Description: Recalc processing class for the recalc points process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecalcPointsUserCount extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
qa_db_userpointscount_update(); // for progress update - not necessarily accurate
qa_db_uapprovecount_update(); // needs to be somewhere and this is the most appropriate place
$this->state->transition('dorecalcpoints_recalc');
return false;
}
public function getMessage()
{
return qa_lang('admin/recalc_points_usercount');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecountPosts.php
Description: Recalc class for the start of the recount posts process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecountPosts extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('dorecountposts_postcount');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecountPostsACount.php
Description: Recalc processing class for the recount posts process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecountPostsACount extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$postids = qa_db_posts_get_for_recounting($this->state->next, 1000);
if (!count($postids)) {
qa_db_unupaqcount_update();
$this->state->transition('dorecountposts_complete');
return false;
}
$lastpostid = max($postids);
qa_db_posts_answers_recount($this->state->next, $lastpostid);
$this->state->next = 1 + $lastpostid;
$this->state->done += count($postids);
return true;
}
public function getMessage()
{
return $this->progressLang('admin/recount_posts_as_recounted', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecountPostsComplete.php
Description: Recalc class for the end of the recount posts process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecountPostsComplete extends Q2A_Recalc_AbstractFinalStep
{
public function getMessage()
{
return qa_lang('admin/recount_posts_complete');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecountPostsPostCount.php
Description: Recalc processing class for the recount posts process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecountPostsPostCount extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
qa_db_qcount_update();
qa_db_acount_update();
qa_db_ccount_update();
qa_db_unaqcount_update();
qa_db_unselqcount_update();
$this->state->transition('dorecountposts_votecount');
return false;
}
public function getMessage()
{
return qa_lang('admin/recalc_posts_count');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RecountPostsVoteCount.php
Description: Recalc processing class for the recount posts process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RecountPostsVoteCount extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$postids = qa_db_posts_get_for_recounting($this->state->next, 1000);
if (!count($postids)) {
$this->state->transition('dorecountposts_acount');
return false;
}
$lastpostid = max($postids);
qa_db_posts_votes_recount($this->state->next, $lastpostid);
$this->state->next = 1 + $lastpostid;
$this->state->done += count($postids);
return true;
}
public function getMessage()
{
return $this->progressLang('admin/recount_posts_votes_recounted', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RefillEvents.php
Description: Recalc class for the start of the refill events process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RefillEvents extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('dorefillevents_qcount');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RefillEventsComplete.php
Description: Recalc class for the end of the refill events process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RefillEventsComplete extends Q2A_Recalc_AbstractFinalStep
{
public function getMessage()
{
return qa_lang('admin/refill_events_complete');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RefillEventsQCount.php
Description: Recalc processing class for the refill events process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_RefillEventsQCount extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
qa_db_qcount_update();
$this->state->transition('dorefillevents_refill');
return false;
}
public function getMessage()
{
return qa_lang('admin/recalc_posts_count');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/RefillEventsRefill.php
Description: Recalc processing class for the refill events process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
require_once QA_INCLUDE_DIR . 'app/events.php';
require_once QA_INCLUDE_DIR . 'app/updates.php';
require_once QA_INCLUDE_DIR . 'util/sort.php';
class Q2A_Recalc_RefillEventsRefill extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$questionids = qa_db_qs_get_for_event_refilling($this->state->next, 1);
if (!count($questionids)) {
$this->state->transition('dorefillevents_complete');
return false;
}
$lastquestionid = max($questionids);
foreach ($questionids as $questionid) {
// Retrieve all posts relating to this question
list($question, $childposts, $achildposts) = qa_db_select_with_pending(
qa_db_full_post_selectspec(null, $questionid),
qa_db_full_child_posts_selectspec(null, $questionid),
qa_db_full_a_child_posts_selectspec(null, $questionid)
);
// Merge all posts while preserving keys as postids
$posts = array($questionid => $question);
foreach ($childposts as $postid => $post) {
$posts[$postid] = $post;
}
foreach ($achildposts as $postid => $post) {
$posts[$postid] = $post;
}
// Creation and editing of each post
foreach ($posts as $postid => $post) {
$followonq = ($post['basetype'] == 'Q') && ($postid != $questionid);
if ($followonq) {
$updatetype = QA_UPDATE_FOLLOWS;
} elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'Q') {
$updatetype = QA_UPDATE_C_FOR_Q;
} elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'A') {
$updatetype = QA_UPDATE_C_FOR_A;
} else {
$updatetype = null;
}
qa_create_event_for_q_user($questionid, $postid, $updatetype, $post['userid'], @$posts[$post['parentid']]['userid'], $post['created']);
if (isset($post['updated']) && !$followonq) {
qa_create_event_for_q_user($questionid, $postid, $post['updatetype'], $post['lastuserid'], $post['userid'], $post['updated']);
}
}
// Tags and categories of question
qa_create_event_for_tags($question['tags'], $questionid, null, $question['userid'], $question['created']);
qa_create_event_for_category($question['categoryid'], $questionid, null, $question['userid'], $question['created']);
// Collect comment threads
$parentidcomments = array();
foreach ($posts as $postid => $post) {
if ($post['basetype'] == 'C') {
$parentidcomments[$post['parentid']][$postid] = $post;
}
}
// For each comment thread, notify all previous comment authors of each comment in the thread (could get slow)
foreach ($parentidcomments as $parentid => $comments) {
$keyuserids = array();
qa_sort_by($comments, 'created');
foreach ($comments as $comment) {
foreach ($keyuserids as $keyuserid => $dummy) {
if ($keyuserid != $comment['userid'] && $keyuserid != @$posts[$parentid]['userid']) {
qa_db_event_create_not_entity($keyuserid, $questionid, $comment['postid'], QA_UPDATE_FOLLOWS, $comment['userid'], $comment['created']);
}
}
if (isset($comment['userid'])) {
$keyuserids[$comment['userid']] = true;
}
}
}
}
$this->state->next = 1 + $lastquestionid;
$this->state->done += count($questionids);
return true;
}
public function getMessage()
{
return $this->progressLang('admin/refill_events_refilled', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/ReindexContent.php
Description: Recalc class for the start of the reindex content process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_ReindexContent extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$this->state->transition('doreindexcontent_pagereindex');
return false;
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/ReindexContentPageReindex.php
Description: Recalc processing class for the reindex content process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_ReindexContentPageReindex extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$pages = qa_db_pages_get_for_reindexing($this->state->next, 10);
if (!count($pages)) {
$this->state->transition('doreindexcontent_postcount');
return false;
}
require_once QA_INCLUDE_DIR . 'app/format.php';
$lastpageid = max(array_keys($pages));
foreach ($pages as $pageid => $page) {
if (!($page['flags'] & QA_PAGE_FLAGS_EXTERNAL)) {
$searchmodules_u = qa_load_modules_with('search', 'unindex_page');
foreach ($searchmodules_u as $searchmodule) {
$searchmodule->unindex_page($pageid);
}
$searchmodules_i = qa_load_modules_with('search', 'index_page');
if (count($searchmodules_i)) {
$indextext = qa_viewer_text($page['content'], 'html');
foreach ($searchmodules_i as $searchmodule) {
$searchmodule->index_page($pageid, $page['tags'], $page['heading'], $page['content'], 'html', $indextext);
}
}
}
}
$this->state->next = 1 + $lastpageid;
$this->state->done += count($pages);
return true;
}
public function getMessage()
{
return $this->progressLang('admin/reindex_pages_reindexed', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/ReindexContentPostCount.php
Description: Recalc processing class for the reindex content process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_ReindexContentPostCount extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
qa_db_qcount_update();
qa_db_acount_update();
qa_db_ccount_update();
$this->state->transition('doreindexcontent_postreindex');
return false;
}
public function getMessage()
{
return qa_lang('admin/recalc_posts_count');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/ReindexContentPostReindex.php
Description: Recalc processing class for the reindex content process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_ReindexContentPostReindex extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$posts = qa_db_posts_get_for_reindexing($this->state->next, 10);
if (!count($posts)) {
qa_db_truncate_indexes($this->state->next);
$this->state->transition('doreindexposts_wordcount');
return false;
}
require_once QA_INCLUDE_DIR . 'app/format.php';
$lastpostid = max(array_keys($posts));
qa_db_prepare_for_reindexing($this->state->next, $lastpostid);
qa_suspend_update_counts();
foreach ($posts as $postid => $post) {
qa_post_unindex($postid);
qa_post_index($postid, $post['type'], $post['questionid'], $post['parentid'], $post['title'], $post['content'],
$post['format'], qa_viewer_text($post['content'], $post['format']), $post['tags'], $post['categoryid']);
}
$this->state->next = 1 + $lastpostid;
$this->state->done += count($posts);
return true;
}
public function getMessage()
{
return $this->progressLang('admin/reindex_posts_reindexed', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/ReindexPostsComplete.php
Description: Recalc class for the end of the reindex posts process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_ReindexPostsComplete extends Q2A_Recalc_AbstractFinalStep
{
public function getMessage()
{
return qa_lang('admin/reindex_posts_complete');
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/ReindexContentWordCount.php
Description: Recalc processing class for the reindex content process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_ReindexPostsWordCount extends Q2A_Recalc_AbstractStep
{
public function doStep()
{
$wordids = qa_db_words_prepare_for_recounting($this->state->next, 1000);
if (!count($wordids)) {
qa_db_tagcount_update(); // this is quick so just do it here
$this->state->transition('doreindexposts_complete');
return false;
}
$lastwordid = max($wordids);
qa_db_words_recount($this->state->next, $lastwordid);
$this->state->next = 1 + $lastwordid;
$this->state->done += count($wordids);
return true;
}
public function getMessage()
{
return $this->progressLang('admin/reindex_posts_wordcounted', $this->state->done, $this->state->length);
}
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Recalc/State.php
Description: Class holding state of the current recalculation process.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class Q2A_Recalc_State
{
public $state;
public $operation;
public $length;
public $next;
public $done;
private $classes = array(
'doreindexcontent' => 'ReindexContent',
'doreindexcontent_pagereindex' => 'ReindexContentPageReindex',
'doreindexcontent_postcount' => 'ReindexContentPostCount',
'doreindexcontent_postreindex' => 'ReindexContentPostReindex',
'doreindexposts_wordcount' => 'ReindexPostsWordCount',
'dorecountposts' => 'RecountPosts',
'dorecountposts_postcount' => 'RecountPostsPostCount',
'dorecountposts_votecount' => 'RecountPostsVoteCount',
'dorecountposts_acount' => 'RecountPostsAcount',
'dorecalcpoints' => 'RecalcPoints',
'dorecalcpoints_usercount' => 'RecalcPointsUserCount',
'dorecalcpoints_recalc' => 'RecalcPointsRecalc',
'dorefillevents' => 'RefillEvents',
'dorefillevents_qcount' => 'RefillEventsQcount',
'dorefillevents_refill' => 'RefillEventsRefill',
'dorecalccategories' => 'RecalcCategories',
'dorecalccategories_postcount' => 'RecalcCategoriesPostCount',
'dorecalccategories_postupdate' => 'RecalcCategoriesPostUpdate',
'dorecalccategories_recount' => 'RecalcCategoriesRecount',
'dorecalccategories_backpaths' => 'RecalcCategoriesBackPaths',
'dodeletehidden' => 'DeleteHidden',
'dodeletehidden_comments' => 'DeleteHiddenComments',
'dodeletehidden_answers' => 'DeleteHiddenAnswers',
'dodeletehidden_questions' => 'DeletehiddenQuestions',
'doblobstodisk' => 'BlobsToDisk',
'doblobstodisk_move' => 'BlobsToDiskMove',
'doblobstodb' => 'BlobsToDB',
'doblobstodb_move' => 'BlobsToDBMove',
'docachetrim' => 'CacheTrim',
'docacheclear' => 'CacheClear',
'docachetrim_process' => 'CacheClearProcess',
'docacheclear_process' => 'CacheClearProcess',
'doreindexposts_complete' => 'ReindexPostsComplete',
'dorecountposts_complete' => 'RecountPostsComplete',
'dorecalcpoints_complete' => 'RecalcPointsComplete',
'dorefillevents_complete' => 'RefillEventsComplete',
'dorecalccategories_complete' => 'RecalcCategoriesComplete',
'dodeletehidden_complete' => 'DeleteHiddenComplete',
'doblobstodisk_complete' => 'BlobsMoveComplete',
'doblobstodb_complete' => 'BlobsMoveComplete',
'docacheclear_complete' => 'CacheClearComplete',
);
/**
* Initialize the counts of resource usage.
*/
public function __construct($state)
{
$this->setState($state);
}
public function getState()
{
return $this->state;
}
public function setState($state = '')
{
$this->state = $state;
list($this->operation, $this->length, $this->next, $this->done) = explode("\t", $state . "\t\t\t\t");
}
public function updateState()
{
$this->state = $this->operation . "\t" . $this->length . "\t" . $this->next . "\t" . $this->done;
}
public function getOperationClass()
{
return isset($this->classes[$this->operation]) ? 'Q2A_Recalc_' . $this->classes[$this->operation] : null;
}
public function allDone()
{
return $this->done >= $this->length;
}
/**
* Change the $state to represent the beginning of a new $operation
* @param $newOperation
*/
public function transition($newOperation)
{
$this->operation = $newOperation;
$this->length = $this->stageLength();
$this->next = (QA_FINAL_EXTERNAL_USERS && ($newOperation == 'dorecalcpoints_recalc')) ? '' : 0;
$this->done = 0;
$this->updateState();
}
/**
* Return how many steps there will be in recalculation $operation
* @return int
*/
private function stageLength()
{
switch ($this->operation) {
case 'doreindexcontent_pagereindex':
return qa_db_count_pages();
case 'doreindexcontent_postreindex':
return qa_opt('cache_qcount') + qa_opt('cache_acount') + qa_opt('cache_ccount');
case 'doreindexposts_wordcount':
return qa_db_count_words();
case 'dorecalcpoints_recalc':
return qa_opt('cache_userpointscount');
case 'dorecountposts_votecount':
case 'dorecountposts_acount':
case 'dorecalccategories_postupdate':
return qa_db_count_posts();
case 'dorefillevents_refill':
return qa_opt('cache_qcount') + qa_db_count_posts('Q_HIDDEN');
case 'dorecalccategories_recount':
case 'dorecalccategories_backpaths':
return qa_db_count_categories();
case 'dodeletehidden_comments':
return count(qa_db_posts_get_for_deleting('C'));
case 'dodeletehidden_answers':
return count(qa_db_posts_get_for_deleting('A'));
case 'dodeletehidden_questions':
return count(qa_db_posts_get_for_deleting('Q'));
case 'doblobstodisk_move':
return qa_db_count_blobs_in_db();
case 'doblobstodb_move':
return qa_db_count_blobs_on_disk();
case 'docachetrim_process':
case 'docacheclear_process':
$cacheDriver = Q2A_Storage_CacheFactory::getCacheDriver();
$cacheStats = $cacheDriver->getStats();
return $cacheStats['files'];
}
return 0;
}
}
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
*/ */
require_once QA_INCLUDE_DIR . 'app/users.php'; require_once QA_INCLUDE_DIR . 'app/users.php';
require_once QA_INCLUDE_DIR . 'app/recalc.php';
if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) { if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
...@@ -29,14 +28,16 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) { ...@@ -29,14 +28,16 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
$message = qa_lang('misc/form_security_reload'); $message = qa_lang('misc/form_security_reload');
} else { } else {
$state = qa_post_text('state'); $recalc = new Q2A_Recalc_RecalcMain(qa_post_text('state'));
$stoptime = time() + 3; $stoptime = time() + 3;
while (qa_recalc_perform_step($state) && time() < $stoptime) { while ($recalc->performStep() && time() < $stoptime) {
// wait // wait
} }
$message = qa_recalc_get_message($state); $message = $recalc->getMessage();
$state = $recalc->getState();
} }
} else { } else {
......
...@@ -60,6 +60,10 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly ...@@ -60,6 +60,10 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly
exit; exit;
} }
if (defined('QA_DEBUG_PERFORMANCE') && QA_DEBUG_PERFORMANCE) {
trigger_error('Included file ' . basename(__FILE__) . ' is deprecated');
}
require_once QA_INCLUDE_DIR . 'db/recalc.php'; require_once QA_INCLUDE_DIR . 'db/recalc.php';
require_once QA_INCLUDE_DIR . 'db/post-create.php'; require_once QA_INCLUDE_DIR . 'db/post-create.php';
require_once QA_INCLUDE_DIR . 'db/points.php'; require_once QA_INCLUDE_DIR . 'db/points.php';
......
...@@ -78,7 +78,7 @@ function qa_db_table_definitions() ...@@ -78,7 +78,7 @@ function qa_db_table_definitions()
* In MySQL versions prior to 5.0.3, VARCHAR(x) columns will be silently converted to TEXT where x>255 * In MySQL versions prior to 5.0.3, VARCHAR(x) columns will be silently converted to TEXT where x>255
* See box at top of /qa-include/app/recalc.php for a list of redundant (non-normal) information in the database * See box at top of /qa-include/Q2A/Recalc/RecalcMain.php for a list of redundant (non-normal) information in the database
* Starting in version 1.2, we explicitly name keys and foreign key constraints, instead of allowing MySQL * Starting in version 1.2, we explicitly name keys and foreign key constraints, instead of allowing MySQL
to name these by default. Our chosen names match the default names that MySQL would have assigned, and to name these by default. Our chosen names match the default names that MySQL would have assigned, and
...@@ -769,8 +769,6 @@ function qa_db_default_userfields_sql() ...@@ -769,8 +769,6 @@ function qa_db_default_userfields_sql()
*/ */
function qa_db_upgrade_tables() function qa_db_upgrade_tables()
{ {
require_once QA_INCLUDE_DIR . 'app/recalc.php';
$definitions = qa_db_table_definitions(); $definitions = qa_db_table_definitions();
$keyrecalc = array(); $keyrecalc = array();
...@@ -1613,16 +1611,17 @@ function qa_db_upgrade_tables() ...@@ -1613,16 +1611,17 @@ function qa_db_upgrade_tables()
// Perform any necessary recalculations, as determined by upgrade steps // Perform any necessary recalculations, as determined by upgrade steps
foreach ($keyrecalc as $state => $dummy) { foreach (array_keys($keyrecalc) as $state) {
while ($state) { $recalc = new Q2A_Recalc_RecalcMain($state);
while ($recalc->getState()) {
set_time_limit(60); set_time_limit(60);
$stoptime = time() + 2; $stoptime = time() + 2;
while (qa_recalc_perform_step($state) && (time() < $stoptime)) while ($recalc->performStep() && (time() < $stoptime))
; ;
qa_db_upgrade_progress(qa_recalc_get_message($state)); qa_db_upgrade_progress($recalc->getMmessage());
} }
} }
} }
......
...@@ -25,8 +25,6 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly ...@@ -25,8 +25,6 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly
} }
require_once QA_INCLUDE_DIR . 'app/admin.php'; require_once QA_INCLUDE_DIR . 'app/admin.php';
require_once QA_INCLUDE_DIR . 'app/recalc.php';
// Check we have administrative privileges // Check we have administrative privileges
...@@ -71,15 +69,16 @@ if ($recalcnow) { ...@@ -71,15 +69,16 @@ if ($recalcnow) {
<?php <?php
while ($state) { $recalc = new Q2A_Recalc_RecalcMain($state);
while ($recalc->getState()) {
set_time_limit(60); set_time_limit(60);
$stoptime = time() + 2; // run in lumps of two seconds... $stoptime = time() + 2; // run in lumps of two seconds...
while (qa_recalc_perform_step($state) && time() < $stoptime) while ($recalc->performStep() && time() < $stoptime)
; ;
echo qa_html(qa_recalc_get_message($state)) . str_repeat(' ', 1024) . "<br>\n"; echo qa_html($recalc->getMessage) . str_repeat(' ', 1024) . "<br>\n";
flush(); flush();
sleep(1); // ... then rest for one sleep(1); // ... then rest for one
......
...@@ -12,4 +12,4 @@ if (defined('QA_DEBUG_PERFORMANCE') && QA_DEBUG_PERFORMANCE) { ...@@ -12,4 +12,4 @@ if (defined('QA_DEBUG_PERFORMANCE') && QA_DEBUG_PERFORMANCE) {
trigger_error('Included file ' . basename(__FILE__) . ' is deprecated'); trigger_error('Included file ' . basename(__FILE__) . ' is deprecated');
} }
require_once QA_INCLUDE_DIR.'app/recalc.php'; require_once QA_INCLUDE_DIR.'app/recalc.php'; //...although that's also deprecated now.
...@@ -37,4 +37,10 @@ ...@@ -37,4 +37,10 @@
</properties> </properties>
</rule> </rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
</ruleset> </ruleset>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment