Xataface 2.0
Xataface Application Framework
actions/install.php
Go to the documentation of this file.
00001 <?php
00002 /********************************************************************************
00003  *
00004  *  Xataface Web Application Framework for PHP and MySQL
00005  *  Copyright (C) 2006  Steve Hannah <shannah@sfu.ca>
00006  *  
00007  *  This library is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Lesser General Public
00009  *  License as published by the Free Software Foundation; either
00010  *  version 2.1 of the License, or (at your option) any later version.
00011  *  
00012  *  This library is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  *  Lesser General Public License for more details.
00016  *  
00017  *  You should have received a copy of the GNU Lesser General Public
00018  *  License along with this library; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  *
00021  *===============================================================================
00022  */
00023  
00031 class dataface_actions_install {
00032 
00033         function handle(&$params){
00034         
00035                 $app =& Dataface_Application::getInstance();
00036                 
00037                 if ( df_get_database_version() == df_get_file_system_version() ){
00038                         $app->redirect(DATAFACE_SITE_HREF.'?--msg='.urlencode('The application database is up to date at version '.df_get_database_version()));
00039                 }
00040                 
00041                 if ( df_get_database_version() > df_get_file_system_version() ){
00042                         $app->redirect(DATAFACE_SITE_HREF.'?--msg='.urlencode('The database version is greater than the file system version.  Please upgrade your application to match the version in the database (version '.df_get_database_version()));
00043                 }
00044                 
00045                 $res = mysql_query("select count(*) from dataface__version", df_db());
00046                 if ( !$res ){
00047                         throw new Exception(mysql_error(df_db()));
00048                 }
00049                 $row = mysql_fetch_row($res);
00050                 if ( $row[0] == 0 ){
00051                         $res2 = mysql_query("insert into dataface__version (`version`) values (0)", df_db());
00052                         if ( !$res2 ) throw new Exception(mysql_error(df_db()));
00053                 }
00054                 
00055                 if ( file_exists('conf/Installer.php') ){
00056                         import('conf/Installer.php');
00057                         $installer = new conf_Installer;
00058                         
00059                         $methods = get_class_methods('conf_Installer');
00060                         $methods = preg_grep('/^update_([0-9]+)$/', $methods);
00061                         
00062                         $updates = array();
00063                         
00064                         foreach ($methods as $method){
00065                                 preg_match('/^update_([0-9]+)$/', $method, $matches);
00066                                 $version = intval($matches[1]);
00067                                 if ( $version > df_get_database_version() and $version <= df_get_file_system_version() ){
00068                                         $updates[] = $version;
00069                                 }
00070                         }
00071                         
00072                         sort($updates);
00073                         
00074                         foreach ($updates as $update ){
00075                                 $method = 'update_'.$update;
00076                                 $res = $installer->$method();
00077                                 if ( PEAR::isError($res) ) return $res;
00078                                 $res = mysql_query("update dataface__version set `version`='".addslashes($update)."'", df_db());
00079                                 if ( !$res ) throw new Exception(mysql_error(df_db()), E_USER_ERROR);   
00080                         }
00081                         
00082                         
00083                         
00084                 }
00085                 
00086                 
00087                 $res = mysql_query("update dataface__version set `version`='".addslashes(df_get_file_system_version())."'", df_db());
00088                 if ( !$res ) throw new Exception(mysql_error(df_db()), E_USER_ERROR);
00089                 
00090                 $app->redirect(DATAFACE_SITE_HREF.'?--msg='.urlencode('The database has been successfully updated to version '.df_get_file_system_version()));
00091 
00092                 
00093         }
00094 }
 All Data Structures Namespaces Files Functions Variables Enumerations