-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathextension.driver.php
executable file
·143 lines (124 loc) · 4.42 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
<?php
require_once(EXTENSIONS . '/cdi/lib/class.cdiutil.php');
require_once(EXTENSIONS . '/cdi/lib/class.cdipreferences.php');
require_once(EXTENSIONS . '/cdi/lib/class.cdilogquery.php');
Class extension_cdi extends Extension {
public function install() {
if(CdiSlave::install()) {
if(CdiUtil::hasDumpDBInstalled()) {
CdiDumpDB::install();
}
} else {
return false;
}
Symphony::Configuration()->set('enabled', 'yes', 'cdi');
Symphony::Configuration()->set('cdi-mode', 'cdi', 'cdi');
Symphony::Configuration()->set('mode', 'CdiSlave', 'cdi');
Symphony::Configuration()->write();
return true;
}
public function uninstall() {
Symphony::Configuration()->remove('cdi');
Symphony::Configuration()->write();
CdiMaster::uninstall();
CdiSlave::uninstall();
CdiDBSync::uninstall();
CdiDumpDB::uninstall();
return true;
}
/*-------------------------------------------------------------------------
Delegate
-------------------------------------------------------------------------*/
public function getSubscribedDelegates()
{
return array(
array(
'page' => '/backend/',
'delegate' => 'PostQueryExecution',
'callback' => 'postQueryExecution'
),
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'initaliseAdminPageHead'
),
array(
'page' => '/backend/',
'delegate' => 'NavigationPreRender',
'callback' => 'NavigationPreRender'
),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
array(
'page' => '/system/extensions/',
'delegate' => 'ExtensionPreEnable',
'callback' => 'extensionPreEnable'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'savePreferences'
)
);
}
/*-------------------------------------------------------------------------
Delegated functions
-------------------------------------------------------------------------*/
public function postQueryExecution($context) {
CdiLogQuery::log($context['query']);
}
public function extensionPreEnable($context) {
foreach($context['extensions'] as $name) {
if($name == 'dump_db') {
CdiDumpDB::install();
}
}
}
public function initaliseAdminPageHead($context) {
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/cdi/assets/cdi.css',null,10);
Administration::instance()->Page->addScriptToHead(URL . '/extensions/cdi/assets/cdi.preferences.js',4598); // I like random numbers
}
public function NavigationPreRender($context) {
if(CdiUtil::hasDisabledBlueprints()) {
unset($context["navigation"][BLUEPRINTS_INDEX]);
}
}
public function appendPreferences($context){
// Import the db_sync.sql file when the cdi_import action is called
// The import action is the only left to require a post-back because AJAX file upload is cumbersome
if(isset($_POST["action"]["cdi_import"])) {
CdiDBSync::import();
} else if(isset($_POST["action"]["dumpdb_restore"])) {
CdiDumpDB::restore();
}
// Create the Preferences user-interface for the CDI extension
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'cdi settings');
$group->appendChild(new XMLElement('legend', 'Continuous Database Integration'));
$group->appendChild(new XMLElement('div', '<span class="image"> </span><span>Processing... please wait.</span>', array('class' => 'help cdiLoading cdiHidden')));
Administration::instance()->Page->Form->setAttribute('enctype', 'multipart/form-data');
$group->appendChild(CdiPreferences::appendCdiMode());
if(CdiUtil::isCdi()) {
$group->appendChild(CdiPreferences::appendCdiPreferences());
} else if(CdiUtil::isCdiDBSync()) {
$group->appendChild(CdiPreferences::appendDBSyncPreferences());
}
// Append preferences
$context['wrapper']->appendChild($group);
}
public function savePreferences($context){
if(CdiPreferences::save()) {
// apply config changes
if(CdiUtil::isCdiSlave()) { CdiSlave::install(); }
else if (CdiUtil::isCdiMaster()) { CdiMaster::install(); }
else { CdiDBSync::install(); }
} else {
Administration::instance()->Page->pageAlert(_('An unknown error occurred while saving preferences for CDI. Your changes have not been saved.'));
return false;
}
}
}
?>