]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/upgrade.php
fixed explodePageList: wrong sortby argument order in UnfoldSubpages
[SourceForge/phpwiki.git] / lib / upgrade.php
1 <?php //-*-php-*-
2 rcs_id('$Id: upgrade.php,v 1.2 2004-03-12 15:48:07 rurban Exp $');
3
4 /*
5  Copyright 2004 $ThePhpWikiProgrammingTeam
6
7  This file is (not yet) part of PhpWiki.
8
9  PhpWiki is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  PhpWiki is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with PhpWiki; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24
25 /**
26  * Upgrade the WikiDB and config settings after installing a new 
27  * PhpWiki upgrade.
28  * Status: experimental, no queries for verification yet, no db update,
29  *         no merge conflict
30  * Installation on an existing PhpWiki database needs some 
31  * additional worksteps. Each step will require multiple pages.
32  *
33  * This is the plan:
34  *  1. Check for new or changed database schema and update it 
35  *     according to some predefined upgrade tables. (medium)
36  *  2. Check for new or changed (localized) pgsrc/ pages and ask 
37  *     for upgrading these. Check timestamps, upgrade silently or 
38  *     show diffs if existing. Overwrite or merge (easy)
39  *  3. Check for new or changed or deprecated index.php settings
40  *     and help in upgrading these. (hard)
41  *  4. Check for changed plugin invocation arguments. (hard)
42  *  5. Check for changed theme variables. (hard)
43  *
44  * @author: Reini Urban
45  */
46 require_once("lib/loadsave.php");
47
48 // see loadsave.php for saving new pages.
49 function CheckPgsrcUpdate(&$request) {
50     $dbh = $request->getDbh(); 
51     $path = FindLocalizedFile(WIKI_PGSRC);
52     $pgsrc = new fileSet($path);
53     // fixme: verification, ...
54     foreach ($pgsrc->getFiles() as $pagename) {
55         $pagename = urldecode($pagename);
56         if (substr($pagename,-1,1) == '~') continue;
57         if ($dbh->isWikiPage($pagename)) {
58             // check mtime
59             ; //echo "$pagename exists<br />\n";
60         } else {
61             echo "$pagename does not exist<br />\n";
62             LoadAny($request,$path."/".$pagename);
63             echo "<br />\n";
64         }
65     }
66     return;
67 }
68
69 /**
70  * search table definition in appropriate schema and 
71  * create it.
72  * supported: mysql
73  */
74 function installTable(&$dbh, $table) {
75     if (!in_array($DBParam['dbtype'],array('SQL','ADODB'))) return;
76     $backend = 'mysql'; // fixme
77     $schema = findFile("schemas/$backend.sql");
78     if (!$schema)
79         return false;
80     switch ($table) {
81     case 'session': 
82         break;
83     case 'user':
84         break;
85     case 'pref':
86         break;
87     case 'members':
88         break;
89     }
90 }
91 /** 
92  * currently update only session, user, pref and member
93  * jeffs-hacks database api (around 1.3.2) later
94  *   people should export/import their pages if using that old versions.
95  */
96 function CheckDatabaseUpdate($request) {
97     global $DBParam, $DBAuthParams;
98     if (!in_array($DBParam['dbtype'],array('SQL','ADODB'))) return;
99     $dbh = &$request->_dbi;
100     $backend = &$dbh->_backend->_dbh;
101     if ($DBParam['dbtype'] == 'SQL') {
102         $tables = $backend->getListOf('tables');
103     } elseif ($DBParam['dbtype'] == 'ADODB') {
104         $tables = $backend->MetaTables();
105     }
106     //...
107     return;
108 }
109
110 /**
111  * Upgrade: Base class for multipage worksteps
112  * identify, validate, display options, next step
113  */
114 class Upgrade {
115 }
116
117 class Upgrade_CheckPgsrc extends Upgrade {
118 }
119
120 class Upgrade_CheckDatabaseUpdate extends Upgrade {
121 }
122
123 // TODO: At which step are we? 
124 // validate and do it again or go on with next step.
125
126 /** entry function from lib/main.php
127  */
128 function DoUpgrade($request) {
129
130     if (!$request->_user->isAdmin()) {
131         $request->_notAuthorized(WIKIAUTH_ADMIN);
132         $request->finish(
133                          HTML::div(array('class' => 'disabled-plugin'),
134                                    fmt("Upgrade disabled: user != isAdmin")));
135         return;
136     }
137
138     StartLoadDump($request, _("Upgrading this PhpWiki"));
139     CheckDatabaseUpdate($request);
140     CheckPgsrcUpdate($request);
141     EndLoadDump($request);
142 }
143
144
145 /**
146  $Log: not supported by cvs2svn $
147  */
148
149 // For emacs users
150 // Local Variables:
151 // mode: php
152 // tab-width: 8
153 // c-basic-offset: 4
154 // c-hanging-comment-ender-p: nil
155 // indent-tabs-mode: nil
156 // End:
157 ?>