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 be09f6c commit d9830f3
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 121 deletions.
18 changes: 17 additions & 1 deletion modules/cms/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
use Illuminate\Support\Facades\View;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use System\Classes\CombineAssets;
use System\Classes\Extensions\WinterExtension;
use System\Classes\MarkupManager;
use System\Classes\SettingsManager;
use Twig\Cache\FilesystemCache as TwigCacheFilesystem;
use Winter\Storm\Support\Facades\Event;
use Winter\Storm\Support\Facades\Url;
use Winter\Storm\Support\ModuleServiceProvider;

class ServiceProvider extends ModuleServiceProvider
class ServiceProvider extends ModuleServiceProvider implements WinterExtension
{
/**
* Register the service provider.
Expand Down Expand Up @@ -477,4 +478,19 @@ protected function registerHalcyonModels()
];
});
}

public function getPath(): string
{
return __DIR__;
}

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

public function getIdentifier(): string
{
return 'Cms';
}
}
44 changes: 2 additions & 42 deletions modules/cms/classes/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,52 +715,12 @@ public function __isset($key)
return false;
}

public function extensionInstall(): static
{
// TODO: Implement extensionInstall() method.
}

public function extensionUninstall(): static
{
// TODO: Implement extensionUninstall() method.
}

public function extensionEnable(): static
{
// TODO: Implement extensionEnable() method.
}

public function extensionDisable(): static
{
// TODO: Implement extensionDisable() method.
}

public function extensionRollback(): static
{
// TODO: Implement extensionRollback() method.
}

public function extensionRefresh(): static
{
// TODO: Implement extensionRefresh() method.
}

public function extensionUpdate(): static
{
// TODO: Implement extensionUpdate() method.
}

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

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

public function extensionIdentifier(): string
public function getIdentifier(): string
{
// TODO: Implement extensionIdentifier() method.
}
Expand Down
2 changes: 1 addition & 1 deletion modules/cms/classes/ThemeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function disable(WinterExtension|string $extension, string|bool $flag = s
// TODO: Implement disable() method.
}

public function update(WinterExtension|string $extension): Theme
public function update(WinterExtension|string|null $extension): Theme
{
// TODO: Implement update() method.
}
Expand Down
37 changes: 35 additions & 2 deletions modules/system/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use Illuminate\Support\Facades\View;
use System\Classes\CombineAssets;
use System\Classes\ErrorHandler;
use System\Classes\Extensions\ModuleManager;
use System\Classes\Extensions\PluginManager;
use System\Classes\Extensions\WinterExtension;
use System\Classes\FileManifest;
use System\Classes\MailManager;
use System\Classes\MarkupManager;
Expand All @@ -26,6 +28,7 @@
use System\Twig\Engine as TwigEngine;
use Twig\Environment;
use Twig\Extension\CoreExtension;
use Winter\Storm\Console\Command;
use Winter\Storm\Exception\SystemException;
use Winter\Storm\Router\Helper as RouterHelper;
use Winter\Storm\Support\ClassLoader;
Expand All @@ -34,14 +37,14 @@
use Winter\Storm\Support\Facades\Validator;
use Winter\Storm\Support\ModuleServiceProvider;

class ServiceProvider extends ModuleServiceProvider
class ServiceProvider extends ModuleServiceProvider implements WinterExtension
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
public function register(): void
{
parent::register();

Expand Down Expand Up @@ -90,6 +93,18 @@ public function register()
$this->registerBackendReportWidgets();
$this->registerBackendSettings();
}

/*
* Console specific
*/
if ($this->app->runningInConsole()) {
Command::extend(function (Command $command) {
$command->bindEvent('beforeRun', function () use ($command) {
ModuleManager::instance()->setOutput($command->getOutput());
PluginManager::instance()->setOutput($command->getOutput());
});
});
}
}

/**
Expand Down Expand Up @@ -342,6 +357,9 @@ protected function registerConsole()
$this->registerConsoleCommand('npm.install', Console\Asset\Npm\NpmInstall::class);
$this->registerConsoleCommand('npm.update', Console\Asset\Npm\NpmUpdate::class);
$this->registerConsoleCommand('npm.version', Console\Asset\Npm\NpmVersion::class);

// @TODO: remove
$this->registerConsoleCommand('jax.test', Console\JaxTest::class);
}

/*
Expand Down Expand Up @@ -672,4 +690,19 @@ protected function registerGlobalViewVars()
{
View::share('appName', Config::get('app.name'));
}

public function getPath(): string
{
return __DIR__;
}

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

public function getIdentifier(): string
{
return 'System';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function enable(WinterExtension|string $extension, string|bool $flag = se

public function disable(WinterExtension|string $extension, string|bool $flag = self::DISABLED_BY_USER): mixed;

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

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

Expand Down
122 changes: 116 additions & 6 deletions modules/system/classes/extensions/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,49 @@

namespace System\Classes\Extensions;

use Illuminate\Console\OutputStyle;
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Support\Facades\App;
use System\Classes\Extensions\Source\ExtensionSource;
use System\Classes\UpdateManager;
use System\Helpers\Cache as CacheHelper;
use System\Models\Parameter;
use System\ServiceProvider;
use Winter\Storm\Exception\ApplicationException;
use Winter\Storm\Support\Facades\Config;

class ModuleManager implements ExtensionManagerInterface
class ModuleManager extends ExtensionManager implements ExtensionManagerInterface
{
protected Migrator $migrator;
protected DatabaseMigrationRepository $repository;

protected function init(): void
{
$this->migrator = App::make('migrator');

$this->migrator->setOutput($this->output);

$this->repository = App::make('migration.repository');
}

public function setOutput(OutputStyle $output): static
{
$this->output = $output;

$this->migrator->setOutput($this->output);

return $this;
}

public function list(): array
{
// TODO: Implement list() method.
return Config::get('cms.loadModules', []);
}

public function create(string $extension): WinterExtension
{
// TODO: Implement create() method.
throw new ApplicationException('Support for creating extensions needs implementing');
}

public function install(WinterExtension|ExtensionSource|string $extension): WinterExtension
Expand All @@ -31,9 +62,51 @@ public function disable(WinterExtension|string $extension, string|bool $flag = s
// TODO: Implement disable() method.
}

public function update(WinterExtension|string $extension): mixed
public function update(WinterExtension|string|null $extension): ?bool
{
// TODO: Implement update() method.
$firstUp = UpdateManager::instance()->isSystemSetup();

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

$modules = $extension
? [$resolved->getIdentifier()]
: $this->list();

if ($firstUp) {
$this->repository->createRepository();
$this->output->info('Migration table created');
}

foreach ($modules as $module) {
$this->output->info(sprintf('<info>Migrating %s module...</info>', $module));
$this->migrator->run(base_path() . '/modules/' . strtolower($module) . '/database/migrations');
}

if ($firstUp) {
$className = '\\' . $module . '\Database\Seeds\DatabaseSeeder';
if (class_exists($className)) {
$this->output->info(sprintf('<info>Seeding %s module...</info>', $module));

$seeder = App::make($className);
$return = $seeder->run();

if ($return && (is_string($return) || is_array($return))) {
$return = is_string($return) ? [$return] : $return;
foreach ($return as $item) {
$this->output->info(sprintf('[%s]: %s', $className, $item));
}
}

$this->output->info(sprintf('Seeded %s', $module));
}
}

Parameter::set('system::update.count', 0);
CacheHelper::clear();

return true;
}

public function refresh(WinterExtension|string $extension): mixed
Expand All @@ -58,6 +131,43 @@ public function isInstalled(WinterExtension|ExtensionSource|string $extension):

public function get(WinterExtension|ExtensionSource|string $extension): ?WinterExtension
{
// TODO: Implement get() method.
if ($extension instanceof WinterExtension) {
return $extension;
}

// @TODO: improve
try {
if (is_string($extension) && ($resolved = App::get($extension . '\\ServiceProvider'))) {
return $resolved;
}
} catch (\Throwable $e) {
// $this->output->error($e->getMessage());
}

try {
return App::get(ucfirst($extension) . '\\ServiceProvider');
} catch (\Throwable $e) {
$this->output->error($e->getMessage());
return null;
}
}

public function availableUpdates(WinterExtension|string|null $extension = null): ?array
{
// TODO: Implement availableUpdates() method.
}

public function tearDown(): static
{
// TODO: Implement tearDown() method.
}

protected function resolve(WinterExtension|ExtensionSource|string $extension): ?WinterExtension
{
if ($extension instanceof WinterExtension) {
return $extension;
}

return $this->get($extension instanceof ExtensionSource ? $extension->getCode() : $extension);
}
}
Loading

0 comments on commit d9830f3

Please sign in to comment.