mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 21:11:55 +08:00
Post Composer Actions (Fixes #3)
This commit is contained in:
parent
19da2e9827
commit
e19c9ea67c
|
@ -7,6 +7,8 @@
|
|||
namespace SychO\PackageManager\Command;
|
||||
|
||||
use Composer\Console\Application;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use SychO\PackageManager\Event\FlarumUpdated;
|
||||
use SychO\PackageManager\Exception\ComposerUpdateFailedException;
|
||||
use SychO\PackageManager\LastUpdateCheck;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
|
@ -24,14 +26,21 @@ class MinorFlarumUpdateHandler
|
|||
*/
|
||||
protected $lastUpdateCheck;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @param Application $composer
|
||||
* @param LastUpdateCheck $lastUpdateCheck
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function __construct(Application $composer, LastUpdateCheck $lastUpdateCheck)
|
||||
public function __construct(Application $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||
$this->events = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,6 +69,10 @@ class MinorFlarumUpdateHandler
|
|||
|
||||
$this->lastUpdateCheck->forget('flarum/*', true);
|
||||
|
||||
$this->events->dispatch(
|
||||
new FlarumUpdated()
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace SychO\PackageManager\Command;
|
||||
|
||||
use Composer\Console\Application;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use SychO\PackageManager\Extension\Event\Removed;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
|
||||
|
@ -19,10 +25,16 @@ class RemoveExtensionHandler
|
|||
*/
|
||||
protected $extensions;
|
||||
|
||||
public function __construct(Application $composer, ExtensionManager $extensions,)
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
public function __construct(Application $composer, ExtensionManager $extensions, Dispatcher $events)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->extensions = $extensions;
|
||||
$this->events = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,5 +58,9 @@ class RemoveExtensionHandler
|
|||
]);
|
||||
|
||||
$this->composer->run($input, $output);
|
||||
|
||||
$this->events->dispatch(
|
||||
new Removed($extension)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace SychO\PackageManager\Command;
|
||||
|
||||
use Composer\Console\Application;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use SychO\PackageManager\Exception\ComposerRequireFailedException;
|
||||
use SychO\PackageManager\Extension\Event\Installed;
|
||||
use SychO\PackageManager\Extension\ExtensionUtils;
|
||||
use SychO\PackageManager\RequirePackageValidator;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
|
@ -27,11 +33,17 @@ class RequireExtensionHandler
|
|||
*/
|
||||
protected $validator;
|
||||
|
||||
public function __construct(Application $composer, ExtensionManager $extensions, RequirePackageValidator $validator)
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
public function __construct(Application $composer, ExtensionManager $extensions, RequirePackageValidator $validator, Dispatcher $events)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->extensions = $extensions;
|
||||
$this->validator = $validator;
|
||||
$this->events = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,6 +75,10 @@ class RequireExtensionHandler
|
|||
throw new ComposerRequireFailedException($command->package, $output->fetch());
|
||||
}
|
||||
|
||||
$this->events->dispatch(
|
||||
new Installed($extensionId)
|
||||
);
|
||||
|
||||
return ['id' => $extensionId];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ namespace SychO\PackageManager\Command;
|
|||
use Composer\Console\Application;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use SychO\PackageManager\Exception\ComposerUpdateFailedException;
|
||||
use SychO\PackageManager\Extension\Event\Updated;
|
||||
use SychO\PackageManager\UpdateExtensionValidator;
|
||||
use SychO\PackageManager\LastUpdateCheck;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
|
@ -37,12 +39,18 @@ class UpdateExtensionHandler
|
|||
*/
|
||||
protected $lastUpdateCheck;
|
||||
|
||||
public function __construct(Application $composer, ExtensionManager $extensions, UpdateExtensionValidator $validator, LastUpdateCheck $lastUpdateCheck)
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
public function __construct(Application $composer, ExtensionManager $extensions, UpdateExtensionValidator $validator, LastUpdateCheck $lastUpdateCheck, Dispatcher $events)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->extensions = $extensions;
|
||||
$this->validator = $validator;
|
||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||
$this->events = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,6 +83,10 @@ class UpdateExtensionHandler
|
|||
|
||||
$this->lastUpdateCheck->forget($extension->name);
|
||||
|
||||
$this->events->dispatch(
|
||||
new Updated($extension)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
8
extensions/package-manager/src/Event/FlarumUpdated.php
Normal file
8
extensions/package-manager/src/Event/FlarumUpdated.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace SychO\PackageManager\Event;
|
||||
|
||||
class FlarumUpdated
|
||||
{
|
||||
|
||||
}
|
|
@ -1,18 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace SychO\PackageManager\Extension\Event;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
use Flarum\Extension\Extension;
|
||||
namespace SychO\PackageManager\Extension\Event;
|
||||
|
||||
class Installed
|
||||
{
|
||||
/**
|
||||
* @var Extension
|
||||
* @var string
|
||||
*/
|
||||
public $extension;
|
||||
public $extensionId;
|
||||
|
||||
public function __construct(Extension $extension)
|
||||
public function __construct(string $extensionId)
|
||||
{
|
||||
$this->extension = $extension;
|
||||
$this->extensionId = $extensionId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace SychO\PackageManager\Extension\Event;
|
||||
|
||||
use Flarum\Extension\Extension;
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace SychO\PackageManager\Extension\Event;
|
||||
|
||||
use Flarum\Extension\Extension;
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace SychO\PackageManager\Extension;
|
||||
|
||||
class ExtensionUtils
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace SychO\PackageManager\Listener;
|
||||
|
||||
use Composer\Command\ClearCacheCommand;
|
||||
use Flarum\Database\Console\MigrateCommand;
|
||||
use Flarum\Foundation\Console\AssetsPublishCommand;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
|
||||
class PostUpdateListener
|
||||
{
|
||||
/**
|
||||
* @var ClearCacheCommand
|
||||
*/
|
||||
private $clearCache;
|
||||
|
||||
/**
|
||||
* @var AssetsPublishCommand
|
||||
*/
|
||||
private $publishAssets;
|
||||
|
||||
/**
|
||||
* @var MigrateCommand
|
||||
*/
|
||||
private $migrate;
|
||||
|
||||
public function __construct(ClearCacheCommand $clearCache, AssetsPublishCommand $publishAssets, MigrateCommand $migrate)
|
||||
{
|
||||
$this->clearCache = $clearCache;
|
||||
$this->publishAssets = $publishAssets;
|
||||
$this->migrate = $migrate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
$this->clearCache->run(new ArrayInput([]), new NullOutput());
|
||||
$this->migrate->run(new ArrayInput([]), new NullOutput());
|
||||
$this->publishAssets->run(new ArrayInput([]), new NullOutput());
|
||||
}
|
||||
}
|
|
@ -1,12 +1,25 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace SychO\PackageManager;
|
||||
|
||||
use Composer\Config;
|
||||
use Composer\Console\Application;
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\Frontend\RecompileFrontendAssets;
|
||||
use Flarum\Locale\LocaleManager;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use SychO\PackageManager\Event\FlarumUpdated;
|
||||
use SychO\PackageManager\Extension\Event\Installed;
|
||||
use SychO\PackageManager\Extension\Event\Updated;
|
||||
use SychO\PackageManager\Listener\PostUpdateListener;
|
||||
|
||||
class PackageManagerServiceProvider extends AbstractServiceProvider
|
||||
{
|
||||
|
@ -35,4 +48,26 @@ class PackageManagerServiceProvider extends AbstractServiceProvider
|
|||
|
||||
$this->container->alias(Application::class, 'flarum.composer');
|
||||
}
|
||||
|
||||
public function boot(Container $container)
|
||||
{
|
||||
/** @var Dispatcher $events */
|
||||
$events = $container->make('events');
|
||||
|
||||
$events->listen(
|
||||
[Updated::class],
|
||||
function (Updated $event) use ($container) {
|
||||
$recompile = new RecompileFrontendAssets(
|
||||
$container->make('flarum.assets.forum'),
|
||||
$container->make(LocaleManager::class)
|
||||
);
|
||||
$recompile->flush();
|
||||
|
||||
$container->make(ExtensionManager::class)->migrate($event->extension);
|
||||
$event->extension->copyAssetsTo($container->make('filesystem')->disk('flarum-assets'));
|
||||
}
|
||||
);
|
||||
|
||||
$events->listen(FlarumUpdated::class, PostUpdateListener::class);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user