Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Added system hooks for checking if proper db schema is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchisari authored and The Appleseed Project committed Dec 9, 2010
1 parent 07972b4 commit eb4d916
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hooks/system/languages/en-US/system.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[check-schema-version]
TABLE_DOES_NOT_EXIST="Table '%tablename$s' does not exist. Check in /_releases/ for update scripts and make sure you have updated to the latest database schema."

SCHEMA_VERSION_INFORMATION_UNAVAILABLE="No schema version information was found. Check in /_releases/ for update scripts and make sure you have updated to the latest schema version."

INCORRECT_SCHEMA_VERSION="Your database schema (version %current$s) is out of date. Run <b>/_releases/update-%version$s.sql</b> to update your Appleseed node."
2 changes: 2 additions & 0 deletions hooks/system/system.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
; Enabled by default
enabled="true"
76 changes: 76 additions & 0 deletions hooks/system/system.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* @version $Id$
* @package Appleseed.Framework
* @subpackage System
* @copyright Copyright (C) 2004 - 2010 Michael Chisari. All rights reserved.
* @link http://opensource.appleseedproject.org
* @license GNU General Public License version 2.0 (See LICENSE.txt)
*/

// Restrict direct access
defined( 'APPLESEED' ) or die( 'Direct Access Denied' );

/** System Hook Class
*
* System Hook Class
*
* @package Appleseed.Framework
* @subpackage System
*/
class cSystemHook extends cHook {

/**
* Constructor
*
* @access public
*/
public function __construct ( ) {
parent::__construct();
}

public function BeginSystemInitialize ( $pData = null ) {

$this->_CheckSchemaVersion ( );
return ( true );
}

private function _CheckSchemaVersion ( ) {

$Config = $this->GetSys ( 'Config' );

// Get the schema version required
$Version = $Config->GetConfiguration ( 'schema_version' );

$Model = new cModel ( 'SchemaVersions' );

// SchemaVersions doesn't exist, we must be upgrading from 0.7.8 and have not updated.
if ( !$Model->Get ( 'Exists' ) ) {
echo __ ( 'Table Does Not Exist', array ( 'tablename' => 'SchemaVersions' ) );
exit;
}

// Retrieve the latest schema version information.
$Model->Retrieve ( null, 'Schema_PK DESC', array ( 'start' => 0, 'step' => 1 ) );

// No schema version info was found, so we must be upgrading from 0.7.8.
if ( $Model->Get ( 'Total' ) == 0 ) {
echo __ ( 'Schema Version Information Unavailable', array ( 'version' => $Version ) );
exit;
}

$Model->Fetch();

$Current = $Model->Get ( 'Version' );
$Script = $Model->Get ( 'Script' );

// If the current and the expected schema version don't match, give a suggested update scripts to run.
if ( $Current != $Version ) {
echo __ ( 'Incorrect Schema Version', array ( 'version' => $Version, 'current' => $Current, 'script' => $Script ) );
exit;
}

return ( true );
}

}

0 comments on commit eb4d916

Please sign in to comment.