From 6f279c5ee49ccfb3dd4528092e634da02e4afb5b Mon Sep 17 00:00:00 2001 From: Davide Scola Date: Thu, 30 Mar 2023 14:23:33 +0000 Subject: [PATCH 1/6] multiple instances of this plugin are disabled --- BitfinexStreamerPlugin.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BitfinexStreamerPlugin.php b/BitfinexStreamerPlugin.php index 18bb18e..2f499c8 100644 --- a/BitfinexStreamerPlugin.php +++ b/BitfinexStreamerPlugin.php @@ -55,6 +55,13 @@ public function bootstrap() { } } + /** + * {@inheritDoc} + */ + public function isMultiInstance() { + return FALSE; + } + /** * {@inheritDoc} */ From 78be8fc3c9686de0e19ea554e38b98b07bf26892 Mon Sep 17 00:00:00 2001 From: Davide Scola Date: Thu, 30 Mar 2023 14:29:44 +0000 Subject: [PATCH 2/6] plugin name displayed in new versions of osTicket is taken from the plugin information instead of the database --- BitfinexStreamerPlugin.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/BitfinexStreamerPlugin.php b/BitfinexStreamerPlugin.php index 2f499c8..7d90796 100644 --- a/BitfinexStreamerPlugin.php +++ b/BitfinexStreamerPlugin.php @@ -27,6 +27,9 @@ /** * Entry point class to bfx-ost-streamer plugin. + * + * @property array $ht + * A cached version of the plugin's configuration taken from the database. */ class BitfinexStreamerPlugin extends \Plugin { @@ -55,6 +58,17 @@ public function bootstrap() { } } + /** + * {@inheritDoc} + */ + public function init() { + if (\method_exists(parent::class, 'init') === TRUE) { + parent::init(); + } + + $this->{'ht'}['name'] = $this->{'info'}['name']; + } + /** * {@inheritDoc} */ From 2bc7eaa481f49e3dab96236f3303056d2f618d84 Mon Sep 17 00:00:00 2001 From: Davide Scola Date: Thu, 30 Mar 2023 14:30:36 +0000 Subject: [PATCH 3/6] minimum required version of osTicket has been added to the plugin information --- plugin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin.php b/plugin.php index dac6cf9..ab86dc4 100644 --- a/plugin.php +++ b/plugin.php @@ -25,6 +25,7 @@ return [ 'id' => /* notrans */ 'bfx:ost:streamer', 'version' => '1.1.0', + 'ost_version' => '1.10', 'name' => /* trans */ 'Bitfinex osTicket Streamer', 'author' => 'Davide Scola, Nicoletta Maia', 'description' => /* trans */ 'Adds the ability to stream data.', From 2fa07fbb1cf1e31b794f2ac54cb202cb9656e0fc Mon Sep 17 00:00:00 2001 From: Davide Scola Date: Thu, 30 Mar 2023 14:31:33 +0000 Subject: [PATCH 4/6] implementation of a new method for rendering configuration form has been added --- .../Configuration/BitfinexStreamerPluginConfig.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/Streamer/osTicket/Configuration/BitfinexStreamerPluginConfig.php b/include/Streamer/osTicket/Configuration/BitfinexStreamerPluginConfig.php index 7662a90..ece7d03 100644 --- a/include/Streamer/osTicket/Configuration/BitfinexStreamerPluginConfig.php +++ b/include/Streamer/osTicket/Configuration/BitfinexStreamerPluginConfig.php @@ -120,12 +120,19 @@ public function getOptions() { /** * {@inheritDoc} */ - public function renderCustomConfig() { + public function renderConfig() { $options = []; $form = $this->getForm(); include \BitfinexStreamerPlugin::PLUGIN_DIR . '/templates/configuration-form.tmpl.php'; } + /** + * {@inheritDoc} + */ + public function renderCustomConfig() { + $this->renderConfig(); + } + /** * {@inheritDoc} */ From c5cfbac2ab235bb2bed3317ccff6a6a6e047e30f Mon Sep 17 00:00:00 2001 From: Davide Scola Date: Thu, 30 Mar 2023 14:32:44 +0000 Subject: [PATCH 5/6] saving of configuration options has been unified across all versions of osTicket --- .../BitfinexStreamerPluginConfig.php | 58 ++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/include/Streamer/osTicket/Configuration/BitfinexStreamerPluginConfig.php b/include/Streamer/osTicket/Configuration/BitfinexStreamerPluginConfig.php index ece7d03..429d87e 100644 --- a/include/Streamer/osTicket/Configuration/BitfinexStreamerPluginConfig.php +++ b/include/Streamer/osTicket/Configuration/BitfinexStreamerPluginConfig.php @@ -133,12 +133,66 @@ public function renderCustomConfig() { $this->renderConfig(); } + /** + * {@inheritDoc} + */ + public function saveConfig() { + try { + $form = $this->getForm(); + + if ($form instanceof \Form && $form->isValid() === TRUE) { + $errors = []; + $values = $form->getClean(); + + $has_requirements = \is_array($values) === TRUE + && $this->pre_save($values, $errors) === TRUE + && \count($errors += $form->errors()) === 0; + + if ($has_requirements) { + $data = []; + + foreach ($values as $name => $value) { + $field = $form->getField($name); + + if ($field instanceof \FormField) { + try { + $data[$name] = $field->to_database($value); + } + + catch (\FieldUnchanged $ex) { + unset($data[$name]); + } + } + } + + return $this->updateAll($data); + } + } + } + + catch (\Throwable $ex) { + } + + return FALSE; + } + /** * {@inheritDoc} */ public function saveCustomConfig() { - $errors = []; - return $this->commitForm($errors); + if (($success = $this->saveConfig()) === TRUE) { + if (empty($GLOBALS['msg']) === TRUE) { + $GLOBALS['msg'] = \__('Instance Updated Successfully'); + } + } + + else { + if (empty($GLOBALS['errors']['err']) === TRUE) { + $GLOBALS['errors']['err'] = \__('Unable to update Plugin Instance.'); + } + } + + return $success; } /** From e9ba00b9a53eac418ecac14ff9c145a69488d2f5 Mon Sep 17 00:00:00 2001 From: Davide Scola Date: Thu, 30 Mar 2023 14:33:48 +0000 Subject: [PATCH 6/6] loading of configuration options takes into account the plugin instance --- .../HasConfigurationManagementTrait.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/include/Streamer/osTicket/Configuration/HasConfigurationManagementTrait.php b/include/Streamer/osTicket/Configuration/HasConfigurationManagementTrait.php index e0119b5..1e90ffb 100644 --- a/include/Streamer/osTicket/Configuration/HasConfigurationManagementTrait.php +++ b/include/Streamer/osTicket/Configuration/HasConfigurationManagementTrait.php @@ -127,18 +127,27 @@ protected static function getConfigAsTertiumNonDaturField(string $name) : Tertiu * @phpstan-return T */ protected static function getConfigAsFormField(\FormField $field, string $name) : \FormField { - $plugin = \PluginManager::getInstance( - \sprintf('plugins/%s', \basename(\BitfinexStreamerPlugin::PLUGIN_DIR)) - ); + try { + $plugin = \PluginManager::getInstance( + \sprintf('plugins/%s', \basename(\BitfinexStreamerPlugin::PLUGIN_DIR)) + ); + + if ($plugin instanceof \Plugin) { + if (\method_exists($plugin, 'getActiveInstances') === TRUE) { + $plugin = $plugin->getActiveInstances()->one(); + } - if ($plugin instanceof \Plugin) { - $config = $plugin->getConfig(); + $config = $plugin->getConfig(); - if ($config instanceof \PluginConfig) { - $field->setValue($config->get($name)); + if ($config instanceof \PluginConfig) { + $field->setValue($config->get($name)); + } } } + catch (\Throwable $ex) { + } + return $field; }