From 69b11d83ccbe21252b3e4df259bf5a7c45cdef52 Mon Sep 17 00:00:00 2001 From: Jack Wilkinson Date: Mon, 30 Dec 2024 13:47:22 +0000 Subject: [PATCH] Refactored stuff --- modules/system/classes/UpdateManager.php | 1 - .../system/classes/extensions/PluginBase.php | 1 - .../classes/extensions/PluginManager.php | 51 +++++++++++++++-- .../{plugins => }/PluginVersionManager.php | 6 +- .../system/classes/extensions/Preserver.php | 12 ++-- .../PluginManagerDeprecatedMethodsTrait.php | 55 ------------------- .../system/console/create/CreateMigration.php | 2 +- .../tests/bootstrap/PluginManagerTestCase.php | 2 +- .../core => traits}/InteractsWithZip.php | 2 +- 9 files changed, 60 insertions(+), 72 deletions(-) rename modules/system/classes/extensions/{plugins => }/PluginVersionManager.php (99%) delete mode 100644 modules/system/classes/extensions/plugins/PluginManagerDeprecatedMethodsTrait.php rename modules/system/{classes/core => traits}/InteractsWithZip.php (96%) diff --git a/modules/system/classes/UpdateManager.php b/modules/system/classes/UpdateManager.php index 6d79d299b..62c8f6783 100644 --- a/modules/system/classes/UpdateManager.php +++ b/modules/system/classes/UpdateManager.php @@ -10,7 +10,6 @@ use Illuminate\Support\Facades\App; use System\Classes\Core\MarketPlaceApi; use System\Classes\Extensions\PluginManager; -use System\Classes\Extensions\Plugins\PluginVersionManager; use System\Helpers\Cache as CacheHelper; use System\Models\Parameter; use Winter\Storm\Exception\ApplicationException; diff --git a/modules/system/classes/extensions/PluginBase.php b/modules/system/classes/extensions/PluginBase.php index f32a786d6..8f80383c4 100644 --- a/modules/system/classes/extensions/PluginBase.php +++ b/modules/system/classes/extensions/PluginBase.php @@ -7,7 +7,6 @@ use Illuminate\Console\Scheduling\Schedule; use Illuminate\Support\ServiceProvider as ServiceProviderBase; use ReflectionClass; -use System\Classes\Extensions\Plugins\PluginVersionManager; use System\Classes\VersionYamlProcessor; use Winter\Storm\Exception\SystemException; use Winter\Storm\Foundation\Application; diff --git a/modules/system/classes/extensions/PluginManager.php b/modules/system/classes/extensions/PluginManager.php index d350a1dbb..bf96254cf 100644 --- a/modules/system/classes/extensions/PluginManager.php +++ b/modules/system/classes/extensions/PluginManager.php @@ -16,8 +16,6 @@ use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use System\Classes\ComposerManager; -use System\Classes\Extensions\Plugins\PluginManagerDeprecatedMethodsTrait; -use System\Classes\Extensions\Plugins\PluginVersionManager; use System\Classes\Extensions\Source\ExtensionSource; use System\Classes\SettingsManager; use System\Models\PluginVersion; @@ -39,8 +37,6 @@ */ class PluginManager extends ExtensionManager implements ExtensionManagerInterface { - use PluginManagerDeprecatedMethodsTrait; - public const EXTENSION_NAME = 'plugin'; /** @@ -1375,4 +1371,51 @@ public function resolveIdentifier(ExtensionSource|WinterExtension|string $extens return null; } + + /** + * Returns an array with all enabled plugins + * + * @return array [$code => $pluginObj] + * @deprecated + */ + public function getPlugins(): array + { + return $this->list(); + } + + /** + * Tears down a plugin's database tables and rebuilds them. + * @deprecated + */ + public function refreshPlugin(string $id): void + { + $this->refresh($id); + } + + /** + * Completely roll back and delete a plugin from the system. + * @deprecated + */ + public function deletePlugin(string $id): void + { + $this->uninstall($id); + } + + /** + * Disables the provided plugin using the provided flag (defaults to static::DISABLED_BY_USER) + * @deprecated + */ + public function disablePlugin(PluginBase|string $plugin, string|bool $flag = self::DISABLED_BY_USER): bool + { + return $this->disable($plugin, $flag); + } + + /** + * Enables the provided plugin using the provided flag (defaults to static::DISABLED_BY_USER) + * @deprecated + */ + public function enablePlugin(PluginBase|string $plugin, $flag = self::DISABLED_BY_USER): bool + { + return $this->enable($plugin, $flag); + } } diff --git a/modules/system/classes/extensions/plugins/PluginVersionManager.php b/modules/system/classes/extensions/PluginVersionManager.php similarity index 99% rename from modules/system/classes/extensions/plugins/PluginVersionManager.php rename to modules/system/classes/extensions/PluginVersionManager.php index 1a9879b58..39ef01500 100644 --- a/modules/system/classes/extensions/plugins/PluginVersionManager.php +++ b/modules/system/classes/extensions/PluginVersionManager.php @@ -1,18 +1,16 @@ 'themes', ]; + /** + * @throws ApplicationException + */ public function store(WinterExtension $extension): string { $this->ensureDirectory(static::ROOT_PATH); @@ -34,15 +38,15 @@ public function store(WinterExtension $extension): string '%s%4$s%s%4$s%s', static::ROOT_PATH, $type, - $extension->extensionIdentifier(), + $extension->getIdentifier(), DIRECTORY_SEPARATOR ); $this->ensureDirectory($extensionArchiveDir); return $this->packArchive( - $extension->extensionPath(), - Storage::path($extensionArchiveDir . DIRECTORY_SEPARATOR . $extension->extensionVersion()) + $extension->getPath(), + Storage::path($extensionArchiveDir . DIRECTORY_SEPARATOR . $extension->getVersion()) ); } diff --git a/modules/system/classes/extensions/plugins/PluginManagerDeprecatedMethodsTrait.php b/modules/system/classes/extensions/plugins/PluginManagerDeprecatedMethodsTrait.php deleted file mode 100644 index 21cf8a082..000000000 --- a/modules/system/classes/extensions/plugins/PluginManagerDeprecatedMethodsTrait.php +++ /dev/null @@ -1,55 +0,0 @@ - $pluginObj] - * @deprecated - */ - public function getPlugins(): array - { - return $this->list(); - } - - /** - * Tears down a plugin's database tables and rebuilds them. - * @deprecated - */ - public function refreshPlugin(string $id): void - { - $this->refresh($id); - } - - /** - * Completely roll back and delete a plugin from the system. - * @deprecated - */ - public function deletePlugin(string $id): void - { - $this->uninstall($id); - } - - /** - * Disables the provided plugin using the provided flag (defaults to static::DISABLED_BY_USER) - * @deprecated - */ - public function disablePlugin(PluginBase|string $plugin, string|bool $flag = self::DISABLED_BY_USER): bool - { - return $this->disable($plugin, $flag); - } - - /** - * Enables the provided plugin using the provided flag (defaults to static::DISABLED_BY_USER) - * @deprecated - */ - public function enablePlugin(PluginBase|string $plugin, $flag = self::DISABLED_BY_USER): bool - { - return $this->enable($plugin, $flag); - } -} diff --git a/modules/system/console/create/CreateMigration.php b/modules/system/console/create/CreateMigration.php index fcf313d9f..ba3887590 100644 --- a/modules/system/console/create/CreateMigration.php +++ b/modules/system/console/create/CreateMigration.php @@ -3,7 +3,7 @@ namespace System\Console\Create; use InvalidArgumentException; -use System\Classes\Extensions\Plugins\PluginVersionManager; +use System\Classes\Extensions\PluginVersionManager; use System\Console\BaseScaffoldCommand; use Winter\Storm\Database\Model; use Winter\Storm\Support\Str; diff --git a/modules/system/tests/bootstrap/PluginManagerTestCase.php b/modules/system/tests/bootstrap/PluginManagerTestCase.php index bb064795b..af33a7cd0 100644 --- a/modules/system/tests/bootstrap/PluginManagerTestCase.php +++ b/modules/system/tests/bootstrap/PluginManagerTestCase.php @@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; use System\Classes\Extensions\PluginManager; -use System\Classes\Extensions\Plugins\PluginVersionManager; +use System\Classes\Extensions\PluginVersionManager; use System\Classes\UpdateManager; use Winter\Storm\Database\Model as ActiveRecord; diff --git a/modules/system/classes/core/InteractsWithZip.php b/modules/system/traits/InteractsWithZip.php similarity index 96% rename from modules/system/classes/core/InteractsWithZip.php rename to modules/system/traits/InteractsWithZip.php index 7e71f807b..60f72b4ee 100644 --- a/modules/system/classes/core/InteractsWithZip.php +++ b/modules/system/traits/InteractsWithZip.php @@ -1,6 +1,6 @@