/
Install.php
71 lines (57 loc) · 1.69 KB
/
Install.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
<?php
class NextShout_Install {
static public function install($existingAddOn, $addOnData) {
if ( !$existingAddOn ) {
self::installFresh();
} else {
self::upgrade($existingAddOn['version_id']);
}
}
static protected function installFresh() {
$installData = new NextShout_Install_Data_Mysql();
$tables = $installData->getTables();
$db = XenForo_Application::get('db');
foreach ( $tables as $tableName => $createSql ) {
$db->query($createSql);
}
}
static protected function upgrade($fromVersion) {
$versions = self::getUpgradeVersions($fromVersion);
foreach ( $versions as $version ) {
$class = 'NextShout_Install_Upgrade_' . $version;
$upgrade = new $class();
$upgrade->upgrade();
}
}
static protected function getUpgradeVersions($fromVersion) {
$root = XenForo_Application::getInstance()->getRootDir();
$upgradeDir = $root . '/library/NextShout/Install/Upgrade';
$upgrades = array();
foreach ( glob($upgradeDir . '/*.php') as $file ) {
$versionId = intval($file);
if ( !$versionId ) {
continue;
}
$upgrades[] = $versionId;
}
sort($upgrades, SORT_NUMERIC);
foreach ( $upgrades as $i => $upgrade ) {
if ( $upgrade > $fromVersion ) {
return array_slice($upgrades, $i);
}
}
return array();
}
static public function getUpgradeData($version, $type = 'Mysql') {
$class = 'NextShout_Install_Upgrade_' . $version . '_' . $type;
return new $class();
}
static public function uninstall($addOnData) {
$installData = new NextShout_Install_Data_Mysql();
$tables = $installData->getTables();
$db = XenForo_Application::get('db');
foreach ( array_keys($tables) as $table ) {
$db->query('DROP TABLE ' . $table);
}
}
}