Skip to content

Commit 3e96e5f

Browse files
committed
plugin: Add Multi-instance Support
This commit adds multi-instance support for plugins
1 parent 5d704ff commit 3e96e5f

16 files changed

+1064
-372
lines changed

bootstrap.php

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static function defineTables($prefix) {
133133
define('FILTER_ACTION_TABLE', $prefix.'filter_action');
134134

135135
define('PLUGIN_TABLE', $prefix.'plugin');
136+
define('PLUGIN_INSTANCE_TABLE', $prefix.'plugin_instance');
136137
define('SEQUENCE_TABLE', $prefix.'sequence');
137138
define('TRANSLATION_TABLE', $prefix.'translation');
138139
define('QUEUE_TABLE', $prefix.'queue');

include/ajax.plugins.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
require_once(INCLUDE_DIR . 'class.plugin.php');
3+
4+
class PluginsAjaxAPI extends AjaxController {
5+
6+
/*
7+
* Protect all routines in this controller
8+
*/
9+
function access() {
10+
global $thisstaff;
11+
if (!$thisstaff || !$thisstaff->isAdmin())
12+
Http::response(403, 'Access Denied');
13+
14+
return true;
15+
}
16+
17+
// helper func to look up plugin & instance
18+
private function lookup($plugin_id, $instance_id=0) {
19+
if (!($plugin = PluginManager::lookup( (int) $plugin_id)))
20+
Http::response(404, 'No such plugin');
21+
22+
if ($instance_id && !($instance = $plugin->getInstance( (int) $instance_id)))
23+
Http::response(404, 'No such plugin instance');
24+
25+
return [$plugin, $instance];
26+
}
27+
28+
function getInstances($plugin_id) {
29+
list($plugin,)= $this->lookup($plugin_id);
30+
$pjax_container = '#items';
31+
include(STAFFINC_DIR . 'templates/plugin-instances.tmpl.php');
32+
}
33+
34+
function updateInstance($plugin_id, $instance_id) {
35+
list($plugin, $instance) = $this->lookup($plugin_id, $instance_id);
36+
$errors = array();
37+
if ($_POST && $instance->update($_POST, $errors))
38+
Http::response(201, $this->encode([
39+
'redirect' => sprintf('plugins.php?id=%d#instances',
40+
$plugin->getId())
41+
]));
42+
$form = $instance->getForm();
43+
$action = "#plugins/{$plugin->getId()}/instances/{$instance->getId()}/update";
44+
include STAFFINC_DIR . 'templates/plugin-instance-modal.tmpl.php';
45+
}
46+
47+
function addInstance($plugin_id) {
48+
list($plugin,) = $this->lookup($plugin_id);
49+
$errors = array();
50+
if ($_POST && ($instance=$plugin->addInstance($_POST, $errors)))
51+
Http::response(201, $this->encode([
52+
'redirect' => sprintf('plugins.php?id=%d#instances',
53+
$plugin->getId())
54+
]));
55+
// This should return cached form with errors (if any)
56+
$form = $plugin->getConfigForm();
57+
// Set action
58+
$action = "#plugins/{$plugin->getId()}/instances/add";
59+
include(STAFFINC_DIR . 'templates/plugin-instance-modal.tmpl.php');
60+
}
61+
}
62+
?>

include/class.osticket.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,9 @@ static function start() {
640640
return null;
641641

642642
// Bootstrap installed plugins
643-
$ost->plugins->bootstrap();
643+
//XXX: This is TEMP for v1.17
644+
if (!$ost->isUpgradePending())
645+
$ost->plugins->bootstrap();
644646

645647
// Mirror content updates to the search backend
646648
$ost->searcher = new SearchInterface();

0 commit comments

Comments
 (0)