Skip to content

Commit

Permalink
Added support for updating composer plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxwilko committed Dec 19, 2024
1 parent f250393 commit be09f6c
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions modules/system/classes/extensions/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class PluginManager extends ExtensionManager implements ExtensionManagerInterfac

/**
* Initializes the plugin manager
* @throws SystemException
*/
protected function init(): void
{
Expand Down Expand Up @@ -143,6 +144,10 @@ public function list(): array
);
}

/**
* @throws SystemException
* @throws ApplicationException
*/
public function create(string $extension): WinterExtension
{
$this->renderComponent(Info::class, sprintf('Running command `create:plugin %s`.', $extension));
Expand All @@ -166,6 +171,10 @@ public function create(string $extension): WinterExtension
return $this->findByIdentifier($extension);
}

/**
* @throws ApplicationException
* @throws SystemException
*/
public function install(ExtensionSource|WinterExtension|string $extension): WinterExtension
{
// Insure the in memory plugins match those on disk
Expand Down Expand Up @@ -278,28 +287,44 @@ public function update(WinterExtension|string $extension): ?bool

// Update the plugin database and version
if (!($plugin = $this->findByIdentifier($code))) {
$this->getOutput()->info(sprintf('Unable to find plugin %s', $code));
$this->output->info(sprintf('Unable to find plugin %s', $code));
return null;
}

$this->output->info(sprintf(
'Migrating %s (%s) plugin...',
Lang::get($plugin->pluginDetails()['name']),
$code
));
$pluginName = Lang::get($plugin->pluginDetails()['name']);

if (
($composerPackage = $plugin->getComposerPackageName())
!$this->getPluginRecord($plugin)->is_frozen
&& ($composerPackage = $plugin->getComposerPackageName())
&& Composer::updateAvailable($composerPackage)
) {
$this->output->info(sprintf(
'Performing composer update for %s (%s) plugin...',
$pluginName,
$code
));

Preserver::instance()->store($plugin);
$update = Composer::update(package: $composerPackage);
dd($update);
$update = Composer::update(package: $composerPackage, dryRun: true);

$versions = $update->getUpgraded()[$composerPackage] ?? null;

$this->output->{$versions ? 'info' : 'error'}(
$versions
? sprintf('Updated plugin %s (%s) from v%s => v%s', $pluginName, $code, $versions[0], $versions[1])
: sprintf('Failed to update plugin %s (%s)', $pluginName, $code)
);
} elseif (false /* Detect if market */) {
Preserver::instance()->store($plugin);
// @TODO: Update files from market
}

$this->output->info(sprintf(
'Migrating %s (%s) plugin...',
Lang::get($plugin->pluginDetails()['name']),
$code
));

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

return true;
Expand Down

0 comments on commit be09f6c

Please sign in to comment.