-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.php
84 lines (71 loc) · 2.22 KB
/
update.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
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
<?php
ini_set('error_reporting', E_ALL & ~(E_STRICT | E_NOTICE));
ini_set('display_errors', 0);
$db_config = require __DIR__ . '/config/db.php';
$prefix = $db_config['prefix'];
try {
$db = _getDatabase($db_config);
$db->beginTransaction();
if ($view_version < 0.2)
{
$db->exec('ALTER TABLE '.$prefix.'admin ADD rbac VARCHAR(10)');
$db->exec('UPDATE '.$prefix.'admin SET `rbac`=\'super\' WHERE `name`=\'admin\'');
$db->exec('ALTER TABLE '.$prefix.'admin ADD `json` VARCHAR(255)');
$db->exec('ALTER TABLE '.$prefix.'admin DROP COLUMN `last_time`');
$db->exec('ALTER TABLE '.$prefix.'admin DROP COLUMN `login_count`');
$db->exec('ALTER TABLE '.$prefix.'admin DROP COLUMN `last_ip`');
$db->exec('ALTER TABLE '.$prefix.'admin DROP COLUMN `issuper`');
}
if ($view_version < 0.4)
{
$db->exec("ALTER TABLE ".$prefix."item ADD `url` VARCHAR(255) NULL DEFAULT ''");
$db->exec("ALTER TABLE ".$prefix."item ADD `url_title` VARCHAR(50) NULL DEFAULT ''");
$db->exec("ALTER TABLE ".$prefix."item ADD `url_target` VARCHAR(10) NULL DEFAULT ''");
}
$db->commit();
} catch (PDOException $e) {
$db->rollBack();
_log($view_version . ' ' . $e->getMessage());
return false;
}
return true;
//连接数据库
function _getDatabase($config)
{
$dsn = $config['type'].':host='.$config['host'].';dbname='.$config['name'].';port='.$config['port'];
$user = $config['user'];
$password = $config['pass'];
$db = new PDO($dsn, $user, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES '.$config['charset']));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
}
//删除目录
function _removeDir($path)
{
if ($handle = @opendir($path))
{
while (false !== ($item = readdir($handle)))
{
if ($item != '.' && $item != '..')
{
if (is_dir("$path/$item"))
{
_removeDir("$path/$item");
}
else
{
@unlink("$path/$item");
}
}
}
@rmdir($path);
closedir($handle);
}
}
//日志记录
function _log($m)
{
$dirname = dirname(__FILE__) . '/data/log/';
@mkdir($dirname, true);
file_put_contents($dirname . 'upgrade', date('H:i:s', time()) . ' ' . getenv('REMOTE_ADDR') . " $m\n", FILE_APPEND);
}