Skip to content

Commit

Permalink
Added wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxwilko committed Dec 30, 2024
1 parent 68721cf commit dd3fc6c
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 164 deletions.
2 changes: 1 addition & 1 deletion modules/system/classes/core/MarketPlaceApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function request(string $request, string $identifier): array
throw new ApplicationException('Invalid request option.');
}

return $this->api->fetch(
return $this->fetch(
$request,
[$request === static::REQUEST_PROJECT_DETAIL ? 'id' : 'name' => $identifier]
);
Expand Down
14 changes: 9 additions & 5 deletions modules/system/classes/extensions/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ public function update(WinterExtension|string|null $extension = null, bool $migr
$this->output->info('Migration table created');
}

if (!$migrationsOnly) {
if (!$migrationsOnly && !Config::get('cms.disableCoreUpdates')) {
foreach ($modules as $module) {
$extension = $this->get($module);
if (
!Config::get('cms.disableCoreUpdates')
&& ($composerPackage = Composer::getPackageNameByExtension($extension))
($composerPackage = Composer::getPackageNameByExtension($extension))
&& Composer::updateAvailable($composerPackage)
) {
$this->output->info(sprintf(
Expand Down Expand Up @@ -246,16 +245,21 @@ public function availableUpdates(WinterExtension|string|null $extension = null):
return $updates;
}

/**
* @param WinterExtension|string|null $extension
* @return array<string, WinterExtension>
* @throws ApplicationException
*/
protected function getModuleList(WinterExtension|string|null $extension = null): array
{
if (!$extension) {
return $this->list();
}

if (!($resolved = $this->resolveIdentifier($extension))) {
if (!($resolved = $this->resolve($extension))) {
throw new ApplicationException('Unable to locate extension');
}

return [$resolved];
return [$resolved->getIdentifier() => $resolved];
}
}
16 changes: 8 additions & 8 deletions modules/system/classes/extensions/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,20 +416,18 @@ public function rollback(WinterExtension|string|null $extension = null, ?string
* Completely roll back and delete a plugin from the system.
* @throws ApplicationException
*/
public function uninstall(WinterExtension|string|null $extension = null): ?bool
public function uninstall(WinterExtension|string|null $extension = null, bool $noRollback = false): ?bool
{
if (!($code = $this->resolveIdentifier($extension))) {
return null;
}

/*
* Rollback plugin
*/
$this->rollback($code);
// Rollback plugin
if (!$noRollback) {
$this->rollback($code);
}

/*
* Delete from file system
*/
// Delete from file system
if ($pluginPath = self::instance()->getPluginPath($code)) {
File::deleteDirectory($pluginPath);

Expand All @@ -440,6 +438,8 @@ public function uninstall(WinterExtension|string|null $extension = null): ?bool
$this->clearFlagCache();
}

$this->output->info('Deleted plugin: ' . $code);

return true;
}

Expand Down
109 changes: 0 additions & 109 deletions modules/system/classes/extensions/plugins/PluginUpdateManager.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Carbon\Carbon;
use Illuminate\Console\View\Components\Error;
use Illuminate\Console\View\Components\Info;
use Illuminate\Console\View\Components\Task;
use Illuminate\Support\Facades\File;
use System\Classes\Extensions\PluginBase;
Expand Down
9 changes: 7 additions & 2 deletions modules/system/console/JaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

namespace System\Console;

use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Redirect;
use Symfony\Component\Console\Output\BufferedOutput;
use System\Classes\Core\MarketPlaceApi;
use System\Classes\Extensions\ModuleManager;
use System\Classes\Extensions\PluginManager;
use System\Classes\Extensions\Preserver;
use System\Classes\Extensions\Source\ComposerSource;
use System\Classes\Extensions\Source\ExtensionSource;
use System\Classes\Extensions\Source\LocalSource;
use System\Classes\Packager\Composer;
use System\Classes\UpdateManager;
use Winter\Storm\Packager\Composer;
use Winter\Storm\Console\Command;
use Winter\Storm\Exception\ApplicationException;
use Winter\Storm\Support\Facades\Flash;
use function Termwind\render;
use function Termwind\renderUsing;

Expand All @@ -38,7 +43,7 @@ class JaxTest extends Command
*/
public function handle(): int
{

return 0;
}
}
5 changes: 2 additions & 3 deletions modules/system/console/PluginDisable.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ class PluginDisable extends Command
public function handle()
{
$pluginName = $this->getPluginIdentifier();
$pluginManager = PluginManager::instance();

// Disable this plugin
$pluginManager->disablePlugin($pluginName);
PluginManager::instance()->disable($pluginName);

$this->output->writeln(sprintf('<info>%s:</info> disabled.', $pluginName));
$this->output->info($pluginName . ': disabled.');
}
}
5 changes: 2 additions & 3 deletions modules/system/console/PluginEnable.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ class PluginEnable extends Command
public function handle()
{
$pluginName = $this->getPluginIdentifier();
$pluginManager = PluginManager::instance();

// Enable this plugin
$pluginManager->enablePlugin($pluginName);
PluginManager::instance()->enable($pluginName);

$this->output->writeln(sprintf('<info>%s:</info> enabled.', $pluginName));
$this->output->info($pluginName . ': enabled.');
}
}
5 changes: 4 additions & 1 deletion modules/system/console/PluginList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableSeparator;
use System\Classes\Extensions\PluginManager;
use System\Models\PluginVersion;
use Winter\Storm\Console\Command;

Expand Down Expand Up @@ -34,6 +35,7 @@ class PluginList extends Command
*/
public function handle()
{
$manager = PluginManager::instance();
$allPlugins = PluginVersion::all();
$pluginsCount = count($allPlugins);

Expand All @@ -47,11 +49,12 @@ public function handle()
$rows[] = [
$plugin->code,
$plugin->version,
$manager->findByIdentifier($plugin->code)->getComposerPackageName(),
(!$plugin->is_frozen) ? '<info>Yes</info>': '<fg=red>No</>',
(!$plugin->is_disabled) ? '<info>Yes</info>': '<fg=red>No</>',
];
}

$this->table(['Plugin name', 'Version', 'Updates enabled', 'Plugin enabled'], $rows);
$this->table(['Plugin name', 'Version', 'Composer Package', 'Updates enabled', 'Plugin enabled'], $rows);
}
}
11 changes: 2 additions & 9 deletions modules/system/console/PluginRefresh.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace System\Console;

use System\Classes\Extensions\PluginManager;
use Winter\Storm\Console\Command;
use System\Classes\UpdateManager;

Expand Down Expand Up @@ -48,15 +49,7 @@ public function handle(): int
return 1;
}

// Set the UpdateManager output stream to the CLI
$manager = UpdateManager::instance()->setNotesOutput($this->output);

// Rollback the plugin
$manager->rollbackPlugin($pluginName);

// Reinstall the plugin
$this->output->writeln('<info>Reinstalling plugin...</info>');
$manager->updatePlugin($pluginName);
PluginManager::instance()->refresh($pluginName);

return 0;
}
Expand Down
20 changes: 4 additions & 16 deletions modules/system/console/PluginRemove.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use System\Classes\Extensions\PluginManager;
use System\Classes\UpdateManager;
use Winter\Storm\Console\Command;
use Winter\Storm\Exception\ApplicationException;

/**
* Console command to remove a plugin.
Expand Down Expand Up @@ -44,13 +45,14 @@ class PluginRemove extends Command

/**
* Execute the console command.
* @throws ApplicationException
*/
public function handle(): int
{
$pluginName = $this->getPluginIdentifier();
$pluginManager = PluginManager::instance();

$confirmQuestion = sprintf('This will remove the files for the "%s" plugin.', $pluginName);

if (!$this->option('no-rollback')) {
$confirmQuestion = sprintf('This will remove the database tables and files for the "%s" plugin.', $pluginName);
}
Expand All @@ -62,21 +64,7 @@ public function handle(): int
return 1;
}

if (!$this->option('no-rollback')) {
/*
* Rollback plugin
*/
$manager = UpdateManager::instance()->setNotesOutput($this->output);
$manager->rollbackPlugin($pluginName);
}

/*
* Delete from file system
*/
if ($pluginPath = $pluginManager->getPluginPath($pluginName)) {
File::deleteDirectory($pluginPath);
$this->output->writeln(sprintf('<info>Deleted: %s</info>', $pluginPath));
}
PluginManager::instance()->uninstall($pluginName, $this->option('no-rollback'));

return 0;
}
Expand Down
Loading

0 comments on commit dd3fc6c

Please sign in to comment.