| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | use AcyMailing\Core\AcymClass; |
| 6 | 6 | |
| 7 | 7 | class PluginClass extends AcymClass |
| 8 | 8 | { |
| 9 | - private $plugins; | |
| 9 | + private array $plugins = []; | |
| 10 | 10 | |
| 11 | 11 | public function __construct() |
| 12 | 12 | { |
| 13 | 13 | parent::__construct(); |
| @@ -13,9 +13,12 @@ | ||
| 13 | 13 | parent::__construct(); |
| 14 | 14 | |
| 15 | 15 | $this->table = 'plugin'; |
| 16 | 16 | $this->pkey = 'id'; |
| 17 | + } | |
| 17 | 18 | |
| 19 | + public function getPlugins(): array | |
| 20 | + { | |
| 18 | 21 | global $acymPluginByFolderName; |
| 19 | 22 | if (empty($acymPluginByFolderName)) { |
| 20 | 23 | $acymPluginByFolderName = $this->getAll('folder_name'); |
| 21 | 24 | } |
| @@ -20,21 +23,20 @@ | ||
| 20 | 23 | $acymPluginByFolderName = $this->getAll('folder_name'); |
| 21 | 24 | } |
| 22 | 25 | |
| 23 | 26 | $this->plugins = $acymPluginByFolderName; |
| 24 | - } | |
| 25 | 27 | |
| 26 | - public function getPlugins() | |
| 27 | - { | |
| 28 | 28 | return $this->plugins; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function getOnePluginByFolderName(string $folderName) | |
| 31 | + public function getOnePluginByFolderName(string $folderName): ?object | |
| 32 | 32 | { |
| 33 | - return $this->plugins[$folderName] ?? null; | |
| 33 | + $plugins = $this->getPlugins(); | |
| 34 | + | |
| 35 | + return $plugins[$folderName] ?? null; | |
| 34 | 36 | } |
| 35 | 37 | |
| 36 | - public function getNotUptoDatePlugins() | |
| 38 | + public function getNotUptoDatePlugins(): array | |
| 37 | 39 | { |
| 38 | 40 | $result = acym_loadResult('SHOW TABLES LIKE "%_acym_plugin"'); |
| 39 | 41 | if (empty($result)) { |
| 40 | 42 | return []; |
| @@ -42,23 +44,18 @@ | ||
| 42 | 44 | |
| 43 | 45 | return acym_loadResultArray('SELECT folder_name FROM #__acym_plugin WHERE uptodate = 0'); |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | - public function getSettings($addon) | |
| 48 | + public function addIntegrationIfMissing(object $plugin): void | |
| 47 | 49 | { |
| 48 | - $settings = acym_loadResult('SELECT settings FROM #__acym_plugin WHERE folder_name = '.acym_escapeDB($addon)); | |
| 49 | - | |
| 50 | - return empty($settings) ? [] : json_decode($settings, true); | |
| 51 | - } | |
| 52 | - | |
| 53 | - public function addIntegrationIfMissing($plugin) | |
| 54 | - { | |
| 55 | 50 | if (empty($plugin->pluginDescription->name)) { |
| 56 | 51 | return; |
| 57 | 52 | } |
| 58 | 53 | |
| 59 | - $data = $this->plugins[$plugin->name] ?? null; | |
| 54 | + $plugins = $this->getPlugins(); | |
| 55 | + $data = $plugins[$plugin->name] ?? null; | |
| 60 | 56 | |
| 57 | + // Prepare the missing entry in the db | |
| 61 | 58 | $newPlugin = new \stdClass(); |
| 62 | 59 | $newPlugin->title = $plugin->pluginDescription->name; |
| 63 | 60 | $newPlugin->folder_name = $plugin->name; |
| 64 | 61 | $newPlugin->version = '1.0'; |
| @@ -77,9 +74,11 @@ | ||
| 77 | 74 | if ($data->type !== 'ADDON') { |
| 78 | 75 | return; |
| 79 | 76 | } |
| 80 | 77 | |
| 78 | + // The integration has just been activated and the old addon was installed | |
| 81 | 79 | |
| 80 | + // Remove the old addon's files | |
| 82 | 81 | if (file_exists(ACYM_ADDONS_FOLDER_PATH.$plugin->name)) { |
| 83 | 82 | acym_deleteFolder(ACYM_ADDONS_FOLDER_PATH.$plugin->name); |
| 84 | 83 | } |
| 85 | 84 | } |
| @@ -86,9 +85,9 @@ | ||
| 86 | 85 | |
| 87 | 86 | $this->save($newPlugin); |
| 88 | 87 | } |
| 89 | 88 | |
| 90 | - public function enable($folderName) | |
| 89 | + public function enable(string $folderName): void | |
| 91 | 90 | { |
| 92 | 91 | $plugin = $this->getOnePluginByFolderName($folderName); |
| 93 | 92 | if (empty($plugin)) return; |
| 94 | 93 | |
| @@ -95,9 +94,9 @@ | ||
| 95 | 94 | $plugin->active = 1; |
| 96 | 95 | $this->save($plugin); |
| 97 | 96 | } |
| 98 | 97 | |
| 99 | - public function disable($folderName) | |
| 98 | + public function disable(string $folderName): void | |
| 100 | 99 | { |
| 101 | 100 | $plugin = $this->getOnePluginByFolderName($folderName); |
| 102 | 101 | if (empty($plugin)) return; |
| 103 | 102 | |
| @@ -104,22 +103,22 @@ | ||
| 104 | 103 | $plugin->active = 0; |
| 105 | 104 | $this->save($plugin); |
| 106 | 105 | } |
| 107 | 106 | |
| 108 | - public function deleteByFolderName($folderName) | |
| 107 | + public function deleteByFolderName(string $folderName): void | |
| 109 | 108 | { |
| 110 | 109 | $plugin = $this->getOnePluginByFolderName($folderName); |
| 111 | 110 | if (empty($plugin)) return; |
| 112 | 111 | |
| 113 | - parent::delete($plugin->id); | |
| 112 | + parent::delete([$plugin->id]); | |
| 114 | 113 | } |
| 115 | 114 | |
| 116 | - public function updateAddon(string $addon) | |
| 115 | + public function updateAddon(string $addon): ?int | |
| 117 | 116 | { |
| 118 | 117 | $plugin = $this->getOnePluginByFolderName($addon); |
| 119 | 118 | |
| 120 | 119 | if (empty($plugin)) { |
| 121 | - return false; | |
| 120 | + return null; | |
| 122 | 121 | } |
| 123 | 122 | |
| 124 | 123 | $pluginClass = new PluginClass(); |
| 125 | 124 | $pluginClass->downloadAddon($addon); |
| @@ -128,22 +127,22 @@ | ||
| 128 | 127 | $pluginToSave->id = $plugin->id; |
| 129 | 128 | $pluginToSave->version = $plugin->latest_version; |
| 130 | 129 | $pluginToSave->uptodate = 1; |
| 131 | 130 | |
| 132 | - return $this->save($pluginToSave); | |
| 131 | + return (int)$this->save($pluginToSave); | |
| 133 | 132 | } |
| 134 | 133 | |
| 135 | - public function downloadAddon(string $name, bool $ajax = true) | |
| 134 | + public function downloadAddon(string $name, bool $ajax = true): ?string | |
| 136 | 135 | { |
| 137 | 136 | |
| 138 | - return true; | |
| 137 | + return null; | |
| 139 | 138 | } |
| 140 | 139 | |
| 141 | - private function handleError($error, $ajax) | |
| 140 | + private function handleError(string $error, bool $ajax): string | |
| 142 | 141 | { |
| 143 | 142 | if ($ajax) { |
| 144 | 143 | acym_sendAjaxResponse(acym_translation($error), [], false); |
| 145 | - } else { | |
| 146 | - return acym_translation($error); | |
| 147 | 144 | } |
| 145 | + | |
| 146 | + return acym_translation($error); | |
| 148 | 147 | } |
| 149 | 148 | } |