PHP Classes

File: update.php

Recommend this page to a friend!
  Classes of Nico den Boer   Database metadata   update.php   Download  
File: update.php
Role: Application script
Content type: text/plain
Description: Main page to execute a update.
Class: Database metadata
Update a MySQL database schema using on metadata
Author: By
Last change: Depedencies removed
Date: 17 years ago
Size: 3,607 bytes
 

Contents

Class file image Download
<?php
/**
 * Page to run a update
 *
 * First written: 12-04-2006
 *
 * Changelog:
 * <ol>
 * <li></li>
 * </ol>
 *
 *
 * @author H.F.N. den Boer <nico@denboer-ims.nl>
 * @version 1.1.0
 * @package nl.denboer-ims.imslib.install
 */

global $imslib_Backbone, $imslib_Update, $local;
$local = true;

/**
 * To automatically update the database structure
 */
require_once("./class.backbone.inc.php");

// First check if access of this page is allowed
if (!isset($imslib_Backbone))
    die(
"In order to call this file, the backbone must be included first...");

$imslib_Backbone->database["Catalog"] = "dbmetadata";
$imslib_Backbone->database["connection"]->connect($imslib_Backbone->database["Catalog"]);

//require("class.mysql.db.backup.inc.php");
//$tmp = new imslib_mysql_db_backup();
//$tmp->Execute();
//return;

/*******************************************************************************
 * Read current version info and prepare update
 *******************************************************************************/

/* @var $dataReader imslib_dataReader */
$dataReader = null;
$imslib_Backbone->getDataSet("SELECT * FROM sys_settings", $dataReader);
if (isset(
$dataReader) && $dataReader->hasNext())
{
   
$row = $dataReader->getNext();
   
$configAvailable = true;
   
$version_major = (int)$row["version_major"];
   
$version_minor = (int)$row["version_minor"];
   
$version_build = (int)$row["version_build"];
}
else
{
   
$configAvailable = false;
   
$version_major = 0;
   
$version_minor = 0;
   
$version_build = 0;
}
$dataReader->dispose();
unset(
$dataReader);


$imslib_Backbone->head["Title"] = "dbmetadata";
$imslib_Backbone->printHead();
echo
"<h1>Update</h1>";
echo
"<p>Current version: $version_major.$version_minor.$version_build</p>";

echo
"<p>Applying database patches:</p><ul>";
flush();
$patchApplied = false;

$sql = file_get_contents("InsertMetaData.sql");
$imslib_Backbone->execScript(explode(";", $sql));

echo
"Metadata updated</li>";
flush();

/**
 * To automatically update the database structure
 */
require_once("class.mysql.db.maint.inc.php");
echo
"<li>Updating database structure ... ";
flush();
$imslib_DataMaintenance->update();
echo
" done</li>";
flush();

/*******************************************************************************
 * Execute patches in chronological order
 *******************************************************************************/
if ($version_major == 0 && $version_minor == 0 && $version_build == 0)
{
    echo
"<li>0.0.0 to 0.0.1 ... ";
   
// apply some data edits here...
   
echo " done</li>";
   
flush();
   
$version_build = 1;
   
$patchApplied = true;
}

/*******************************************************************************
 * Update version information and exit
 *******************************************************************************/
if (!$patchApplied)
    echo
"<li>System was already up to date, no patches nessecary...</li>";
echo
"</ul>";

require(
"class.sqlBuilder.inc.php");
$sqlBuilder = new imslib_sqlBuilder();
/* @var $sqlBuilder imslib_sqlBuilder */
$sqlBuilder->reset("sys_settings");
$sqlBuilder->add("version_major", $version_major);
$sqlBuilder->add("version_minor", $version_minor);
$sqlBuilder->add("version_build", $version_build);
if (
$configAvailable)
   
$sqlBuilder->setUpdateModus("id", (int)$row["id"]);
echo
"<p>Registering latest version number ... ";
$imslib_Backbone->execSql($sqlBuilder->getSql());
echo
" done</p>";
echo
"<p>Update <b>finished</b>.</p>";

$imslib_Backbone->printFooter();

?>