-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathupgrade.php
43 lines (36 loc) · 1.21 KB
/
upgrade.php
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
<?php
if (file_exists(dirname(__FILE__).'/www/config.inc.php')) {
require_once dirname(__FILE__).'/www/config.inc.php';
} else {
require dirname(__FILE__).'/www/config-sample.inc.php';
}
echo 'Connecting to the database…';
$mysqli = UNL_Officefinder::getDB();
echo 'connected successfully!<br />'.PHP_EOL;
echo 'Initializing database structure…';
$result = $mysqli->multi_query(file_get_contents(dirname(__FILE__).'/data/officefinder.sql'));
if (!$result) {
echo 'There was an error initializing the database.<br />'.PHP_EOL;
echo $mysqli->error;
exit();
}
do {
if ($result = $mysqli->use_result()) {
$result->close();
}
} while ($mysqli->next_result());
echo 'initialization complete!<br />'.PHP_EOL;
foreach (
array(
__DIR__.'/data/add_academic.sql'=>'academic field',
__DIR__.'/data/add_suppress.sql'=>'suppress field',
) as $sql_file => $field_name) {
echo 'Adding '.$field_name.' to departments...<br />'.PHP_EOL;
$result = $mysqli->query(file_get_contents($sql_file));
if (!$result) {
if (mysqli_errno($mysqli) == 1060) {
echo 'Field already has been added<br />'.PHP_EOL;
}
}
}
echo 'Upgrade complete!'.PHP_EOL;