PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/upgrade.php

http://wordcraft.googlecode.com/
PHP | 102 lines | 56 code | 34 blank | 12 comment | 10 complexity | 9fe4d732e07923e9ea85a57687326e8b MD5 | raw file
Possible License(s): CC0-1.0, AGPL-1.0
  1. <?php
  2. /**
  3. * Install script that handles sanity checks and sets up the database
  4. *
  5. * @author Brian Moon <brian@moonspot.net>
  6. * @copyright 1997-Present Brian Moon
  7. * @package Wordcraft
  8. * @license http://wordcraft.googlecode.com/files/license.txt
  9. * @link http://wordcraft.googlecode.com/
  10. *
  11. */
  12. define("WC_INSTALLING", true);
  13. // do this so session check will not fail
  14. ob_start();
  15. require_once "../include/common.php";
  16. require_once "./admin_functions.php";
  17. require_once "./header.php";
  18. if(!isset($WC["db_version"]) || $WC["db_version"] != WC_DB_VERSION){
  19. $pending_upgrades = array();
  20. $d = dir("../include/upgrade");
  21. while (false !== ($entry = $d->read())) {
  22. $ver = (int)$entry;
  23. if($ver > $WC["db_version"]){
  24. $pending_upgrades[] = $entry;
  25. }
  26. }
  27. $d->close();
  28. $current = array_shift($pending_upgrades);
  29. if(count($pending_upgrades)){
  30. $next = (int)array_shift($pending_upgrades);
  31. }
  32. $version = (int)$current;
  33. $schema = file_get_contents("../include/upgrade/$current");
  34. $schema = str_replace("{PREFIX}", $WC["db_prefix"], $schema);
  35. preg_match_all('!^[a-z].+?;!ism', $schema, $matches);
  36. $WCDB->query("BEGIN");
  37. $success = true;
  38. foreach($matches[0] as $sql){
  39. // trim off the ;
  40. $sql = substr($sql, 0, -1);
  41. $success = $WCDB->query($sql);
  42. if(!$success){
  43. wc_admin_error("Oops! There was an error upgrarding your database. The server said: '".$WCDB->last_error."'.", false);
  44. $continue = false;
  45. $WCDB->query("ROLLBACK");
  46. break;
  47. }
  48. }
  49. if($success){
  50. $WCDB->query("COMMIT");
  51. wc_db_save_settings(array("db_version"=>$version));
  52. wc_admin_message("Great! The database was updated to version $version without error.", false);
  53. ?>
  54. <?php if(isset($next)){ ?>
  55. <p>
  56. Press "Continue" to upgrade the datbase to version <?php echo $next; ?>.
  57. </p>
  58. <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
  59. <input type="submit" value="Continue">
  60. </form>
  61. <?php } ?>
  62. <?php
  63. }
  64. } else {
  65. wc_admin_message("Your database is up to date.");
  66. }
  67. require_once "./footer.php";
  68. ?>