-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethod.upgrade.php
More file actions
126 lines (122 loc) · 3.89 KB
/
Copy pathmethod.upgrade.php
File metadata and controls
126 lines (122 loc) · 3.89 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
#----------------------------------------------------------------------
# Module: MBVFaq - a simple FAQ module
# Method: upgrade
#----------------------------------------------------------------------
# See file MBVFaq.module.php for full details of copyright, licence, etc.
#----------------------------------------------------------------------
function rmdir_recursive($dir)
{
foreach(scandir($dir) as $file) {
if (!($file === '.' || $file === '..')) {
$fp = $dir.DIRECTORY_SEPARATOR.$file;
if (is_dir($fp)) {
rmdir_recursive($fp);
} else {
@unlink($fp);
}
}
}
rmdir($dir);
}
switch ($oldversion) {
case '0.1.0':
//convert and add db fields
$dict = NewDataDictionary($db);
$fields = '
category_id I(4) KEY,
number I(6),
owner I(4) NOTNULL DEFAULT 0
';
$sqlarray = $dict->AlterColumnSQL($this->CatTable, $fields);
$dict->ExecuteSQLArray($sqlarray, FALSE);
$fields = '
item_id I(6) KEY,
category_id I(4),
owner I(4),
create_date DT,
last_modified_date DT,
active I(1) NOTNULL DEFAULT 0,
number I(6)
';
$sqlarray = $dict->AlterColumnSQL($this->ItemTable, $fields);
$dict->ExecuteSQLArray($sqlarray, FALSE);
//add new preferences
$this->SetPreference('mbvf_clear_category', FALSE);
$this->SetPreference('mbvf_user_categories', FALSE);
$this->SetPreference('mbvf_short_answer', TRUE);
$this->SetPreference('mbvf_short_question', TRUE);
$this->SetPreference('mbvf_use_jquery', TRUE);
$this->SetPreference('mbvf_ignore_click', TRUE);
//add new permissions
$this->CreatePermission($this->PermAddName, $this->Lang('perm_add'));
$this->CreatePermission($this->PermModName, $this->Lang('perm_modify'));
$this->CreatePermission($this->PermDelName, $this->Lang('perm_delete'));
$this->CreatePermission($this->PermSeeName, $this->Lang('perm_view'));
case '0.3.0':
//remove files now renamed
$files = glob(cms_join_path(dirname(__FILE__), 'lib', 'MBVF*.php'));
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
}
}
$files = glob(cms_join_path(dirname(__FILE__), 'templates', 'mbvfaq*.tpl'));
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
}
}
//remove files mistakenly in 0.3.0 .xml release
$files = array('MBVFaq.prj','MBVFaq.pws','.tm_project.cache');
foreach ($files as $name) {
$file = cms_join_path(dirname(__FILE__), $name);
if (is_file($file)) {
unlink($file);
}
}
case '0.4.0':
case '0.4.1':
case '0.4.2':
//rename db fields
if (!isset($dict)) {
$dict = NewDataDictionary($db);
}
$fields = "number I(6)"; //field type needed only for MySQL
$sqlarray = $dict->RenameColumnSQL($this->CatTable, 'number', 'vieworder', $fields);
$dict->ExecuteSQLArray($sqlarray, FALSE);
$sqlarray = $dict->RenameColumnSQL($this->ItemTable, 'number', 'vieworder', $fields);
$dict->ExecuteSQLArray($sqlarray, FALSE);
$fields = "question C(255)";
$sqlarray = $dict->RenameColumnSQL($this->ItemTable, 'question', 'short_question', $fields);
$dict->ExecuteSQLArray($sqlarray, FALSE);
//rename preferences
$a = $this->GetPreference('mbvf_clear_category', FALSE);
$b = $this->GetPreference('mbvf_user_categories', FALSE);
$c = $this->GetPreference('mbvf_short_answer', TRUE);
$d = $this->GetPreference('mbvf_short_question', TRUE);
$e = $this->GetPreference('mbvf_use_jquery', TRUE);
$f = $this->GetPreference('mbvf_ignore_click', TRUE);
$this->RemovePreference();
$this->SetPreference('clear_category', $a);
$this->SetPreference('owned_categories', $b);
$this->SetPreference('short_answer', $c);
$this->SetPreference('short_question', $d);
$this->SetPreference('use_jquery', $e);
$this->SetPreference('ignore_click', $f);
case '0.5.0':
//redundant file
$file = cms_join_path(dirname(__FILE__), 'include', 'module_funcs.js');
if (is_file($file)) {
unlink($file);
}
case '1.0':
case '1.0.1':
case '1.1':
case '1.2':
//redundant directory
$file = cms_join_path(dirname(__FILE__), 'include');
if (is_dir($file)) {
rmdir_recursive($file);
}
}