This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added system hooks for checking if proper db schema is available.
- Loading branch information
1 parent
07972b4
commit eb4d916
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
; Enabled by default | ||
enabled="true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
|
||
} |