Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 1
<?php
2
 
3
///////////////////////////////////////////////////////////////////////////////
4
//                                                                           //
5
// Copyright (C) 2006  Phorum Development Team                               //
6
// http://www.phorum.org                                                     //
7
//                                                                           //
8
// This program is free software. You can redistribute it and/or modify      //
9
// it under the terms of either the current Phorum License (viewable at      //
10
// phorum.org) or the Phorum License that was distributed with this file     //
11
//                                                                           //
12
// This program 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.                      //
15
//                                                                           //
16
// You should have received a copy of the Phorum License                     //
17
// along with this program.                                                  //
18
///////////////////////////////////////////////////////////////////////////////
19
define("phorum_page", "console_upgrade");
20
 
21
// I guess the phorum-directory is one level up. if you move the script to
22
// somewhere else you'll need to change that.
23
$PHORUM_DIRECTORY="../";
24
 
25
// change directory to the main-dir so we can use common.php
26
if(file_exists($PHORUM_DIRECTORY."/common.php")) {
27
    chdir($PHORUM_DIRECTORY);
28
} else {
29
    echo "Can't find common.php in the given directory. Please check the \$PHORUM_DIRECTORY -setting in console_upgrade.php\n";
30
    exit();
31
}
32
 
33
// include required files
34
include_once './common.php';
35
include_once './include/users.php';
36
 
37
// if we are running in the webserver, bail out
38
if (isset($_SERVER["REMOTE_ADDR"])) {
39
   echo $PHORUM["DATA"]["LANG"]["CannotBeRunFromBrowser"];
40
   return;
41
}
42
 
43
// no database connection?
44
if(!phorum_db_check_connection()){
45
    echo "A database connection could not be established.  Please edit include/db/config.php.\n";
46
    return;
47
} else {
48
    echo "Database connection confirmed, we will start the upgrade.\n";
49
    flush();
50
}
51
 
52
// no need for upgrade
53
if(isset($PHORUM['internal_version']) && $PHORUM['internal_version'] == PHORUMINTERNAL){
54
    echo "Your install is already up-to-date. No database-upgrade needed.\n";
55
    return;
56
}
57
 
58
if (! ini_get('safe_mode')) {
59
    echo "Trying to reset the timeout and rise the memory-limit ...\n";
60
    set_time_limit(0);
61
    ini_set("memory_limit","64M");
62
}
63
 
64
$fromversion=$PHORUM['internal_version'];
65
 
66
$upgradepath="./include/db/upgrade/{$PHORUM['DBCONFIG']['type']}/";
67
 
68
// read in all existing files
69
$dh=opendir($upgradepath);
70
$upgradefiles=array();
71
while ($file = readdir ($dh)) {
72
    if (substr($file,-4,4) == ".php") {
73
        $upgradefiles[]=$file;
74
    }
75
}
76
unset($file);
77
closedir($dh);
78
 
79
// sorting by number
80
sort($upgradefiles,SORT_NUMERIC);
81
reset($upgradefiles);
82
 
83
// advance to current version
84
while(list($key,$val)=each($upgradefiles)) {
85
    if($val == $fromversion.".php")
86
    break;
87
}
88
 
89
 
90
while(list($dump,$file) = each($upgradefiles)) {
91
 
92
    // extract the pure version, needed as internal version
93
    $pure_version = basename($file,".php");
94
 
95
    if(empty($pure_version)){
96
        die("Something is wrong with the upgrade script.  Please contact the Phorum Dev Team. ($fromversion,$pure_version)");
97
    }
98
 
99
 
100
    $upgradefile=$upgradepath.$file;
101
 
102
    if(file_exists($upgradefile)) {
103
        echo "Upgrading from db-version $fromversion to $pure_version ... \n";
104
        flush();
105
 
106
        if (! is_readable($upgradefile))
107
        die("$upgradefile is not readable. Make sure the file has got the neccessary permissions and try again.");
108
 
109
 
110
        $upgrade_queries=array();
111
        include($upgradefile);
112
        $err=phorum_db_run_queries($upgrade_queries);
113
        if($err){
114
            echo "an error occured: $err ... try to continue.\n";
115
        } else {
116
            echo "done.\n";
117
        }
118
        $GLOBALS["PHORUM"]["internal_version"]=$pure_version;
119
        phorum_db_update_settings(array("internal_version"=>$pure_version));
120
    } else {
121
        echo "Ooops, the upgradefile is missing. How could this happen?\n";
122
    }
123
 
124
    $fromversion=$pure_version;
125
 
126
}
127
?>