-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJobDiagnosticsPlugin.php
137 lines (128 loc) · 3.79 KB
/
JobDiagnosticsPlugin.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
<?php
/**
* The main plugin.
* @package JobDiagnostics
*/
class JobDiagnosticsPlugin extends Omeka_Plugin_AbstractPlugin
{
/**
* Hooks used by this plugin.
* @var array
*/
protected $_hooks = array(
'install',
'uninstall',
'upgrade',
'define_acl',
'define_routes',
);
/**
* Filters used by this plugin.
* @var array
*/
protected $_filters = array(
'admin_navigation_main',
);
/**
* HOOK: Install
* Add tables to the database.
*/
public function hookInstall()
{
$db = get_db();
$db->query(
"CREATE TABLE IF NOT EXISTS `{$db->prefix}job_diagnostics_tests` (
`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`dispatch_type` VARCHAR(64) NOT NULL,
`started` TIMESTAMP DEFAULT NOW() NOT NULL,
`finished` TIMESTAMP NULL,
`error` TEXT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
);
}
/**
* HOOK: Uninstall
* Remove tables from the database
*/
public function hookUninstall()
{
$db = get_db();
$db->query("DROP TABLE IF EXISTS `{$db->prefix}job_diagnostics_tests`;");
}
/**
* HOOK: Upgrade
* Follow migrations in sequence from oldest to newest.
*/
public function hookUpgrade($args)
{
// Capture arguments
$oldVersion = $args['old_version'];
$newVersion = $args['new_version'];
$doMigrate = false;
// Load in all migrations
$versions = array();
foreach (glob(dirname(__FILE__) . '/libraries/JobDiagnostics/Migration/*.php') as $migrationFile) {
$className = 'JobDiagnostics_Migration_' . basename($migrationFile, '.php');
include $migrationFile;
$versions[$className::$version] = new $className();
}
// Sort in version order
uksort($versions, 'version_compare');
// Run from oldest to newest, starting with the first one later than the old version
foreach ($versions as $version => $migration) {
if (version_compare($version, $oldVersion, '>')) {
$doMigrate = true;
}
if ($doMigrate) {
$migration->up();
if (version_compare($version, $newVersion, '>')) {
break;
}
}
}
}
/**
* HOOK: Setting up ACL
* Allow only superusers and admins to use this plugin.
*
* @param array $args
*/
public function hookDefineAcl($args)
{
$acl = $args['acl'];
$acl->add(new Zend_Acl_Resource('Process'));
$acl->deny(null, 'Process');
$acl->allow(array('super', 'admin'), 'Process', array('browse', 'show'));
$acl->add(new Zend_Acl_Resource('JobDiagnostics_Test'));
$acl->deny(null, 'JobDiagnostics_Test');
$acl->allow(array('super', 'admin'), 'JobDiagnostics_Test', array('browse', 'show', 'add', 'clear'));
}
/**
* HOOK: Setting up routes
* Add routes to the admin side only.
*
* @param array $args
*/
public function hookDefineRoutes($args)
{
$args['router']->addConfig(new Zend_Config_Ini(dirname(__FILE__) . '/routes.ini', 'routes'));
}
/**
* FILTER: Add entry to admin navigation menu.
*
* @param array $nav
* @return array
*/
public function filterAdminNavigationMain($nav)
{
$user = current_user();
$acl = get_acl();
if ($acl->isAllowed($user->role, 'Process', 'browse')) {
$nav[] = array(
'label' => __('Job Diagnostics'),
'uri' => url(array(), 'job_diagnostics_root'),
);
}
return $nav;
}
}