Commit caeb200c by Simon Champion

Update all state properties correctly.

parent 4570e5cf
...@@ -112,7 +112,7 @@ class Q2A_App_Recalc_Main ...@@ -112,7 +112,7 @@ class Q2A_App_Recalc_Main
private function DoReindexContent_PageReindex() private function DoReindexContent_PageReindex()
{ {
$pages = qa_db_pages_get_for_reindexing($this->next, 10); $pages = qa_db_pages_get_for_reindexing($this->state->next, 10);
if (!count($pages)) { if (!count($pages)) {
$this->state->transition('doreindexcontent_postcount'); $this->state->transition('doreindexcontent_postcount');
...@@ -141,8 +141,8 @@ class Q2A_App_Recalc_Main ...@@ -141,8 +141,8 @@ class Q2A_App_Recalc_Main
} }
} }
$this->next = 1 + $lastpageid; $this->state->next = 1 + $lastpageid;
$this->done += count($pages); $this->state->done += count($pages);
return true; return true;
} }
...@@ -158,10 +158,10 @@ class Q2A_App_Recalc_Main ...@@ -158,10 +158,10 @@ class Q2A_App_Recalc_Main
private function DoReindexContent_PostReindex() private function DoReindexContent_PostReindex()
{ {
$posts = qa_db_posts_get_for_reindexing($this->next, 10); $posts = qa_db_posts_get_for_reindexing($this->state->next, 10);
if (!count($posts)) { if (!count($posts)) {
qa_db_truncate_indexes($this->next); qa_db_truncate_indexes($this->state->next);
$this->state->transition('doreindexposts_wordcount'); $this->state->transition('doreindexposts_wordcount');
return false; return false;
} }
...@@ -170,7 +170,7 @@ class Q2A_App_Recalc_Main ...@@ -170,7 +170,7 @@ class Q2A_App_Recalc_Main
$lastpostid = max(array_keys($posts)); $lastpostid = max(array_keys($posts));
qa_db_prepare_for_reindexing($this->next, $lastpostid); qa_db_prepare_for_reindexing($this->state->next, $lastpostid);
qa_suspend_update_counts(); qa_suspend_update_counts();
foreach ($posts as $postid => $post) { foreach ($posts as $postid => $post) {
...@@ -179,14 +179,14 @@ class Q2A_App_Recalc_Main ...@@ -179,14 +179,14 @@ class Q2A_App_Recalc_Main
$post['format'], qa_viewer_text($post['content'], $post['format']), $post['tags'], $post['categoryid']); $post['format'], qa_viewer_text($post['content'], $post['format']), $post['tags'], $post['categoryid']);
} }
$this->next = 1 + $lastpostid; $this->state->next = 1 + $lastpostid;
$this->done += count($posts); $this->state->done += count($posts);
return true; return true;
} }
private function DoReindexPosts_WordCount() private function DoReindexPosts_WordCount()
{ {
$wordids = qa_db_words_prepare_for_recounting($this->next, 1000); $wordids = qa_db_words_prepare_for_recounting($this->state->next, 1000);
if (!count($wordids)) { if (!count($wordids)) {
qa_db_tagcount_update(); // this is quick so just do it here qa_db_tagcount_update(); // this is quick so just do it here
...@@ -196,10 +196,10 @@ class Q2A_App_Recalc_Main ...@@ -196,10 +196,10 @@ class Q2A_App_Recalc_Main
$lastwordid = max($wordids); $lastwordid = max($wordids);
qa_db_words_recount($this->next, $lastwordid); qa_db_words_recount($this->state->next, $lastwordid);
$this->next = 1 + $lastwordid; $this->state->next = 1 + $lastwordid;
$this->done += count($wordids); $this->state->done += count($wordids);
return true; return true;
} }
...@@ -223,7 +223,7 @@ class Q2A_App_Recalc_Main ...@@ -223,7 +223,7 @@ class Q2A_App_Recalc_Main
private function DoRecountPosts_VoteCount() private function DoRecountPosts_VoteCount()
{ {
$postids = qa_db_posts_get_for_recounting($this->next, 1000); $postids = qa_db_posts_get_for_recounting($this->state->next, 1000);
if (!count($postids)) { if (!count($postids)) {
$this->state->transition('dorecountposts_acount'); $this->state->transition('dorecountposts_acount');
...@@ -232,16 +232,16 @@ class Q2A_App_Recalc_Main ...@@ -232,16 +232,16 @@ class Q2A_App_Recalc_Main
$lastpostid = max($postids); $lastpostid = max($postids);
qa_db_posts_votes_recount($this->next, $lastpostid); qa_db_posts_votes_recount($this->state->next, $lastpostid);
$this->next = 1 + $lastpostid; $this->state->next = 1 + $lastpostid;
$this->done += count($postids); $this->state->done += count($postids);
return true; return true;
} }
private function DoRecountPosts_Acount() private function DoRecountPosts_Acount()
{ {
$postids = qa_db_posts_get_for_recounting($this->next, 1000); $postids = qa_db_posts_get_for_recounting($this->state->next, 1000);
if (count($postids)) { if (count($postids)) {
qa_db_unupaqcount_update(); qa_db_unupaqcount_update();
...@@ -251,10 +251,10 @@ class Q2A_App_Recalc_Main ...@@ -251,10 +251,10 @@ class Q2A_App_Recalc_Main
$lastpostid = max($postids); $lastpostid = max($postids);
qa_db_posts_answers_recount($this->next, $lastpostid); qa_db_posts_answers_recount($this->state->next, $lastpostid);
$this->next = 1 + $lastpostid; $this->state->next = 1 + $lastpostid;
$this->done += count($postids); $this->state->done += count($postids);
return true; return true;
} }
...@@ -275,21 +275,21 @@ class Q2A_App_Recalc_Main ...@@ -275,21 +275,21 @@ class Q2A_App_Recalc_Main
private function DoRecalcPoints_Recalc() private function DoRecalcPoints_Recalc()
{ {
$default_recalccount = 10; $default_recalccount = 10;
$userids = qa_db_users_get_for_recalc_points($this->next, $default_recalccount + 1); // get one extra so we know where to start from next $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); $gotcount = count($userids);
$recalccount = min($default_recalccount, $gotcount); // can't recalc more than we got $recalccount = min($default_recalccount, $gotcount); // can't recalc more than we got
if ($recalccount > 0) { if ($recalccount > 0) {
$lastuserid = $userids[$recalccount - 1]; $lastuserid = $userids[$recalccount - 1];
qa_db_users_recalc_points($this->next, $lastuserid); qa_db_users_recalc_points($this->state->next, $lastuserid);
$this->done += $recalccount; $this->state->done += $recalccount;
} else { } else {
$lastuserid = $this->next; // for truncation $lastuserid = $this->state->next; // for truncation
} }
if ($gotcount > $recalccount) { // more left to do if ($gotcount > $recalccount) { // more left to do
$this->next = $userids[$recalccount]; // start next round at first one not recalculated $this->state->next = $userids[$recalccount]; // start next round at first one not recalculated
return true; return true;
} else { } else {
qa_db_truncate_userpoints($lastuserid); qa_db_truncate_userpoints($lastuserid);
...@@ -314,7 +314,7 @@ class Q2A_App_Recalc_Main ...@@ -314,7 +314,7 @@ class Q2A_App_Recalc_Main
private function DoRefillEvents_Refill() private function DoRefillEvents_Refill()
{ {
$questionids = qa_db_qs_get_for_event_refilling($this->next, 1); $questionids = qa_db_qs_get_for_event_refilling($this->state->next, 1);
if (!count($questionids)) { if (!count($questionids)) {
$this->state->transition('dorefillevents_complete'); $this->state->transition('dorefillevents_complete');
...@@ -406,8 +406,8 @@ class Q2A_App_Recalc_Main ...@@ -406,8 +406,8 @@ class Q2A_App_Recalc_Main
} }
} }
$this->next = 1 + $lastquestionid; $this->state->next = 1 + $lastquestionid;
$this->done += count($questionids); $this->state->done += count($questionids);
return true; return true;
} }
...@@ -428,7 +428,7 @@ class Q2A_App_Recalc_Main ...@@ -428,7 +428,7 @@ class Q2A_App_Recalc_Main
private function DoRecalcCategories_PostUpdate() private function DoRecalcCategories_PostUpdate()
{ {
$postids = qa_db_posts_get_for_recategorizing($this->next, 100); $postids = qa_db_posts_get_for_recategorizing($this->state->next, 100);
if (!count($postids)) { if (!count($postids)) {
$this->state->transition('dorecalccategories_recount'); $this->state->transition('dorecalccategories_recount');
...@@ -437,17 +437,17 @@ class Q2A_App_Recalc_Main ...@@ -437,17 +437,17 @@ class Q2A_App_Recalc_Main
$lastpostid = max($postids); $lastpostid = max($postids);
qa_db_posts_recalc_categoryid($this->next, $lastpostid); qa_db_posts_recalc_categoryid($this->state->next, $lastpostid);
qa_db_posts_calc_category_path($this->next, $lastpostid); qa_db_posts_calc_category_path($this->state->next, $lastpostid);
$this->next = 1 + $lastpostid; $this->state->next = 1 + $lastpostid;
$this->done += count($postids); $this->state->done += count($postids);
return true; return true;
} }
private function DoRecalcCategories_Recount() private function DoRecalcCategories_Recount()
{ {
$categoryids = qa_db_categories_get_for_recalcs($this->next, 10); $categoryids = qa_db_categories_get_for_recalcs($this->state->next, 10);
if (!count($categoryids)) { if (!count($categoryids)) {
$this->state->transition('dorecalccategories_backpaths'); $this->state->transition('dorecalccategories_backpaths');
...@@ -459,14 +459,14 @@ class Q2A_App_Recalc_Main ...@@ -459,14 +459,14 @@ class Q2A_App_Recalc_Main
qa_db_ifcategory_qcount_update($categoryid); qa_db_ifcategory_qcount_update($categoryid);
} }
$this->next = 1 + $lastcategoryid; $this->state->next = 1 + $lastcategoryid;
$this->done += count($categoryids); $this->state->done += count($categoryids);
return true; return true;
} }
private function DoRecalcCategories_BackPaths() private function DoRecalcCategories_BackPaths()
{ {
$categoryids = qa_db_categories_get_for_recalcs($this->next, 10); $categoryids = qa_db_categories_get_for_recalcs($this->state->next, 10);
if (!count($categoryids)) { if (!count($categoryids)) {
$this->state->transition('dorecalccategories_complete'); $this->state->transition('dorecalccategories_complete');
...@@ -474,10 +474,10 @@ class Q2A_App_Recalc_Main ...@@ -474,10 +474,10 @@ class Q2A_App_Recalc_Main
} }
$lastcategoryid = max($categoryids); $lastcategoryid = max($categoryids);
qa_db_categories_recalc_backpaths($this->next, $lastcategoryid); qa_db_categories_recalc_backpaths($this->state->next, $lastcategoryid);
$this->next = 1 + $lastcategoryid; $this->state->next = 1 + $lastcategoryid;
$this->done += count($categoryids); $this->state->done += count($categoryids);
return true; return true;
} }
...@@ -489,7 +489,7 @@ class Q2A_App_Recalc_Main ...@@ -489,7 +489,7 @@ class Q2A_App_Recalc_Main
private function DoDeleteHidden_Comments() private function DoDeleteHidden_Comments()
{ {
$posts = qa_db_posts_get_for_deleting('C', $this->next, 1); $posts = qa_db_posts_get_for_deleting('C', $this->state->next, 1);
if (!count($posts)) { if (!count($posts)) {
$this->state->transition('dodeletehidden_answers'); $this->state->transition('dodeletehidden_answers');
...@@ -501,14 +501,14 @@ class Q2A_App_Recalc_Main ...@@ -501,14 +501,14 @@ class Q2A_App_Recalc_Main
$postid = $posts[0]; $postid = $posts[0];
qa_post_delete($postid); qa_post_delete($postid);
$this->next = 1 + $postid; $this->state->next = 1 + $postid;
$this->done++; $this->state->done++;
return true; return true;
} }
private function DoDeleteHidden_Answers() private function DoDeleteHidden_Answers()
{ {
$posts = qa_db_posts_get_for_deleting('A', $this->next, 1); $posts = qa_db_posts_get_for_deleting('A', $this->state->next, 1);
if (!count($posts)) { if (!count($posts)) {
$this->state->transition('dodeletehidden_questions'); $this->state->transition('dodeletehidden_questions');
...@@ -520,14 +520,14 @@ class Q2A_App_Recalc_Main ...@@ -520,14 +520,14 @@ class Q2A_App_Recalc_Main
$postid = $posts[0]; $postid = $posts[0];
qa_post_delete($postid); qa_post_delete($postid);
$this->next = 1 + $postid; $this->state->next = 1 + $postid;
$this->done++; $this->state->done++;
return true; return true;
} }
private function Dodeletehidden_questions() private function Dodeletehidden_questions()
{ {
$posts = qa_db_posts_get_for_deleting('Q', $this->next, 1); $posts = qa_db_posts_get_for_deleting('Q', $this->state->next, 1);
if (!count($posts)) { if (!count($posts)) {
$this->state->transition('dodeletehidden_complete'); $this->state->transition('dodeletehidden_complete');
...@@ -539,8 +539,8 @@ class Q2A_App_Recalc_Main ...@@ -539,8 +539,8 @@ class Q2A_App_Recalc_Main
$postid = $posts[0]; $postid = $posts[0];
qa_post_delete($postid); qa_post_delete($postid);
$this->next = 1 + $postid; $this->state->next = 1 + $postid;
$this->done++; $this->state->done++;
return true; return true;
} }
...@@ -552,7 +552,7 @@ class Q2A_App_Recalc_Main ...@@ -552,7 +552,7 @@ class Q2A_App_Recalc_Main
private function DoBlobsToDisk_Move() private function DoBlobsToDisk_Move()
{ {
$blob = qa_db_get_next_blob_in_db($this->next); $blob = qa_db_get_next_blob_in_db($this->state->next);
if (!isset($blob)) { if (!isset($blob)) {
$this->state->transition('doblobstodisk_complete'); $this->state->transition('doblobstodisk_complete');
...@@ -566,8 +566,8 @@ class Q2A_App_Recalc_Main ...@@ -566,8 +566,8 @@ class Q2A_App_Recalc_Main
qa_db_blob_set_content($blob['blobid'], null); qa_db_blob_set_content($blob['blobid'], null);
} }
$this->next = 1 + $blob['blobid']; $this->state->next = 1 + $blob['blobid'];
$this->done++; $this->state->done++;
return true; return true;
} }
...@@ -579,7 +579,7 @@ class Q2A_App_Recalc_Main ...@@ -579,7 +579,7 @@ class Q2A_App_Recalc_Main
private function DoBlobsToDB_Move() private function DoBlobsToDB_Move()
{ {
$blob = qa_db_get_next_blob_on_disk($this->next); $blob = qa_db_get_next_blob_on_disk($this->state->next);
if (!isset($blob)) { if (!isset($blob)) {
$this->state->transition('doblobstodb_complete'); $this->state->transition('doblobstodb_complete');
...@@ -592,8 +592,8 @@ class Q2A_App_Recalc_Main ...@@ -592,8 +592,8 @@ class Q2A_App_Recalc_Main
qa_db_blob_set_content($blob['blobid'], $content); qa_db_blob_set_content($blob['blobid'], $content);
qa_delete_blob_file($blob['blobid'], $blob['format']); qa_delete_blob_file($blob['blobid'], $blob['format']);
$this->next = 1 + $blob['blobid']; $this->state->next = 1 + $blob['blobid'];
$this->done++; $this->state->done++;
return true; return true;
} }
...@@ -620,14 +620,14 @@ class Q2A_App_Recalc_Main ...@@ -620,14 +620,14 @@ class Q2A_App_Recalc_Main
$cacheStats = $cacheDriver->getStats(); $cacheStats = $cacheDriver->getStats();
$limit = min($cacheStats['files'], 20); $limit = min($cacheStats['files'], 20);
if (!($cacheStats['files'] > 0 && $this->next <= $this->length)) { if (!($cacheStats['files'] > 0 && $this->state->next <= $this->state->length)) {
$this->state->transition('docacheclear_complete'); $this->state->transition('docacheclear_complete');
return false; return false;
} }
$deleted = $cacheDriver->clear($limit, $this->next, ($this->state->operation === 'docachetrim_process')); $deleted = $cacheDriver->clear($limit, $this->state->next, ($this->state->operation === 'docachetrim_process'));
$this->done += $deleted; $this->state->done += $deleted;
$this->next += $limit - $deleted; // skip files that weren't deleted on next iteration $this->state->next += $limit - $deleted; // skip files that weren't deleted on next iteration
return true; return true;
} }
...@@ -657,8 +657,8 @@ class Q2A_App_Recalc_Main ...@@ -657,8 +657,8 @@ class Q2A_App_Recalc_Main
{ {
require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'app/format.php';
$this->done = (int) $this->done; $this->state->done = (int) $this->state->done;
$this->length = (int) $this->length; $this->state->length = (int) $this->state->length;
switch ($this->state->operation) { switch ($this->state->operation) {
case 'doreindexcontent_postcount': case 'doreindexcontent_postcount':
...@@ -669,11 +669,11 @@ class Q2A_App_Recalc_Main ...@@ -669,11 +669,11 @@ class Q2A_App_Recalc_Main
break; break;
case 'doreindexcontent_pagereindex': case 'doreindexcontent_pagereindex':
$message = $this->progressLang('admin/reindex_pages_reindexed', $this->done, $this->length); $message = $this->progressLang('admin/reindex_pages_reindexed', $this->state->done, $this->state->length);
break; break;
case 'doreindexcontent_postreindex': case 'doreindexcontent_postreindex':
$message = $this->progressLang('admin/reindex_posts_reindexed', $this->done, $this->length); $message = $this->progressLang('admin/reindex_posts_reindexed', $this->state->done, $this->state->length);
break; break;
case 'doreindexposts_complete': case 'doreindexposts_complete':
...@@ -681,15 +681,15 @@ class Q2A_App_Recalc_Main ...@@ -681,15 +681,15 @@ class Q2A_App_Recalc_Main
break; break;
case 'doreindexposts_wordcount': case 'doreindexposts_wordcount':
$message = $this->progressLang('admin/reindex_posts_wordcounted', $this->done, $this->length); $message = $this->progressLang('admin/reindex_posts_wordcounted', $this->state->done, $this->state->length);
break; break;
case 'dorecountposts_votecount': case 'dorecountposts_votecount':
$message = $this->progressLang('admin/recount_posts_votes_recounted', $this->done, $this->length); $message = $this->progressLang('admin/recount_posts_votes_recounted', $this->state->done, $this->state->length);
break; break;
case 'dorecountposts_acount': case 'dorecountposts_acount':
$message = $this->progressLang('admin/recount_posts_as_recounted', $this->done, $this->length); $message = $this->progressLang('admin/recount_posts_as_recounted', $this->state->done, $this->state->length);
break; break;
case 'dorecountposts_complete': case 'dorecountposts_complete':
...@@ -701,7 +701,7 @@ class Q2A_App_Recalc_Main ...@@ -701,7 +701,7 @@ class Q2A_App_Recalc_Main
break; break;
case 'dorecalcpoints_recalc': case 'dorecalcpoints_recalc':
$message = $this->progressLang('admin/recalc_points_recalced', $this->done, $this->length); $message = $this->progressLang('admin/recalc_points_recalced', $this->state->done, $this->state->length);
break; break;
case 'dorecalcpoints_complete': case 'dorecalcpoints_complete':
...@@ -709,7 +709,7 @@ class Q2A_App_Recalc_Main ...@@ -709,7 +709,7 @@ class Q2A_App_Recalc_Main
break; break;
case 'dorefillevents_refill': case 'dorefillevents_refill':
$message = $this->progressLang('admin/refill_events_refilled', $this->done, $this->length); $message = $this->progressLang('admin/refill_events_refilled', $this->state->done, $this->state->length);
break; break;
case 'dorefillevents_complete': case 'dorefillevents_complete':
...@@ -717,15 +717,15 @@ class Q2A_App_Recalc_Main ...@@ -717,15 +717,15 @@ class Q2A_App_Recalc_Main
break; break;
case 'dorecalccategories_postupdate': case 'dorecalccategories_postupdate':
$message = $this->progressLang('admin/recalc_categories_updated', $this->done, $this->length); $message = $this->progressLang('admin/recalc_categories_updated', $this->state->done, $this->state->length);
break; break;
case 'dorecalccategories_recount': case 'dorecalccategories_recount':
$message = $this->progressLang('admin/recalc_categories_recounting', $this->done, $this->length); $message = $this->progressLang('admin/recalc_categories_recounting', $this->state->done, $this->state->length);
break; break;
case 'dorecalccategories_backpaths': case 'dorecalccategories_backpaths':
$message = $this->progressLang('admin/recalc_categories_backpaths', $this->done, $this->length); $message = $this->progressLang('admin/recalc_categories_backpaths', $this->state->done, $this->state->length);
break; break;
case 'dorecalccategories_complete': case 'dorecalccategories_complete':
...@@ -733,15 +733,15 @@ class Q2A_App_Recalc_Main ...@@ -733,15 +733,15 @@ class Q2A_App_Recalc_Main
break; break;
case 'dodeletehidden_comments': case 'dodeletehidden_comments':
$message = $this->progressLang('admin/hidden_comments_deleted', $this->done, $this->length); $message = $this->progressLang('admin/hidden_comments_deleted', $this->state->done, $this->state->length);
break; break;
case 'dodeletehidden_answers': case 'dodeletehidden_answers':
$message = $this->progressLang('admin/hidden_answers_deleted', $this->done, $this->length); $message = $this->progressLang('admin/hidden_answers_deleted', $this->state->done, $this->state->length);
break; break;
case 'dodeletehidden_questions': case 'dodeletehidden_questions':
$message = $this->progressLang('admin/hidden_questions_deleted', $this->done, $this->length); $message = $this->progressLang('admin/hidden_questions_deleted', $this->state->done, $this->state->length);
break; break;
case 'dodeletehidden_complete': case 'dodeletehidden_complete':
...@@ -750,7 +750,7 @@ class Q2A_App_Recalc_Main ...@@ -750,7 +750,7 @@ class Q2A_App_Recalc_Main
case 'doblobstodisk_move': case 'doblobstodisk_move':
case 'doblobstodb_move': case 'doblobstodb_move':
$message = $this->progressLang('admin/blobs_move_moved', $this->done, $this->length); $message = $this->progressLang('admin/blobs_move_moved', $this->state->done, $this->state->length);
break; break;
case 'doblobstodisk_complete': case 'doblobstodisk_complete':
...@@ -760,7 +760,7 @@ class Q2A_App_Recalc_Main ...@@ -760,7 +760,7 @@ class Q2A_App_Recalc_Main
case 'docachetrim_process': case 'docachetrim_process':
case 'docacheclear_process': case 'docacheclear_process':
$message = $this->progressLang('admin/caching_delete_progress', $this->done, $this->length); $message = $this->progressLang('admin/caching_delete_progress', $this->state->done, $this->state->length);
break; break;
case 'docacheclear_complete': case 'docacheclear_complete':
......
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