Fix event of plugin.versionChanged
This commit is contained in:
parent
a75e116510
commit
65111d3609
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Services\Plugin;
|
||||
|
||||
class PluginVersionChanged extends Event
|
||||
{
|
||||
public $plugin;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Plugin $plugin
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Plugin $plugin)
|
||||
{
|
||||
$this->plugin = $plugin;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Services\Plugin;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class CopyPluginAssets
|
||||
@ -18,7 +19,7 @@ class CopyPluginAssets
|
||||
|
||||
public function handle($event)
|
||||
{
|
||||
$plugin = $event->plugin;
|
||||
$plugin = $event instanceof Plugin ? $event : $event->plugin;
|
||||
$dir = public_path('plugins/'.$plugin->name);
|
||||
$this->filesystem->deleteDirectory($dir);
|
||||
|
||||
|
@ -25,7 +25,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
'App\Listeners\CopyPluginAssets',
|
||||
'App\Listeners\GeneratePluginTranslations',
|
||||
],
|
||||
'App\Events\PluginVersionChanged' => [
|
||||
'plugin.versionChanged' => [
|
||||
'App\Listeners\CopyPluginAssets',
|
||||
'App\Listeners\GeneratePluginTranslations',
|
||||
],
|
||||
|
@ -82,6 +82,7 @@ class PluginManager
|
||||
return [$item['name'] => ['version' => $item['version']]];
|
||||
});
|
||||
$plugins = collect();
|
||||
$versionChanged = [];
|
||||
|
||||
$this->getPluginsDirs()
|
||||
->flatMap(function ($directory) {
|
||||
@ -91,7 +92,7 @@ class PluginManager
|
||||
->filter(function ($directory) {
|
||||
return $this->filesystem->exists($directory.DIRECTORY_SEPARATOR.'package.json');
|
||||
})
|
||||
->each(function ($directory) use (&$plugins) {
|
||||
->each(function ($directory) use (&$plugins, &$versionChanged) {
|
||||
$manifest = json_decode(
|
||||
$this->filesystem->get($directory.DIRECTORY_SEPARATOR.'package.json'),
|
||||
true
|
||||
@ -117,12 +118,18 @@ class PluginManager
|
||||
$this->enabled->get($name)['version']
|
||||
)) {
|
||||
$this->enabled->put($name, ['version' => $manifest['version']]);
|
||||
$this->dispatcher->dispatch(new Events\PluginVersionChanged($plugin));
|
||||
$versionChanged[] = $plugin;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$this->plugins = $plugins;
|
||||
if (count($versionChanged) > 0) {
|
||||
$this->saveEnabled();
|
||||
}
|
||||
array_walk($versionChanged, function ($plugin) {
|
||||
$this->dispatcher->dispatch('plugin.versionChanged', [$plugin]);
|
||||
});
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
@ -23,6 +23,6 @@ class CopyPluginAssetsTest extends TestCase
|
||||
->once();
|
||||
});
|
||||
|
||||
event(new \App\Events\PluginVersionChanged($plugin));
|
||||
event('plugin.versionChanged', [$plugin]);
|
||||
}
|
||||
}
|
||||
|
@ -117,6 +117,12 @@ class PluginManagerTest extends TestCase
|
||||
$mock->shouldReceive('get')
|
||||
->with('plugins_enabled', '[]')
|
||||
->andReturn(json_encode([['name' => 'mayaka', 'version' => '0.0.0']]));
|
||||
$mock->shouldReceive('set')
|
||||
->with(
|
||||
'plugins_enabled',
|
||||
json_encode([['name' => 'mayaka', 'version' => '0.1.0']])
|
||||
)
|
||||
->once();
|
||||
});
|
||||
$this->mock(Filesystem::class, function ($mock) {
|
||||
$mock->shouldReceive('directories')
|
||||
@ -149,8 +155,8 @@ class PluginManagerTest extends TestCase
|
||||
|
||||
app()->forgetInstance(PluginManager::class);
|
||||
resolve(PluginManager::class)->boot();
|
||||
Event::assertDispatched(\App\Events\PluginVersionChanged::class, function ($event) {
|
||||
$this->assertEquals('0.1.0', $event->plugin->version);
|
||||
Event::assertDispatched('plugin.versionChanged', function ($eventName, $payload) {
|
||||
$this->assertEquals('0.1.0', $payload[0]->version);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user