Merge pull request #3749 from annando/poller-db-update

DB Structure call is now executed directly when it cannot be called via proc_run
This commit is contained in:
Tobias Diekershoff 2017-09-30 19:49:44 +02:00 committed by GitHub
commit 5a77f7c326
5 changed files with 26 additions and 17 deletions

View file

@ -591,7 +591,12 @@ function is_ajax() {
return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
} }
function check_db() { /**
* @brief Function to check if request was an AJAX (xmlhttprequest) request.
*
* @param $via_worker boolean Is the check run via the poller?
*/
function check_db($via_worker) {
$build = get_config('system', 'build'); $build = get_config('system', 'build');
if (!x($build)) { if (!x($build)) {
@ -599,7 +604,10 @@ function check_db() {
$build = DB_UPDATE_VERSION; $build = DB_UPDATE_VERSION;
} }
if ($build != DB_UPDATE_VERSION) { if ($build != DB_UPDATE_VERSION) {
proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php'); // When we cannot execute the database update via the worker, we will do it directly
if (!proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php') && $via_worker) {
update_db(get_app());
}
} }
} }
@ -1024,6 +1032,8 @@ function get_max_import_size() {
* *
* @hooks 'proc_run' * @hooks 'proc_run'
* array $arr * array $arr
*
* @return boolean "false" if proc_run couldn't be executed
*/ */
function proc_run($cmd) { function proc_run($cmd) {
@ -1033,7 +1043,7 @@ function proc_run($cmd) {
$args = array(); $args = array();
if (!count($proc_args)) { if (!count($proc_args)) {
return; return false;
} }
// Preserve the first parameter // Preserve the first parameter
@ -1059,7 +1069,7 @@ function proc_run($cmd) {
call_hooks("proc_run", $arr); call_hooks("proc_run", $arr);
if (!$arr['run_cmd'] || ! count($args)) { if (!$arr['run_cmd'] || ! count($args)) {
return; return true;
} }
$priority = PRIORITY_MEDIUM; $priority = PRIORITY_MEDIUM;
@ -1088,7 +1098,7 @@ function proc_run($cmd) {
// Quit if there was a database error - a precaution for the update process to 3.5.3 // Quit if there was a database error - a precaution for the update process to 3.5.3
if (dba::errorNo() != 0) { if (dba::errorNo() != 0) {
return; return false;
} }
if (!$found) { if (!$found) {
@ -1097,12 +1107,12 @@ function proc_run($cmd) {
// Should we quit and wait for the poller to be called as a cronjob? // Should we quit and wait for the poller to be called as a cronjob?
if ($dont_fork) { if ($dont_fork) {
return; return true;
} }
// If there is a lock then we don't have to check for too much worker // If there is a lock then we don't have to check for too much worker
if (!Lock::set('poller_worker', 0)) { if (!Lock::set('poller_worker', 0)) {
return; return true;
} }
// If there are already enough workers running, don't fork another one // If there are already enough workers running, don't fork another one
@ -1110,13 +1120,15 @@ function proc_run($cmd) {
Lock::remove('poller_worker'); Lock::remove('poller_worker');
if ($quit) { if ($quit) {
return; return true;
} }
// Now call the poller to execute the jobs that we just added to the queue // Now call the poller to execute the jobs that we just added to the queue
$args = array("include/poller.php", "no_cron"); $args = array("include/poller.php", "no_cron");
$a->proc_run($args); $a->proc_run($args);
return true;
} }
function current_theme() { function current_theme() {

View file

@ -32,6 +32,9 @@ function poller_run($argv, $argc){
Config::load(); Config::load();
// Check the database structure and possibly fixes it
check_db(true);
// Quit when in maintenance // Quit when in maintenance
if (Config::get('system', 'maintenance', true)) { if (Config::get('system', 'maintenance', true)) {
return; return;
@ -889,7 +892,7 @@ function poller_run_cron() {
poller_kill_stale_workers(); poller_kill_stale_workers();
} }
if (array_search(__file__,get_included_files())===0){ if (array_search(__file__,get_included_files())===0) {
poller_run($_SERVER["argv"],$_SERVER["argc"]); poller_run($_SERVER["argv"],$_SERVER["argc"]);
poller_unclaim_process(); poller_unclaim_process();

View file

@ -196,7 +196,7 @@ if ($install && $a->module!="view") {
$a->module = 'maintenance'; $a->module = 'maintenance';
} else { } else {
check_url($a); check_url($a);
check_db(); check_db(false);
check_plugins($a); check_plugins($a);
} }

View file

@ -1729,8 +1729,3 @@ function update_1202() {
$r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)", $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
dbesc(ACCOUNT_TYPE_COMMUNITY), dbesc(PAGE_COMMUNITY), dbesc(PAGE_PRVGROUP)); dbesc(ACCOUNT_TYPE_COMMUNITY), dbesc(PAGE_COMMUNITY), dbesc(PAGE_PRVGROUP));
} }
function update_1231() {
// For this special case we have to use the old update routine
$r = q("ALTER TABLE `workerqueue` ADD `done` tinyint(1) NOT NULL DEFAULT 0");
}

View file

@ -29,7 +29,6 @@ echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n";
if ($build != DB_UPDATE_VERSION) { if ($build != DB_UPDATE_VERSION) {
echo "Updating database..."; echo "Updating database...";
check_db($a); update_db($a);
echo "Done\n"; echo "Done\n";
} }