Commit 1c21830c by Simon Champion

Refactor the recalc functions into a class.

parent f9f9d3bb
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
require_once QA_INCLUDE_DIR . 'app/users.php'; require_once QA_INCLUDE_DIR . 'app/users.php';
require_once QA_INCLUDE_DIR . 'app/recalc.php'; require_once QA_INCLUDE_DIR . 'app/recalc/RecalcMain.php';
if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) { if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
...@@ -29,14 +29,16 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) { ...@@ -29,14 +29,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_App_Recalc_Main(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/app/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,7 +769,7 @@ function qa_db_default_userfields_sql() ...@@ -769,7 +769,7 @@ function qa_db_default_userfields_sql()
*/ */
function qa_db_upgrade_tables() function qa_db_upgrade_tables()
{ {
require_once QA_INCLUDE_DIR . 'app/recalc.php'; require_once QA_INCLUDE_DIR . 'app/recalc/RecalcMain.php';
$definitions = qa_db_table_definitions(); $definitions = qa_db_table_definitions();
$keyrecalc = array(); $keyrecalc = array();
...@@ -1611,16 +1611,17 @@ function qa_db_upgrade_tables() ...@@ -1611,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_App_Recalc_Main($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,7 +25,7 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly ...@@ -25,7 +25,7 @@ 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'; require_once QA_INCLUDE_DIR . 'app/recalc/RecalcMain.php';
// Check we have administrative privileges // Check we have administrative privileges
...@@ -71,15 +71,16 @@ if ($recalcnow) { ...@@ -71,15 +71,16 @@ if ($recalcnow) {
<?php <?php
while ($state) { $recalc = new Q2A_App_Recalc_Main($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/RecalcMain.php';
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