Skip to content

Commit

Permalink
Added wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxwilko committed Dec 19, 2024
1 parent 6c4bbe8 commit 5d705b9
Show file tree
Hide file tree
Showing 16 changed files with 509 additions and 53 deletions.
15 changes: 15 additions & 0 deletions modules/cms/classes/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,4 +749,19 @@ public function extensionUpdate(): static
{
// TODO: Implement extensionUpdate() method.
}

public function extensionPath(): string
{
// TODO: Implement extensionPath() method.
}

public function extensionVersion(): string
{
// TODO: Implement extensionVersion() method.
}

public function extensionIdentifier(): string
{
// TODO: Implement extensionIdentifier() method.
}
}
2 changes: 1 addition & 1 deletion modules/system/classes/UpdateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Illuminate\Support\Facades\App;
use System\Classes\Core\MarketPlaceApi;
use System\Classes\Extensions\PluginManager;
use System\Classes\Extensions\Plugins\VersionManager;
use System\Classes\Extensions\Plugins\PluginVersionManager;
use System\Helpers\Cache as CacheHelper;
use System\Models\Parameter;
use Winter\Storm\Exception\ApplicationException;
Expand Down
9 changes: 9 additions & 0 deletions modules/system/classes/core/InteractsWithZip.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ public function extractArchive(string $archive, string $destination): void

@unlink($archive);
}

public function packArchive(string $src, string $destination): string
{
if (!Zip::make($destination, $src)) {
throw new ApplicationException(Lang::get('system::lang.zip.pack_failed', ['file' => $src]));
}

return $destination;
}
}
23 changes: 11 additions & 12 deletions modules/system/classes/core/UpdateManagerPluginInstallerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function mapPluginReplacements(): array
throw new ApplicationException(Lang::get('system::lang.plugins.replace.multi_install_error'));
}
foreach ($replaces as $replace) {
$this->pluginManager->getVersionManager()->replacePlugin($plugin, $replace);
$this->pluginManager->versionManager()->replacePlugin($plugin, $replace);
}
}

Expand Down Expand Up @@ -55,21 +55,20 @@ public function generatePluginReplacementNotices(): static
return $this;
}


/**
* Runs update on a single plugin
*/
public function updatePlugin(string $name): static
{
// Update the plugin database and version
if (!($plugin = $this->pluginManager->findByIdentifier($name))) {
$this->message($this, sprintf('Unable to find plugin %s', $name));
$this->pluginManager->getOutput()->info(sprintf('Unable to find plugin %s', $name));
return $this;
}

$this->message($this, sprintf('<info>Migrating %s (%s) plugin...</info>', Lang::get($plugin->pluginDetails()['name']), $name));
$this->pluginManager->getOutput()->info(sprintf('<info>Migrating %s (%s) plugin...</info>', Lang::get($plugin->pluginDetails()['name']), $name));

$this->pluginManager->getVersionManager()->updatePlugin($plugin);
$this->pluginManager->versionManager()->updatePlugin($plugin);

return $this;
}
Expand All @@ -84,25 +83,25 @@ public function rollbackPlugin(string $name, string $stopOnVersion = null): stat
{
// Remove the plugin database and version
if (!($plugin = $this->pluginManager->findByIdentifier($name))
&& $this->pluginManager->getVersionManager()->purgePlugin($name)
&& $this->pluginManager->versionManager()->purgePlugin($name)
) {
$this->message($this, '%s purged from database', $name);
$this->pluginManager->getOutput()->info(sprintf('%s purged from database', $name));
return $this;
}

if ($stopOnVersion && !$this->pluginManager->getVersionManager()->hasDatabaseVersion($plugin, $stopOnVersion)) {
if ($stopOnVersion && !$this->pluginManager->versionManager()->hasDatabaseVersion($plugin, $stopOnVersion)) {
throw new ApplicationException(Lang::get('system::lang.updates.plugin_version_not_found'));
}

if ($this->pluginManager->getVersionManager()->removePlugin($plugin, $stopOnVersion, true)) {
$this->message($this, '%s rolled back', $name);
if ($this->pluginManager->versionManager()->removePlugin($plugin, $stopOnVersion, true)) {
$this->pluginManager->getOutput()->info(sprintf('%s rolled back', $name));

if ($currentVersion = $this->pluginManager->getVersionManager()->getCurrentVersion($plugin)) {
if ($currentVersion = $this->pluginManager->versionManager()->getCurrentVersion($plugin)) {
$this->message(
$this,
'Current Version: %s (%s)',
$currentVersion,
$this->pluginManager->getVersionManager()->getCurrentVersionNote($plugin)
$this->pluginManager->versionManager()->getCurrentVersionNote($plugin)
);
}

Expand Down
3 changes: 2 additions & 1 deletion modules/system/classes/extensions/ExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\Container\Container;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Termwind\Termwind;

abstract class ExtensionManager
{
Expand All @@ -31,7 +32,7 @@ public function getOutput(): OutputStyle
return $this->output;
}

public function termwind(string $component, ...$args): void
public function renderComponent(string $component, ...$args): void
{
(new $component($this->output))->render(...$args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ public function disable(WinterExtension|string $extension, string|bool $flag = s

public function update(WinterExtension|string $extension): mixed;

public function availableUpdates(WinterExtension|string|null $extension = null): ?array;

public function refresh(WinterExtension|string $extension): mixed;

public function rollback(WinterExtension|string $extension, string $targetVersion): mixed;

public function uninstall(WinterExtension|string $extension): mixed;

public function tearDown(): static;
}
20 changes: 16 additions & 4 deletions modules/system/classes/extensions/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@

namespace System\Classes\Extensions;

use System\Classes\Extensions\Source\ExtensionSource;

class ModuleManager implements ExtensionManagerInterface
{
public function list(): array
{
// TODO: Implement list() method.
}

public function create(): WinterExtension
public function create(string $extension): WinterExtension
{
// TODO: Implement create() method.
}

public function install(WinterExtension|string $extension): WinterExtension
public function install(WinterExtension|ExtensionSource|string $extension): WinterExtension
{
// TODO: Implement install() method.
}

public function enable(WinterExtension|string $extension): mixed
public function enable(WinterExtension|string $extension, string|bool $flag = self::DISABLED_BY_USER): mixed
{
// TODO: Implement enable() method.
}

public function disable(WinterExtension|string $extension): mixed
public function disable(WinterExtension|string $extension, string|bool $flag = self::DISABLED_BY_USER): mixed
{
// TODO: Implement disable() method.
}
Expand All @@ -48,4 +50,14 @@ public function uninstall(WinterExtension|string $extension): mixed
{
// TODO: Implement uninstall() method.
}

public function isInstalled(WinterExtension|ExtensionSource|string $extension): bool
{
// TODO: Implement isInstalled() method.
}

public function get(WinterExtension|ExtensionSource|string $extension): ?WinterExtension
{
// TODO: Implement get() method.
}
}
48 changes: 46 additions & 2 deletions modules/system/classes/extensions/PluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\ServiceProvider as ServiceProviderBase;
use ReflectionClass;
use System\Classes\Extensions\Plugins\VersionManager;
use System\Classes\Extensions\Plugins\PluginVersionManager;
use System\Classes\VersionYamlProcessor;
use Winter\Storm\Exception\SystemException;
use Winter\Storm\Foundation\Application;
Expand Down Expand Up @@ -38,6 +38,11 @@ abstract class PluginBase extends ServiceProviderBase implements WinterExtension
*/
protected $path;

/**
* @var ?array The composer package details for this plugin.
*/
protected ?array $composerPackage = null;

/**
* @var string The version of this plugin as reported by updates/version.yaml, access with getPluginVersion()
*/
Expand Down Expand Up @@ -446,7 +451,7 @@ public function getPluginVersion(): string

$versions = $this->getPluginVersions();
if (empty($versions)) {
return $this->version = VersionManager::NO_VERSION_VALUE;
return $this->version = PluginVersionManager::NO_VERSION_VALUE;
}

return $this->version = trim(key(array_slice($versions, -1, 1)));
Expand Down Expand Up @@ -490,6 +495,30 @@ public function getPluginVersions(bool $includeScripts = true): array
return $versions;
}

/**
* Set the composer package property for the plugin
*/
public function setComposerPackage(?array $package): void
{
$this->composerPackage = $package;
}

/**
* Get the composer package details
*/
public function getComposerPackage(): ?array
{
return $this->composerPackage;
}

/**
* Get the composer package name
*/
public function getComposerPackageName(): ?string
{
return $this->composerPackage['name'] ?? null;
}

/**
* Returns the requested plugin markdown file parsed into sanitized HTML
*/
Expand Down Expand Up @@ -576,4 +605,19 @@ public function extensionUpdate(): static
// TODO: Implement update() method.
return $this;
}

public function extensionVersion(): string
{
return $this->getPluginVersion();
}

public function extensionPath(): string
{
return $this->getPluginPath();
}

public function extensionIdentifier(): string
{
return strtolower($this->getPluginIdentifier());
}
}
Loading

0 comments on commit 5d705b9

Please sign in to comment.