From 14dd13943c66a17e662022daccd60fbecc1e6e78 Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 16:57:24 -0500 Subject: [PATCH 01/16] Create ExtensionWillBeDisabled --- .../core/src/Event/ExtensionWillBeDisabled | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 framework/core/src/Event/ExtensionWillBeDisabled diff --git a/framework/core/src/Event/ExtensionWillBeDisabled b/framework/core/src/Event/ExtensionWillBeDisabled new file mode 100644 index 000000000..595374266 --- /dev/null +++ b/framework/core/src/Event/ExtensionWillBeDisabled @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Event; + +use Flarum\Extension\Extension; + +class ExtensionWillBeDisabled +{ + /** + * @var string + */ + protected $extension; + /** + * @param Extension $extension + */ + public function __construct(Extension $extension) + { + $this->extension = $extension; + } +} From 7b8679ca76f9396b85242f2e50812c6af5ccfc0d Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 17:05:41 -0500 Subject: [PATCH 02/16] Forgot the extension :/ --- .../{ExtensionWillBeDisabled => ExtensionWillBeDisabled.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename framework/core/src/Event/{ExtensionWillBeDisabled => ExtensionWillBeDisabled.php} (100%) diff --git a/framework/core/src/Event/ExtensionWillBeDisabled b/framework/core/src/Event/ExtensionWillBeDisabled.php similarity index 100% rename from framework/core/src/Event/ExtensionWillBeDisabled rename to framework/core/src/Event/ExtensionWillBeDisabled.php From 430bfc63c95873223f32c6a94fc3c12898cbe1ee Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 17:07:00 -0500 Subject: [PATCH 03/16] Create ExtensionWillBeEnabled.php --- .../core/src/Event/ExtensionWillBeEnabled.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 framework/core/src/Event/ExtensionWillBeEnabled.php diff --git a/framework/core/src/Event/ExtensionWillBeEnabled.php b/framework/core/src/Event/ExtensionWillBeEnabled.php new file mode 100644 index 000000000..e17ceb92b --- /dev/null +++ b/framework/core/src/Event/ExtensionWillBeEnabled.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Event; + +use Flarum\Extension\Extension; + +class ExtensionWillBeEnabled +{ + /** + * @var string + */ + protected $extension; + /** + * @param Extension $extension + */ + public function __construct(Extension $extension) + { + $this->extension = $extension; + } +} From e67d83b6bdde5d10420f66999e132ea63a21f074 Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 19:14:30 -0500 Subject: [PATCH 04/16] Create ExtensionValidator.php --- .../src/Core/Listener/ExtensionValidator.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 framework/core/src/Core/Listener/ExtensionValidator.php diff --git a/framework/core/src/Core/Listener/ExtensionValidator.php b/framework/core/src/Core/Listener/ExtensionValidator.php new file mode 100644 index 000000000..142004bfc --- /dev/null +++ b/framework/core/src/Core/Listener/ExtensionValidator.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Core\Listener; + +use Flarum\Event\ExtensionWillBeEnabled; +use Flarum\Event\ExtensionWillBeDisabled; +use Illuminate\Contracts\Events\Dispatcher; +use Flarum\Http\Exception\MethodNotAllowedException; + +class ExtensionModificationValidator +{ + /** + * @param Dispatcher $events + */ + public function subscribe(Dispatcher $events) + { + $events->listen(ExtensionWillBeEnabled::class, [$this, 'whenExtensionWillBeEnabled']); + $events->listen(ExtensionWillBeDisabled::class, [$this, 'whenExtensionWillBeDisabled']); + } + + /** + * @param ExtensionWillBeEnabled $event + */ + public function whenExtensionWillBeEnabled(ExtensionWillBeEnabled $event) + { + + } + + /** + * @param ExtensionWillBeDisabled $event + * @throws MethodNotAllowedException + */ + public function whenExtensionWillBeDisabled(ExtensionWillBeDisabled $event) + { + if (in_array('flarum-locale', $event->extension->extra)) { + $default_locale = $this->app->make('flarum.settings')->get('default_locale'); + $locale = array_get($event->extension->extra, 'flarum-locale.code'); + if ($locale === $default_locale) { + throw new MethodNotAllowedException('You cannot remove all your language packs!'); + } + } + } +} From a6e6c2dd9319934fb649748857bff690c2119e19 Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 22:17:54 -0500 Subject: [PATCH 05/16] Add WillBe Modifiers --- framework/core/src/Extension/ExtensionManager.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 3796ca05f..bb1fb77c6 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -13,6 +13,8 @@ namespace Flarum\Extension; use Flarum\Database\Migrator; use Flarum\Event\ExtensionWasDisabled; use Flarum\Event\ExtensionWasEnabled; +use Flarum\Event\ExtensionWillBeEnabled; +use Flarum\Event\ExtensionWillBeDisabled; use Flarum\Event\ExtensionWasUninstalled; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; @@ -110,6 +112,8 @@ class ExtensionManager public function enable($name) { if (! $this->isEnabled($name)) { + $this->dispatcher->fire(new ExtensionWillBeEnabled($extension)); + $extension = $this->getExtension($name); $enabled = $this->getEnabled(); @@ -138,6 +142,8 @@ class ExtensionManager $enabled = $this->getEnabled(); if (($k = array_search($name, $enabled)) !== false) { + $this->dispatcher->fire(new ExtensionWillBeDisabled($extension)); + unset($enabled[$k]); $extension = $this->getExtension($name); From efcbf200c55e521587b5948f744ebd14fbc9d890 Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 22:19:47 -0500 Subject: [PATCH 06/16] Remove useless code --- .../core/src/Core/Listener/ExtensionValidator.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/framework/core/src/Core/Listener/ExtensionValidator.php b/framework/core/src/Core/Listener/ExtensionValidator.php index 142004bfc..0f8048a56 100644 --- a/framework/core/src/Core/Listener/ExtensionValidator.php +++ b/framework/core/src/Core/Listener/ExtensionValidator.php @@ -10,7 +10,6 @@ namespace Flarum\Core\Listener; -use Flarum\Event\ExtensionWillBeEnabled; use Flarum\Event\ExtensionWillBeDisabled; use Illuminate\Contracts\Events\Dispatcher; use Flarum\Http\Exception\MethodNotAllowedException; @@ -22,18 +21,9 @@ class ExtensionModificationValidator */ public function subscribe(Dispatcher $events) { - $events->listen(ExtensionWillBeEnabled::class, [$this, 'whenExtensionWillBeEnabled']); $events->listen(ExtensionWillBeDisabled::class, [$this, 'whenExtensionWillBeDisabled']); } - /** - * @param ExtensionWillBeEnabled $event - */ - public function whenExtensionWillBeEnabled(ExtensionWillBeEnabled $event) - { - - } - /** * @param ExtensionWillBeDisabled $event * @throws MethodNotAllowedException From e4b5ebb69f7b8767f99bb12b29c76b3b238af31f Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 22:23:31 -0500 Subject: [PATCH 07/16] Make StyleCL Happy --- framework/core/src/Core/Listener/ExtensionValidator.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Core/Listener/ExtensionValidator.php b/framework/core/src/Core/Listener/ExtensionValidator.php index 0f8048a56..49da05f5e 100644 --- a/framework/core/src/Core/Listener/ExtensionValidator.php +++ b/framework/core/src/Core/Listener/ExtensionValidator.php @@ -1,4 +1,5 @@ Date: Mon, 12 Sep 2016 22:24:57 -0500 Subject: [PATCH 08/16] StyleCL --- framework/core/src/Event/ExtensionWillBeEnabled.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/core/src/Event/ExtensionWillBeEnabled.php b/framework/core/src/Event/ExtensionWillBeEnabled.php index e17ceb92b..e0a9214e3 100644 --- a/framework/core/src/Event/ExtensionWillBeEnabled.php +++ b/framework/core/src/Event/ExtensionWillBeEnabled.php @@ -1,4 +1,5 @@ Date: Mon, 12 Sep 2016 22:26:22 -0500 Subject: [PATCH 09/16] StyleCl --- framework/core/src/Extension/ExtensionManager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index bb1fb77c6..29971a418 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -13,9 +13,9 @@ namespace Flarum\Extension; use Flarum\Database\Migrator; use Flarum\Event\ExtensionWasDisabled; use Flarum\Event\ExtensionWasEnabled; +use Flarum\Event\ExtensionWasUninstalled; use Flarum\Event\ExtensionWillBeEnabled; use Flarum\Event\ExtensionWillBeDisabled; -use Flarum\Event\ExtensionWasUninstalled; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; @@ -113,7 +113,7 @@ class ExtensionManager { if (! $this->isEnabled($name)) { $this->dispatcher->fire(new ExtensionWillBeEnabled($extension)); - + $extension = $this->getExtension($name); $enabled = $this->getEnabled(); @@ -143,7 +143,7 @@ class ExtensionManager if (($k = array_search($name, $enabled)) !== false) { $this->dispatcher->fire(new ExtensionWillBeDisabled($extension)); - + unset($enabled[$k]); $extension = $this->getExtension($name); From 428f9df2aeab266942facdc06282c177b8c68f55 Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 22:27:18 -0500 Subject: [PATCH 10/16] StyleCl --- framework/core/src/Extension/ExtensionManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 29971a418..8a07bc9b9 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -14,8 +14,8 @@ use Flarum\Database\Migrator; use Flarum\Event\ExtensionWasDisabled; use Flarum\Event\ExtensionWasEnabled; use Flarum\Event\ExtensionWasUninstalled; -use Flarum\Event\ExtensionWillBeEnabled; use Flarum\Event\ExtensionWillBeDisabled; +use Flarum\Event\ExtensionWillBeEnabled; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; From 4819523742508e9a02406eb38399f0e29c1e13a6 Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 22:28:03 -0500 Subject: [PATCH 11/16] StyleCl --- framework/core/src/Event/ExtensionWillBeDisabled.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/core/src/Event/ExtensionWillBeDisabled.php b/framework/core/src/Event/ExtensionWillBeDisabled.php index 595374266..6df58a41c 100644 --- a/framework/core/src/Event/ExtensionWillBeDisabled.php +++ b/framework/core/src/Event/ExtensionWillBeDisabled.php @@ -1,4 +1,5 @@ Date: Mon, 12 Sep 2016 22:28:50 -0500 Subject: [PATCH 12/16] StyleCl FINALLY! --- framework/core/src/Extension/ExtensionManager.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 8a07bc9b9..0e008230a 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -1,4 +1,5 @@ Date: Mon, 12 Sep 2016 22:31:03 -0500 Subject: [PATCH 13/16] Forgot to subscribe --- framework/core/src/Core/CoreServiceProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index 478baf97d..68ec477e0 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -105,6 +105,7 @@ class CoreServiceProvider extends AbstractServiceProvider $events->subscribe('Flarum\Core\Listener\DiscussionMetadataUpdater'); $events->subscribe('Flarum\Core\Listener\UserMetadataUpdater'); + $events->subscribe('Flarum\Core\Listener\ExtensionValidator'); $events->subscribe('Flarum\Core\Listener\EmailConfirmationMailer'); $events->subscribe('Flarum\Core\Listener\DiscussionRenamedNotifier'); From 9c2e19edb2fba1e9ff2b67cf5d18ef4aa6f3ea40 Mon Sep 17 00:00:00 2001 From: Davis Date: Mon, 12 Sep 2016 22:31:55 -0500 Subject: [PATCH 14/16] StyleCl is making me hate myself --- framework/core/src/Core/CoreServiceProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index 68ec477e0..d6c3f7de2 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -1,4 +1,5 @@ Date: Tue, 4 Oct 2016 15:09:43 -0500 Subject: [PATCH 15/16] Change exception message --- framework/core/src/Core/Listener/ExtensionValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Core/Listener/ExtensionValidator.php b/framework/core/src/Core/Listener/ExtensionValidator.php index 49da05f5e..2f25af476 100644 --- a/framework/core/src/Core/Listener/ExtensionValidator.php +++ b/framework/core/src/Core/Listener/ExtensionValidator.php @@ -35,7 +35,7 @@ class ExtensionValidator $default_locale = $this->app->make('flarum.settings')->get('default_locale'); $locale = array_get($event->extension->extra, 'flarum-locale.code'); if ($locale === $default_locale) { - throw new MethodNotAllowedException('You cannot remove all your language packs!'); + throw new MethodNotAllowedException('You cannot disable the default language pack!'); } } } From e1a75b51d9fe09c3d27225637be52a202a7263d8 Mon Sep 17 00:00:00 2001 From: Davis Date: Wed, 5 Oct 2016 12:46:14 -0500 Subject: [PATCH 16/16] $extension was undefined --- framework/core/src/Extension/ExtensionManager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 0e008230a..f0e62838c 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -113,9 +113,9 @@ class ExtensionManager public function enable($name) { if (! $this->isEnabled($name)) { - $this->dispatcher->fire(new ExtensionWillBeEnabled($extension)); - $extension = $this->getExtension($name); + + $this->dispatcher->fire(new ExtensionWillBeEnabled($extension)); $enabled = $this->getEnabled(); @@ -143,12 +143,12 @@ class ExtensionManager $enabled = $this->getEnabled(); if (($k = array_search($name, $enabled)) !== false) { + $extension = $this->getExtension($name); + $this->dispatcher->fire(new ExtensionWillBeDisabled($extension)); unset($enabled[$k]); - $extension = $this->getExtension($name); - $this->setEnabled($enabled); $extension->setEnabled(false);