File: update.php

package info (click to toggle)
letodms 3.3.9%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,828 kB
  • sloc: php: 21,980; sql: 1,054; sh: 85; makefile: 84
file content (93 lines) | stat: -rw-r--r-- 2,819 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
//    MyDMS. Document Management System
//    Copyright (C) 2002-2005  Markus Westphal
//    Copyright (C) 2006-2008 Malcolm Cowe
//    Copyright (C) 2010 Matteo Lucarelli
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

require_once("../inc/inc.Utils.php");
require_once('../inc/inc.ClassSettings.php');

$configDir = Settings::getConfigDir();
$settings = new Settings();
$settings->load($configDir."/settings.xml");

/**
 * Check if ENABLE_INSTALL_TOOL exists in config dir
 */
if (!file_exists($configDir."/ENABLE_INSTALL_TOOL")) {
	echo "For installation of LetoDMS, you must create the file conf/ENABLE_INSTALL_TOOL";
	exit;
}

require_once("../inc/inc.Language.php");
require_once("../inc/inc.ClassUI.php");

UI::htmlStartPage('Database update');
UI::contentHeading("letoDMS Installation for version ".$_GET['version']);
UI::contentContainerStart();

require_once($settings->_ADOdbPath."adodb/adodb.inc.php");
$db = ADONewConnection($settings->_dbDriver);
if ($db) {
	$db->Connect($settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase);
	if (!$db->IsConnected()) {
		die;
	}
}

$errorMsg = '';
$res = $db->Execute('select * from tblVersion');
if($rec = $res->FetchRow()) {
	if($_GET['version'] > $rec['major'].'.'.$rec['minor'].'.'.$rec['subminor']) {

		$queries = file_get_contents('update-'.$_GET['version'].'/update.sql');
		$queries = explode(";", $queries);

		// execute queries
		if($queries) {
			echo "<h3>Updating database schema</h3>";
			foreach($queries as $query) {
				$query = trim($query);
				if (!empty($query)) {
					echo $query."<br />";
					$db->Execute($query);

					if ($db->ErrorNo()<>0) {
						$errorMsg .= $db->ErrorMsg() . "<br/>";
					}
				}
			}
		}
	} else {
		echo "<p>Database schema already up to date.</p>";
	}


	if(!$errorMsg) {
		echo "<h3>Running update script</h3>";
		include('update-'.$_GET['version'].'/update.php');
	} else {
		echo $errorMsg;
	}
	echo "<p><a href=\"install.php\">Go back to installation.</a></p>";
} else {
	echo "<p>Could not determine database schema version.</p>";
}

UI::contentContainerEnd();
UI::htmlEndPage();
?>