forked from davjand/database_integration_manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.driver.php
317 lines (262 loc) · 8.06 KB
/
extension.driver.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
require_once(EXTENSIONS . "/database_integration_manager/lib/client.class.php");
require_once(EXTENSIONS . "/database_integration_manager/lib/base.class.php");
require_once(EXTENSIONS . "/database_integration_manager/lib/statemanager.class.php");
require_once(EXTENSIONS . "/database_integration_manager/lib/querymanager.class.php");
require_once(EXTENSIONS . "/database_integration_manager/lib/versioning.class.php");
class Extension_database_integration_manager extends Extension {
var $config = null;
/*
->__construct()
*/
public function __construct() {
parent::__construct();
$this->config = new DIM_Base();
}
/*
->install()
Symphony Override - see http://getsymphony.com/learn/api/2.3/toolkit/extension/#install
*/
public function install() {
/*
MODIFYING THIS? ADD A VERSION UPDATE IN THE update() FUNCTION!
*/
try {
Symphony::Database()->query('CREATE TABLE IF NOT EXISTS tbl_dim_versions (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`version` int(11) NOT NULL,
`state` varchar(100) NOT NULL,
`message` varchar(1024) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;');
} catch(Exception $e) { return false; }
$this->createFolders();
return true;
}
/*
->createFolders()
Create all folders required if they don't already exist
*/
public function createFolders(){
//data folder
if (!is_dir(DOCROOT.'/data')) {
mkdir(DOCROOT.'/data');
}
/*if (!is_dir(DOCROOT.'/data/global')) {
mkdir(DOCROOT.'/data/global');
} NOT USED AT THE MOMENT */
//config folder
if (!is_dir(MANIFEST.'/dim')) {
mkdir(MANIFEST.'/dim');
}
//cache folder
if (!is_dir(MANIFEST.'/dim/g_cache')) {
mkdir(MANIFEST.'/dim/g_cache');
}
}
public function checkWritableDirectories(){
$dir = array();
if(!is_writable(DOCROOT.'/data')){
array_push($dir, DOCROOT.'/data');
}
if (!is_writable(MANIFEST.'/dim')) {
array_push($dir, MANIFEST.'/dim');
}
//cache folder
if (!is_writable(MANIFEST.'/dim/g_cache')) {
array_push($dir, MANIFEST.'/dim/g_cache');
}
if(count($dir) > 0){
$error = "Database Integration Manager Directories not writable: ";
foreach($dir as $d){
$error = $error.$d." , ";
}
throw new Exception($error);
}
}
/*
->update($previousVersion)
Symphony Override - see http://getsymphony.com/learn/api/2.3/toolkit/extension/#update
*/
public function update($previousVersion) {
// fall through sequential updates
switch($previousVersion) {
case "0.0.1":
Symphony::Database()->query('ALTER TABLE tbl_dim_versions ADD `state` varchar(100) NOT NULL;');
case "0.0.2":
Symphony::Database()->query('ALTER TABLE tbl_dim_versions ADD `message` varchar(1024) NOT NULL;');
case "0.0.3":
break;
}
$this->createFolders();
}
/*
->uninstall()
Symphony Override - see http://getsymphony.com/learn/api/2.3/toolkit/extension/#uninstall
*/
public function uninstall() {
// if they've uninstalled this, then they're outside versioning so we need to delete this
Symphony::Database()->query("DROP TABLE tbl_dim_versions;");
}
/*
->fetchNavigation()
Symphony Override - see http://getsymphony.com/learn/api/2.3/toolkit/extension/#fetchNavigation
*/
public function fetchNavigation(){
return array(
array(
'location' => __('System'),
'name' => __('Database Manager'),
'link' => '/',
'limit' => 'developer'
),
array(
'location' => __('System'),
'name' => __('Database Log'),
'link' => '/log',
'limit' => 'developer'
)
);
}
/*
->getSubscribedDelegates()
Symphony Override - see http://getsymphony.com/learn/api/2.3/toolkit/extension/#getSubscribedDelegates
*/
public function getSubscribedDelegates() {
return array(
array(
'page' => '/backend/',
'delegate' => 'AppendPageAlert',
'callback' => 'appendAlerts'
),
array(
'page' => '/backend/',
'delegate' => 'NavigationPreRender',
'callback' => 'modifyNavigation'
),
array(
'page' => '/backend/',
'delegate' => 'PostQueryExecution',
'callback' => 'processQuery'
)
);
}
/*
->processQuery($context)
Marshalls the query into the querymanager for processing
*/
public function processQuery($context) {
/*
check actually needs to process query
If client and checked out
*/
if(strpos($context['page'][0],'frontend') !== FALSE ){
return;
}
if($this->config->getExtensionMode() == 'client'){
$stateManager = new DIM_StateManager("client");
if($stateManager->isCheckedOut()) {
$queryManager = new DIM_QueryManager();
$queryManager->logNewQuery(trim($context["query"]));
}
}
}
/*
->appendAlerts()
Adds an alert to the administration pages if DIM is installed but not configured.
*/
public function appendAlerts($context) {
$this->createFolders();//just to be on the safe side
$this->checkWritableDirectories();
if(!$this->config->isExtensionConfigured()) {
Administration::instance()->Page->pageAlert(
__('Database Integration Manager is installed but not configured. <a href=\'' . SYMPHONY_URL . '/extension/database_integration_manager\'>Configure it now</a>.'),
Alert::ERROR
);
}
else {
$versioning = new DIM_Versioning();
if($versioning->databaseNeedsUpdating()) {
Administration::instance()->Page->pageAlert(
__("<a href='" . SYMPHONY_URL . "/extension/database_integration_manager/update'> Your Database Is Out Of Date Update It</a>."),
Alert::ERROR
);
}
}
}
/*
->modifyNavigation($navigation)
Modify the Symphony admin navigation according to the current mode.
*/
public function modifyNavigation(&$navigation) {
if($this->config->isExtensionConfigured()) {
switch($this->config->getExtensionMode()) {
case "client":
$stateManager = new DIM_StateManager("client");
if(!$stateManager->isCheckedOut()) {
// clear out the blueprints
$navigation["navigation"][200] = array();
//remove extensions menu item
foreach($navigation["navigation"][100]['children'] as $key => $val){
if($val['link']=='/system/extensions/'){
$navigation["navigation"][100]['children'][$key]['visible']='no';
}
}
}
break;
case "server":
// clear out the blueprints
$navigation["navigation"][200] = array();
//remove extensions menu item
foreach($navigation["navigation"][100]['children'] as $key => $val){
if($val['link']=='/system/extensions/'){
$navigation["navigation"][100]['children'][$key]['visible']='no';
}
}
break;
case "disabled":
// we're disabled - don't do anything!
break;
}
}
else {
// clear all navigation items - the user will be able to get to the config via the alert.
$navigation["navigation"] = array();
}
}
/*
::testSettings($settings)
Run tests on the user-supplied settings to determine their integrity.
@params
$settings - the settings array supplied by the user
@returns
true/false based on test result
*/
public static function testSettings($settings) {
$config = new DIM_Base();
if($config->getDatabaseSettings() != null) {
switch($settings["mode"]["mode"]) {
case "client":
return DIM_Client::testClientSettings($settings["client"]);
break;
case "server":
// PASSED - no settings needed
return true;
break;
case "disabled":
// PASSED - no settings needed
return true;
break;
default:
// FAILED - something weird happened!
return false;
break;
}
}
else {
return false;
}
}
}
?>