Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
install.php
Go to the documentation of this file.
1 <?php
2 /********************************************************************************
3  *
4  * Xataface Web Application Framework for PHP and MySQL
5  * Copyright (C) 2006 Steve Hannah <shannah@sfu.ca>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  *===============================================================================
22  */
23 
32 
33  function handle(&$params){
34 
36 
37  if ( df_get_database_version() == df_get_file_system_version() ){
38  $app->redirect(DATAFACE_SITE_HREF.'?--msg='.urlencode('The application database is up to date at version '.df_get_database_version()));
39  }
40 
41  if ( df_get_database_version() > df_get_file_system_version() ){
42  $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()));
43  }
44 
45  $res = mysql_query("select count(*) from dataface__version", df_db());
46  if ( !$res ){
47  throw new Exception(mysql_error(df_db()));
48  }
49  $row = mysql_fetch_row($res);
50  if ( $row[0] == 0 ){
51  $res2 = mysql_query("insert into dataface__version (`version`) values (0)", df_db());
52  if ( !$res2 ) throw new Exception(mysql_error(df_db()));
53  }
54 
55  if ( file_exists('conf/Installer.php') ){
56  import('conf/Installer.php');
57  $installer = new conf_Installer;
58 
59  $methods = get_class_methods('conf_Installer');
60  $methods = preg_grep('/^update_([0-9]+)$/', $methods);
61 
62  $updates = array();
63 
64  foreach ($methods as $method){
65  preg_match('/^update_([0-9]+)$/', $method, $matches);
66  $version = intval($matches[1]);
67  if ( $version > df_get_database_version() and $version <= df_get_file_system_version() ){
68  $updates[] = $version;
69  }
70  }
71 
72  sort($updates);
73 
74  foreach ($updates as $update ){
75  $method = 'update_'.$update;
76  $res = $installer->$method();
77  if ( PEAR::isError($res) ) return $res;
78  $res = mysql_query("update dataface__version set `version`='".addslashes($update)."'", df_db());
79  if ( !$res ) throw new Exception(mysql_error(df_db()), E_USER_ERROR);
80  }
81 
82 
83 
84  }
85 
86 
87  $res = mysql_query("update dataface__version set `version`='".addslashes(df_get_file_system_version())."'", df_db());
88  if ( !$res ) throw new Exception(mysql_error(df_db()), E_USER_ERROR);
89 
90  $app->redirect(DATAFACE_SITE_HREF.'?--msg='.urlencode('The database has been successfully updated to version '.df_get_file_system_version()));
91 
92 
93  }
94 }