Changeset 433 for trunk/upgrade.php
- Timestamp:
- 03/31/07 18:45:48 (20 months ago)
- Files:
-
- 1 modified
-
trunk/upgrade.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/upgrade.php
r410 r433 21 21 * Uprade mvblog to the latest version 22 22 */ 23 require_once("common/mvblog_common.php"); 24 $common = new Mvblog_common(); 25 $latest_patch = $common->settings["dbversion"]; 26 /** 27 * Find out what patchfiles we need to commit. 28 */ 29 function get_patchfiles($current_version = 0, $sqltype="mysql") { 30 /* read the db patchfiles into an array */ 31 $patchfiles = array(); 32 if ($dh = opendir(sprintf("upgrades/%s", $sqltype))) { 33 while (false !== ($v = readdir($dh))) { 34 if (!is_dir($v)) { 35 if (substr($v, 0, strpos($v, "to")) >= $current_version) 36 $patchfiles[] = $v; 37 } 38 } 39 } 40 return $patchfiles; 41 } 23 if (array_key_exists("mode", $_REQUEST)) 24 $mode = $_REQUEST["mode"]; 25 else 26 $mode = ""; 42 27 43 /** 44 * Update/create dbversion setting in the database 45 */ 46 function set_latest_version($version=0) { 47 /* check if the field is already in the database */ 48 $sql = "SELECT COUNT(*) FROM settings WHERE settingname = 'dbversion'"; 49 $res = $GLOBALS["common"]->db->query($sql); 50 $res->fetchInto($row); 51 if ($row[0]) { 52 /* update the entry */ 53 $sql = sprintf("UPDATE settings SET settingvalue = '%s' WHERE settingname = 'dbversion'", $version); 54 } else { 55 /* create the entry */ 56 $sql = sprintf("INSERT INTO settings (settingname, settingvalue) VALUES ('dbversion', '%s')", $version); 57 } 58 $res = $GLOBALS["common"]->db->query($sql); 59 } 28 require_once("common/mvblog_upgrade.php"); 29 $updater = new Mvblog_upgrade(); 60 30 61 echo "looking up files for db type <b>".$common->db->phptype."</b> starting at version <b>".$common->settings["dbversion"]."</b>...<br>"; 62 $patches = get_patchfiles($common->settings["dbversion"], $common->db->phptype); 31 if (array_key_exists("dbversion", $updater->settings["dbversion"]) && $updater->settings["dbversion"]) 32 $latest_version = $updater->settings["dbversion"]; 33 else 34 $latest_version = 0; 35 36 echo "looking up files for db type <b>".$updater->db->phptype."</b> starting at version <b>".$latest_version."</b>...<br>"; 37 $patches = $updater->get_patchfiles($mode); 63 38 if (!count($patches)) 64 39 die("nothing to do. Your mvblog is already up-to-date."); 65 40 66 41 foreach ($patches as $patch) { 67 echo "applying patchfile $patch..."; 68 require_once("upgrades/".$common->db->phptype."/$patch"); 69 foreach ($sql as $query) { 70 $common->db->query($query); 71 if (PEAR::isError($res)) 72 die($res->getMessage()); 73 } 74 echo "done.<br>"; 42 if (!$updater->apply_dbpatch($patch, $mode)) 43 die("something went wrong with patchfile $patch. Rollback to backup."); 44 echo "applied patchfile $patch. <br>"; 75 45 /* put last version in var so we can update settings table later */ 76 $latest = substr($patch, strpos($patch, "to")+2, -4); 77 if ($latest > $latest_version) 78 $latest_version = $latest; 46 if ($updater->lastpatch > $latest_version) 47 $latest_version = $updater->lastpatch; 79 48 } 80 set_latest_version($latest_version);49 $updater->set_latest_version($latest_version); 81 50 echo "Your MvBlog installation is updated. Have fun."; 82 51 ?>
