function admin_page_dbsync(&$a) { $o = ''; if ($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') { set_config('database', 'update_' . intval($a->argv[3]), 'success'); $curr = get_config('system', 'build'); if (intval($curr) == intval($a->argv[3])) { set_config('system', 'build', intval($curr) + 1); } info(t('Update has been marked successful') . EOL); goaway($a->get_baseurl(true) . '/admin/dbsync'); } if ($a->argc > 2 and (intval($a->argv[2]) or $a->argv[2] === 'check')) { require_once "include/dbstructure.php"; $retval = update_structure(false, true); if (!$retval) { $o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION) . "<br />"; set_config('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success'); } else { $o .= sprintf(t("Executing of database structure update %s failed with error: %s"), DB_UPDATE_VERSION, $retval) . "<br />"; } if ($a->argv[2] === 'check') { return $o; } } if ($a->argc > 2 && intval($a->argv[2])) { require_once 'update.php'; $func = 'update_' . intval($a->argv[2]); if (function_exists($func)) { $retval = $func(); if ($retval === UPDATE_FAILED) { $o .= sprintf(t("Executing %s failed with error: %s"), $func, $retval); } elseif ($retval === UPDATE_SUCCESS) { $o .= sprintf(t('Update %s was successfully applied.', $func)); set_config('database', $func, 'success'); } else { $o .= sprintf(t('Update %s did not return a status. Unknown if it succeeded.'), $func); } } else { $o .= sprintf(t('There was no additional update function %s that needed to be called.'), $func) . "<br />"; set_config('database', $func, 'success'); } return $o; } $failed = array(); $r = q("select k, v from config where `cat` = 'database' "); if (count($r)) { foreach ($r as $rr) { $upd = intval(substr($rr['k'], 7)); if ($upd < 1139 || $rr['v'] === 'success') { continue; } $failed[] = $upd; } } if (!count($failed)) { $o = replace_macros(get_markup_template('structure_check.tpl'), array('$base' => $a->get_baseurl(true), '$banner' => t('No failed updates.'), '$check' => t('Check database structure'))); } else { $o = replace_macros(get_markup_template('failed_updates.tpl'), array('$base' => $a->get_baseurl(true), '$banner' => t('Failed Updates'), '$desc' => t('This does not include updates prior to 1139, which did not return a status.'), '$mark' => t('Mark success (if update was manually applied)'), '$apply' => t('Attempt to execute this update step automatically'), '$failed' => $failed)); } return $o; }
function load_database($db) { require_once "include/dbstructure.php"; $errors = update_structure(false, true); /* $str = file_get_contents('database.sql'); $arr = explode(';',$str); $errors = false; foreach($arr as $a) { if(strlen(trim($a))) { $r = @$db->q(trim($a)); if(false === $r) { $errors .= t('Errors encountered creating database tables.') . $a . EOL; } } }*/ return $errors; }
function dbstructure_run(&$argv, &$argc) { global $a, $db; if (is_null($a)) { $a = new App(); } if (is_null($db)) { @(include ".htconfig.php"); require_once "include/dba.php"; $db = new dba($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); } if ($argc == 2) { switch ($argv[1]) { case "update": update_structure(true, true); return; case "dumpsql": print_structure(db_definition()); return; } } // print help echo $argv[0] . " <command>\n"; echo "\n"; echo "commands:\n"; echo "update\t\tupdate database schema\n"; echo "dumpsql\t\tdump database schema\n"; return; }
function update_db(&$a) { $build = get_config('system', 'build'); if (!x($build)) { $build = set_config('system', 'build', DB_UPDATE_VERSION); } if ($build != DB_UPDATE_VERSION) { $stored = intval($build); $current = intval(DB_UPDATE_VERSION); if ($stored < $current) { load_config('database'); // We're reporting a different version than what is currently installed. // Run any existing update scripts to bring the database up to current. // make sure that boot.php and update.php are the same release, we might be // updating right this very second and the correct version of the update.php // file may not be here yet. This can happen on a very busy site. if (DB_UPDATE_VERSION == UPDATE_VERSION) { // Compare the current structure with the defined structure $t = get_config('database', 'dbupdate_' . DB_UPDATE_VERSION); if ($t !== false) { return; } set_config('database', 'dbupdate_' . DB_UPDATE_VERSION, time()); // run old update routine (wich could modify the schema and // conflits with new routine) for ($x = $stored; $x < NEW_UPDATE_ROUTINE_VERSION; $x++) { $r = run_update_function($x); if (!$r) { break; } } if ($stored < NEW_UPDATE_ROUTINE_VERSION) { $stored = NEW_UPDATE_ROUTINE_VERSION; } // run new update routine // it update the structure in one call $retval = update_structure(false, true); if ($retval) { update_fail(DB_UPDATE_VERSION, $retval); return; } else { set_config('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success'); } // run any left update_nnnn functions in update.php for ($x = $stored; $x < $current; $x++) { $r = run_update_function($x); if (!$r) { break; } } } } } return; }
function dbstructure_run(&$argv, &$argc) { global $a, $db; if (is_null($a)) { $a = new App(); } if (is_null($db)) { @(include ".htconfig.php"); require_once "include/dba.php"; $db = new dba($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); } update_structure(true, true); }