From 4b00f7996b5b2f7f616b800d7325d65746f02186 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 13 Dec 2018 21:58:00 +0100 Subject: [PATCH 01/78] Early returns --- src/Extension/DefaultLanguagePackGuard.php | 15 +++-- src/Forum/ValidateCustomLess.php | 78 ++++++++++++---------- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/Extension/DefaultLanguagePackGuard.php b/src/Extension/DefaultLanguagePackGuard.php index d8fd3dc8a..88d98c7a8 100644 --- a/src/Extension/DefaultLanguagePackGuard.php +++ b/src/Extension/DefaultLanguagePackGuard.php @@ -42,12 +42,15 @@ class DefaultLanguagePackGuard */ public function whenExtensionWillBeDisabled(Disabling $event) { - if (in_array('flarum-locale', $event->extension->extra)) { - $defaultLocale = $this->settings->get('default_locale'); - $locale = array_get($event->extension->extra, 'flarum-locale.code'); - if ($locale === $defaultLocale) { - throw new ForbiddenException('You cannot disable the default language pack!'); - } + if (! in_array('flarum-locale', $event->extension->extra)) { + return; + } + + $defaultLocale = $this->settings->get('default_locale'); + $locale = array_get($event->extension->extra, 'flarum-locale.code'); + + if ($locale === $defaultLocale) { + throw new ForbiddenException('You cannot disable the default language pack!'); } } } diff --git a/src/Forum/ValidateCustomLess.php b/src/Forum/ValidateCustomLess.php index 190f98a50..532c9b623 100644 --- a/src/Forum/ValidateCustomLess.php +++ b/src/Forum/ValidateCustomLess.php @@ -69,39 +69,41 @@ class ValidateCustomLess */ public function whenSettingsSaving(Saving $event) { - if (isset($event->settings['custom_less'])) { - // We haven't saved the settings yet, but we want to trial a full - // recompile of the CSS to see if this custom LESS will break - // anything. In order to do that, we will temporarily override the - // settings repository with the new settings so that the recompile - // is effective. We will also use a dummy filesystem so that nothing - // is actually written yet. - - $settings = $this->container->make(SettingsRepositoryInterface::class); - - $this->container->extend( - SettingsRepositoryInterface::class, - function ($settings) use ($event) { - return new OverrideSettingsRepository($settings, $event->settings); - } - ); - - $assetsDir = $this->assets->getAssetsDir(); - $this->assets->setAssetsDir(new FilesystemAdapter(new Filesystem(new NullAdapter))); - - try { - $this->assets->makeCss()->commit(); - - foreach ($this->locales->getLocales() as $locale => $name) { - $this->assets->makeLocaleCss($locale)->commit(); - } - } catch (Less_Exception_Parser $e) { - throw new ValidationException(['custom_less' => $e->getMessage()]); - } - - $this->assets->setAssetsDir($assetsDir); - $this->container->instance(SettingsRepositoryInterface::class, $settings); + if (! isset($event->settings['custom_less'])) { + return; } + + // We haven't saved the settings yet, but we want to trial a full + // recompile of the CSS to see if this custom LESS will break + // anything. In order to do that, we will temporarily override the + // settings repository with the new settings so that the recompile + // is effective. We will also use a dummy filesystem so that nothing + // is actually written yet. + + $settings = $this->container->make(SettingsRepositoryInterface::class); + + $this->container->extend( + SettingsRepositoryInterface::class, + function ($settings) use ($event) { + return new OverrideSettingsRepository($settings, $event->settings); + } + ); + + $assetsDir = $this->assets->getAssetsDir(); + $this->assets->setAssetsDir(new FilesystemAdapter(new Filesystem(new NullAdapter))); + + try { + $this->assets->makeCss()->commit(); + + foreach ($this->locales->getLocales() as $locale => $name) { + $this->assets->makeLocaleCss($locale)->commit(); + } + } catch (Less_Exception_Parser $e) { + throw new ValidationException(['custom_less' => $e->getMessage()]); + } + + $this->assets->setAssetsDir($assetsDir); + $this->container->instance(SettingsRepositoryInterface::class, $settings); } /** @@ -109,12 +111,14 @@ class ValidateCustomLess */ public function whenSettingsSaved(Saved $event) { - if (isset($event->settings['custom_less'])) { - $this->assets->makeCss()->flush(); + if (! isset($event->settings['custom_less'])) { + return; + } - foreach ($this->locales->getLocales() as $locale => $name) { - $this->assets->makeLocaleCss($locale)->flush(); - } + $this->assets->makeCss()->flush(); + + foreach ($this->locales->getLocales() as $locale => $name) { + $this->assets->makeLocaleCss($locale)->flush(); } } } From 5c9fa4c62da4ca4dbbb09a6dc7599fab7a9f3c36 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 13 Dec 2018 21:59:49 +0100 Subject: [PATCH 02/78] Get rid of docblocks that don't add information --- src/Discussion/DiscussionMetadataUpdater.php | 18 ------------------ src/Discussion/DiscussionRenamedLogger.php | 9 --------- src/Forum/ValidateCustomLess.php | 10 ---------- src/User/EmailConfirmationMailer.php | 12 ------------ 4 files changed, 49 deletions(-) diff --git a/src/Discussion/DiscussionMetadataUpdater.php b/src/Discussion/DiscussionMetadataUpdater.php index 27a162fd0..23a958364 100644 --- a/src/Discussion/DiscussionMetadataUpdater.php +++ b/src/Discussion/DiscussionMetadataUpdater.php @@ -20,9 +20,6 @@ use Illuminate\Contracts\Events\Dispatcher; class DiscussionMetadataUpdater { - /** - * @param Dispatcher $events - */ public function subscribe(Dispatcher $events) { $events->listen(Posted::class, [$this, 'whenPostWasPosted']); @@ -31,9 +28,6 @@ class DiscussionMetadataUpdater $events->listen(Restored::class, [$this, 'whenPostWasRestored']); } - /** - * @param Posted $event - */ public function whenPostWasPosted(Posted $event) { $discussion = $event->post->discussion; @@ -46,9 +40,6 @@ class DiscussionMetadataUpdater } } - /** - * @param \Flarum\Post\Event\Deleted $event - */ public function whenPostWasDeleted(Deleted $event) { $this->removePost($event->post); @@ -60,17 +51,11 @@ class DiscussionMetadataUpdater } } - /** - * @param \Flarum\Post\Event\Hidden $event - */ public function whenPostWasHidden(Hidden $event) { $this->removePost($event->post); } - /** - * @param Restored $event - */ public function whenPostWasRestored(Restored $event) { $discussion = $event->post->discussion; @@ -83,9 +68,6 @@ class DiscussionMetadataUpdater } } - /** - * @param Post $post - */ protected function removePost(Post $post) { $discussion = $post->discussion; diff --git a/src/Discussion/DiscussionRenamedLogger.php b/src/Discussion/DiscussionRenamedLogger.php index 8c014794e..2ab5f91d5 100644 --- a/src/Discussion/DiscussionRenamedLogger.php +++ b/src/Discussion/DiscussionRenamedLogger.php @@ -24,25 +24,16 @@ class DiscussionRenamedLogger */ protected $notifications; - /** - * @param NotificationSyncer $notifications - */ public function __construct(NotificationSyncer $notifications) { $this->notifications = $notifications; } - /** - * @param Dispatcher $events - */ public function subscribe(Dispatcher $events) { $events->listen(Renamed::class, [$this, 'whenDiscussionWasRenamed']); } - /** - * @param \Flarum\Discussion\Event\Renamed $event - */ public function whenDiscussionWasRenamed(Renamed $event) { $post = DiscussionRenamedPost::reply( diff --git a/src/Forum/ValidateCustomLess.php b/src/Forum/ValidateCustomLess.php index 532c9b623..a2af7f650 100644 --- a/src/Forum/ValidateCustomLess.php +++ b/src/Forum/ValidateCustomLess.php @@ -54,19 +54,12 @@ class ValidateCustomLess $this->container = $container; } - /** - * @param Dispatcher $events - */ public function subscribe(Dispatcher $events) { $events->listen(Saving::class, [$this, 'whenSettingsSaving']); $events->listen(Saved::class, [$this, 'whenSettingsSaved']); } - /** - * @param Saving $event - * @throws ValidationException - */ public function whenSettingsSaving(Saving $event) { if (! isset($event->settings['custom_less'])) { @@ -106,9 +99,6 @@ class ValidateCustomLess $this->container->instance(SettingsRepositoryInterface::class, $settings); } - /** - * @param Saved $event - */ public function whenSettingsSaved(Saved $event) { if (! isset($event->settings['custom_less'])) { diff --git a/src/User/EmailConfirmationMailer.php b/src/User/EmailConfirmationMailer.php index 01357287b..074a54c26 100644 --- a/src/User/EmailConfirmationMailer.php +++ b/src/User/EmailConfirmationMailer.php @@ -42,12 +42,6 @@ class EmailConfirmationMailer */ protected $translator; - /** - * @param \Flarum\Settings\SettingsRepositoryInterface $settings - * @param Mailer $mailer - * @param UrlGenerator $url - * @param Translator $translator - */ public function __construct(SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, Translator $translator) { $this->settings = $settings; @@ -65,9 +59,6 @@ class EmailConfirmationMailer $events->listen(EmailChangeRequested::class, [$this, 'whenUserEmailChangeWasRequested']); } - /** - * @param \Flarum\User\Event\Registered $event - */ public function whenUserWasRegistered(Registered $event) { $user = $event->user; @@ -86,9 +77,6 @@ class EmailConfirmationMailer }); } - /** - * @param \Flarum\User\Event\EmailChangeRequested $event - */ public function whenUserEmailChangeWasRequested(EmailChangeRequested $event) { $email = $event->email; From 3e0cd3a21ffa0c92ba9784ab018c29306eed5426 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 14 Dec 2018 01:47:54 +0100 Subject: [PATCH 03/78] Use class constant to get qualified class names --- src/Database/DatabaseServiceProvider.php | 13 +++++---- src/Database/MigrationServiceProvider.php | 5 ++-- src/Post/PostServiceProvider.php | 6 ++-- src/Search/SearchServiceProvider.php | 34 +++++++++++++++-------- src/Settings/SettingsServiceProvider.php | 3 +- src/User/UserServiceProvider.php | 9 ++++-- 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/Database/DatabaseServiceProvider.php b/src/Database/DatabaseServiceProvider.php index 44c7acfd1..12892f2fb 100644 --- a/src/Database/DatabaseServiceProvider.php +++ b/src/Database/DatabaseServiceProvider.php @@ -12,7 +12,10 @@ namespace Flarum\Database; use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionResolver; +use Illuminate\Database\ConnectionResolverInterface; use Illuminate\Database\Connectors\ConnectionFactory; class DatabaseServiceProvider extends AbstractServiceProvider @@ -28,14 +31,14 @@ class DatabaseServiceProvider extends AbstractServiceProvider $dbConfig = $this->app->config('database'); $dbConfig['engine'] = 'InnoDB'; $connection = $factory->make($dbConfig); - $connection->setEventDispatcher($this->app->make('Illuminate\Contracts\Events\Dispatcher')); + $connection->setEventDispatcher($this->app->make(Dispatcher::class)); return $connection; }); - $this->app->alias('flarum.db', 'Illuminate\Database\ConnectionInterface'); + $this->app->alias('flarum.db', ConnectionInterface::class); - $this->app->singleton('Illuminate\Database\ConnectionResolverInterface', function () { + $this->app->singleton(ConnectionResolverInterface::class, function () { $resolver = new ConnectionResolver([ 'flarum' => $this->app->make('flarum.db'), ]); @@ -44,7 +47,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider return $resolver; }); - $this->app->alias('Illuminate\Database\ConnectionResolverInterface', 'db'); + $this->app->alias(ConnectionResolverInterface::class, 'db'); } /** @@ -52,7 +55,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider */ public function boot() { - AbstractModel::setConnectionResolver($this->app->make('Illuminate\Database\ConnectionResolverInterface')); + AbstractModel::setConnectionResolver($this->app->make(ConnectionResolverInterface::class)); AbstractModel::setEventDispatcher($this->app->make('events')); } } diff --git a/src/Database/MigrationServiceProvider.php b/src/Database/MigrationServiceProvider.php index 165cec0da..9ffc6af7a 100644 --- a/src/Database/MigrationServiceProvider.php +++ b/src/Database/MigrationServiceProvider.php @@ -13,6 +13,7 @@ namespace Flarum\Database; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\Application; +use Illuminate\Filesystem\Filesystem; class MigrationServiceProvider extends AbstractServiceProvider { @@ -21,12 +22,12 @@ class MigrationServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->singleton('Flarum\Database\MigrationRepositoryInterface', function ($app) { + $this->app->singleton(MigrationRepositoryInterface::class, function ($app) { return new DatabaseMigrationRepository($app['flarum.db'], 'migrations'); }); $this->app->bind(MigrationCreator::class, function (Application $app) { - return new MigrationCreator($app->make('Illuminate\Filesystem\Filesystem'), $app->basePath()); + return new MigrationCreator($app->make(Filesystem::class), $app->basePath()); }); } } diff --git a/src/Post/PostServiceProvider.php b/src/Post/PostServiceProvider.php index b597f875c..b7cdae086 100644 --- a/src/Post/PostServiceProvider.php +++ b/src/Post/PostServiceProvider.php @@ -26,14 +26,14 @@ class PostServiceProvider extends AbstractServiceProvider $this->registerPostTypes(); $events = $this->app->make('events'); - $events->subscribe('Flarum\Post\PostPolicy'); + $events->subscribe(PostPolicy::class); } public function registerPostTypes() { $models = [ - 'Flarum\Post\CommentPost', - 'Flarum\Post\DiscussionRenamedPost' + CommentPost::class, + DiscussionRenamedPost::class ]; $this->app->make('events')->fire( diff --git a/src/Search/SearchServiceProvider.php b/src/Search/SearchServiceProvider.php index 71d316d54..fbbfefe41 100644 --- a/src/Search/SearchServiceProvider.php +++ b/src/Search/SearchServiceProvider.php @@ -11,9 +11,19 @@ namespace Flarum\Search; +use Flarum\Discussion\Search\DiscussionSearcher; +use Flarum\Discussion\Search\Gambit\AuthorGambit; +use Flarum\Discussion\Search\Gambit\CreatedGambit; +use Flarum\Discussion\Search\Gambit\FulltextGambit as DiscussionFulltextGambit; +use Flarum\Discussion\Search\Gambit\HiddenGambit; +use Flarum\Discussion\Search\Gambit\UnreadGambit; use Flarum\Event\ConfigureDiscussionGambits; use Flarum\Event\ConfigureUserGambits; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\User\Search\Gambit\EmailGambit; +use Flarum\User\Search\Gambit\FulltextGambit as UserFulltextGambit; +use Flarum\User\Search\Gambit\GroupGambit; +use Flarum\User\Search\UserSearcher; use Illuminate\Contracts\Container\Container; class SearchServiceProvider extends AbstractServiceProvider @@ -37,14 +47,14 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerUserGambits() { - $this->app->when('Flarum\User\Search\UserSearcher') - ->needs('Flarum\Search\GambitManager') + $this->app->when(UserSearcher::class) + ->needs(GambitManager::class) ->give(function (Container $app) { $gambits = new GambitManager($app); - $gambits->setFulltextGambit('Flarum\User\Search\Gambit\FulltextGambit'); - $gambits->add('Flarum\User\Search\Gambit\EmailGambit'); - $gambits->add('Flarum\User\Search\Gambit\GroupGambit'); + $gambits->setFulltextGambit(UserFulltextGambit::class); + $gambits->add(EmailGambit::class); + $gambits->add(GroupGambit::class); $app->make('events')->fire( new ConfigureUserGambits($gambits) @@ -56,16 +66,16 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerDiscussionGambits() { - $this->app->when('Flarum\Discussion\Search\DiscussionSearcher') - ->needs('Flarum\Search\GambitManager') + $this->app->when(DiscussionSearcher::class) + ->needs(GambitManager::class) ->give(function (Container $app) { $gambits = new GambitManager($app); - $gambits->setFulltextGambit('Flarum\Discussion\Search\Gambit\FulltextGambit'); - $gambits->add('Flarum\Discussion\Search\Gambit\AuthorGambit'); - $gambits->add('Flarum\Discussion\Search\Gambit\CreatedGambit'); - $gambits->add('Flarum\Discussion\Search\Gambit\HiddenGambit'); - $gambits->add('Flarum\Discussion\Search\Gambit\UnreadGambit'); + $gambits->setFulltextGambit(DiscussionFulltextGambit::class); + $gambits->add(AuthorGambit::class); + $gambits->add(CreatedGambit::class); + $gambits->add(HiddenGambit::class); + $gambits->add(UnreadGambit::class); $app->make('events')->fire( new ConfigureDiscussionGambits($gambits) diff --git a/src/Settings/SettingsServiceProvider.php b/src/Settings/SettingsServiceProvider.php index 6955083ba..a87cb206f 100644 --- a/src/Settings/SettingsServiceProvider.php +++ b/src/Settings/SettingsServiceProvider.php @@ -12,6 +12,7 @@ namespace Flarum\Settings; use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Database\ConnectionInterface; class SettingsServiceProvider extends AbstractServiceProvider { @@ -23,7 +24,7 @@ class SettingsServiceProvider extends AbstractServiceProvider $this->app->singleton(SettingsRepositoryInterface::class, function () { return new MemoryCacheSettingsRepository( new DatabaseSettingsRepository( - $this->app->make('Illuminate\Database\ConnectionInterface') + $this->app->make(ConnectionInterface::class) ) ); }); diff --git a/src/User/UserServiceProvider.php b/src/User/UserServiceProvider.php index 12aae50fb..30e8f823b 100644 --- a/src/User/UserServiceProvider.php +++ b/src/User/UserServiceProvider.php @@ -15,6 +15,9 @@ use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetPermission; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Container\Container; +use Illuminate\Contracts\Auth\Access\Gate as GateContract; +use Illuminate\Contracts\Filesystem\Factory; +use League\Flysystem\FilesystemInterface; use RuntimeException; class UserServiceProvider extends AbstractServiceProvider @@ -36,18 +39,18 @@ class UserServiceProvider extends AbstractServiceProvider }); }); - $this->app->alias('flarum.gate', 'Illuminate\Contracts\Auth\Access\Gate'); + $this->app->alias('flarum.gate', GateContract::class); $this->app->alias('flarum.gate', Gate::class); } protected function registerAvatarsFilesystem() { $avatarsFilesystem = function (Container $app) { - return $app->make('Illuminate\Contracts\Filesystem\Factory')->disk('flarum-avatars')->getDriver(); + return $app->make(Factory::class)->disk('flarum-avatars')->getDriver(); }; $this->app->when(AvatarUploader::class) - ->needs('League\Flysystem\FilesystemInterface') + ->needs(FilesystemInterface::class) ->give($avatarsFilesystem); } From 6acc91577d8501312204a1932b892add1b5ec9c5 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 14 Dec 2018 01:48:19 +0100 Subject: [PATCH 04/78] Apply fixes from StyleCI (#1701) [ci skip] [skip ci] --- src/User/UserServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/User/UserServiceProvider.php b/src/User/UserServiceProvider.php index 30e8f823b..69a42f143 100644 --- a/src/User/UserServiceProvider.php +++ b/src/User/UserServiceProvider.php @@ -14,8 +14,8 @@ namespace Flarum\User; use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetPermission; use Flarum\Foundation\AbstractServiceProvider; -use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Auth\Access\Gate as GateContract; +use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Filesystem\Factory; use League\Flysystem\FilesystemInterface; use RuntimeException; From f0da3cf304bb4251cd6b251535bcf953ead28149 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 14 Dec 2018 11:28:11 +1030 Subject: [PATCH 05/78] Remove obsolete binding --- src/Search/SearchServiceProvider.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Search/SearchServiceProvider.php b/src/Search/SearchServiceProvider.php index fbbfefe41..63005a2b3 100644 --- a/src/Search/SearchServiceProvider.php +++ b/src/Search/SearchServiceProvider.php @@ -35,11 +35,6 @@ class SearchServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->bind( - 'Flarum\Discussion\Search\Fulltext\DriverInterface', - 'Flarum\Discussion\Search\Fulltext\MySqlFulltextDriver' - ); - $this->registerDiscussionGambits(); $this->registerUserGambits(); From 565131e2a75d80970229970185b45435e18f11ae Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 15 Dec 2018 12:05:17 +0100 Subject: [PATCH 06/78] Allow passing strings (names of invokable classes) to Formatter extender In preparation for fixing #1703. --- src/Extend/Formatter.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Extend/Formatter.php b/src/Extend/Formatter.php index 1ae2a6ed8..2707432d2 100644 --- a/src/Extend/Formatter.php +++ b/src/Extend/Formatter.php @@ -21,7 +21,7 @@ class Formatter implements ExtenderInterface, LifecycleInterface { protected $callback; - public function configure(callable $callback) + public function configure($callback) { $this->callback = $callback; @@ -34,8 +34,14 @@ class Formatter implements ExtenderInterface, LifecycleInterface $events->listen( Configuring::class, - function (Configuring $event) { - call_user_func($this->callback, $event->configurator); + function (Configuring $event) use ($container) { + if (is_string($this->callback)) { + $callback = $container->make($this->callback); + } else { + $callback = $this->callback; + } + + $callback($event->configurator); } ); } From 54503d2c295cf02d5c2911c68d03d5f5586782d9 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 18 Dec 2018 10:33:01 +0100 Subject: [PATCH 07/78] API: Populate default routes only when they are resolved Refs #1708. --- src/Api/ApiServiceProvider.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Api/ApiServiceProvider.php b/src/Api/ApiServiceProvider.php index d49398eae..d904ec3d9 100644 --- a/src/Api/ApiServiceProvider.php +++ b/src/Api/ApiServiceProvider.php @@ -43,6 +43,10 @@ class ApiServiceProvider extends AbstractServiceProvider return new RouteCollection; }); + $this->app->afterResolving('flarum.api.routes', function (RouteCollection $routes) { + $this->populateRoutes($routes); + }); + $this->app->singleton('flarum.api.middleware', function (Application $app) { $pipe = new MiddlewarePipe; @@ -90,8 +94,6 @@ class ApiServiceProvider extends AbstractServiceProvider */ public function boot() { - $this->populateRoutes($this->app->make('flarum.api.routes')); - $this->registerNotificationSerializers(); AbstractSerializeController::setContainer($this->app); From 3468bdf51148f152c34c97cbf0a89e970bc0dc67 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 18 Dec 2018 11:16:30 +0100 Subject: [PATCH 08/78] Run local extenders before booting service providers We still need to discuss the priority of local extenders vs. those from enabled extensions, but let's first fix the actual bug. Refs #1708. --- src/Foundation/InstalledSite.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Foundation/InstalledSite.php b/src/Foundation/InstalledSite.php index 712c2ca4e..8e516ef0b 100644 --- a/src/Foundation/InstalledSite.php +++ b/src/Foundation/InstalledSite.php @@ -146,12 +146,12 @@ class InstalledSite implements SiteInterface $laravel->register(ExtensionServiceProvider::class); - $laravel->boot(); - foreach ($this->extenders as $extension) { $extension->extend($laravel); } + $laravel->boot(); + return $laravel; } From 9eca9192ca98232750dd9b353106be0f8cd95b6f Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Wed, 19 Dec 2018 11:40:48 +0100 Subject: [PATCH 09/78] fixes a notice due to the forum variable not being defined before compacting --- src/Forum/Content/Index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Forum/Content/Index.php b/src/Forum/Content/Index.php index 11b5a4b50..8818265c9 100644 --- a/src/Forum/Content/Index.php +++ b/src/Forum/Content/Index.php @@ -58,7 +58,7 @@ class Index $apiDocument = $this->getApiDocument($request->getAttribute('actor'), $params); - $document->content = $this->view->make('flarum.forum::frontend.content.index', compact('apiDocument', 'page', 'forum')); + $document->content = $this->view->make('flarum.forum::frontend.content.index', compact('apiDocument', 'page')); $document->payload['apiDocument'] = $apiDocument; return $document; From 671fdec8d0a092ccceb5d4d5f657d0f4287fc4c7 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Wed, 19 Dec 2018 15:07:32 +0100 Subject: [PATCH 10/78] fixes #1695, post comment count is incorrectly calculated based on all posts, including events --- src/User/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/User/User.php b/src/User/User.php index 3fc2f2110..45c248059 100644 --- a/src/User/User.php +++ b/src/User/User.php @@ -753,7 +753,7 @@ class User extends AbstractModel */ public function refreshCommentCount() { - $this->comment_count = $this->posts()->count(); + $this->comment_count = $this->posts()->where('type', 'comment')->count(); return $this; } From 209d13affdaf6d24e783097568b297eed5bbfda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Wed, 19 Dec 2018 18:09:36 +0100 Subject: [PATCH 11/78] add 7.3 to travis (#1710) --- .travis.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2a83625f6..c62d1e8d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,8 @@ jobs: - php: 7.2 env: DB=mysql - - php: 7.2 - env: DB=mysql PREFIX=forum_ + - php: 7.3 + env: DB=mysql - php: 7.1 addons: @@ -36,6 +36,14 @@ jobs: mariadb: '10.2' env: DB=mariadb + - php: 7.3 + addons: + mariadb: '10.2' + env: DB=mariadb + + - php: 7.2 + env: DB=mysql PREFIX=forum_ + - stage: build language: generic if: branch = master AND type = push From ba594de13a033480834d53d73f747b05fe9796f8 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 19 Dec 2018 21:30:29 +0100 Subject: [PATCH 12/78] Make site extenders run after extensions Fixes #1708. --- src/Extension/ExtensionServiceProvider.php | 2 +- src/Foundation/InstalledSite.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Extension/ExtensionServiceProvider.php b/src/Extension/ExtensionServiceProvider.php index fa61df382..fe5135628 100644 --- a/src/Extension/ExtensionServiceProvider.php +++ b/src/Extension/ExtensionServiceProvider.php @@ -27,7 +27,7 @@ class ExtensionServiceProvider extends AbstractServiceProvider // Boot extensions when the app is booting. This must be done as a boot // listener on the app rather than in the service provider's boot method // below, so that extensions have a chance to register things on the - // container before the core boot code runs. + // container before the core boots up (and starts resolving services). $this->app->booting(function (Container $app) { $app->make('flarum.extensions')->extend($app); }); diff --git a/src/Foundation/InstalledSite.php b/src/Foundation/InstalledSite.php index 8e516ef0b..de15623bd 100644 --- a/src/Foundation/InstalledSite.php +++ b/src/Foundation/InstalledSite.php @@ -36,6 +36,7 @@ use Illuminate\Cache\Repository as CacheRepository; use Illuminate\Config\Repository as ConfigRepository; use Illuminate\Contracts\Cache\Repository; use Illuminate\Contracts\Cache\Store; +use Illuminate\Contracts\Container\Container; use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\FilesystemServiceProvider; use Illuminate\Hashing\HashServiceProvider; @@ -146,9 +147,14 @@ class InstalledSite implements SiteInterface $laravel->register(ExtensionServiceProvider::class); - foreach ($this->extenders as $extension) { - $extension->extend($laravel); - } + $laravel->booting(function (Container $app) { + // Run all local-site extenders before booting service providers + // (but after those from "real" extensions, which have been set up + // in a service provider above). + foreach ($this->extenders as $extension) { + $extension->extend($app); + } + }); $laravel->boot(); From 1080d255613c31d059d5c5304a9cfcdbf7cc5fd2 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 19 Dec 2018 21:55:58 +0100 Subject: [PATCH 13/78] Frontends: Populate default routes only when they are resolved --- src/Admin/AdminServiceProvider.php | 6 ++++-- src/Forum/ForumServiceProvider.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Admin/AdminServiceProvider.php b/src/Admin/AdminServiceProvider.php index ea727c2f0..2bed0a017 100644 --- a/src/Admin/AdminServiceProvider.php +++ b/src/Admin/AdminServiceProvider.php @@ -44,6 +44,10 @@ class AdminServiceProvider extends AbstractServiceProvider return new RouteCollection; }); + $this->app->afterResolving('flarum.admin.routes', function (RouteCollection $routes) { + $this->populateRoutes($routes); + }); + $this->app->singleton('flarum.admin.middleware', function (Application $app) { $pipe = new MiddlewarePipe; @@ -103,8 +107,6 @@ class AdminServiceProvider extends AbstractServiceProvider */ public function boot() { - $this->populateRoutes($this->app->make('flarum.admin.routes')); - $this->loadViewsFrom(__DIR__.'/../../views', 'flarum.admin'); $events = $this->app->make('events'); diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php index 94ee49d5b..93787cf93 100644 --- a/src/Forum/ForumServiceProvider.php +++ b/src/Forum/ForumServiceProvider.php @@ -49,6 +49,10 @@ class ForumServiceProvider extends AbstractServiceProvider return new RouteCollection; }); + $this->app->afterResolving('flarum.forum.routes', function (RouteCollection $routes) { + $this->populateRoutes($routes); + }); + $this->app->singleton('flarum.forum.middleware', function (Application $app) { $pipe = new MiddlewarePipe; @@ -110,8 +114,6 @@ class ForumServiceProvider extends AbstractServiceProvider */ public function boot() { - $this->populateRoutes($this->app->make('flarum.forum.routes')); - $this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum'); $this->app->make('view')->share([ From e4514d84131a82785157dd15550ba2278a5cc154 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 19 Dec 2018 21:57:59 +0100 Subject: [PATCH 14/78] Shorten registration of routes --- src/Admin/AdminServiceProvider.php | 6 ++---- src/Api/ApiServiceProvider.php | 6 ++---- src/Forum/ForumServiceProvider.php | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Admin/AdminServiceProvider.php b/src/Admin/AdminServiceProvider.php index 2bed0a017..f7dcab95a 100644 --- a/src/Admin/AdminServiceProvider.php +++ b/src/Admin/AdminServiceProvider.php @@ -41,11 +41,9 @@ class AdminServiceProvider extends AbstractServiceProvider }); $this->app->singleton('flarum.admin.routes', function () { - return new RouteCollection; - }); - - $this->app->afterResolving('flarum.admin.routes', function (RouteCollection $routes) { + $routes = new RouteCollection; $this->populateRoutes($routes); + return $routes; }); $this->app->singleton('flarum.admin.middleware', function (Application $app) { diff --git a/src/Api/ApiServiceProvider.php b/src/Api/ApiServiceProvider.php index d904ec3d9..f3937e7ec 100644 --- a/src/Api/ApiServiceProvider.php +++ b/src/Api/ApiServiceProvider.php @@ -40,11 +40,9 @@ class ApiServiceProvider extends AbstractServiceProvider }); $this->app->singleton('flarum.api.routes', function () { - return new RouteCollection; - }); - - $this->app->afterResolving('flarum.api.routes', function (RouteCollection $routes) { + $routes = new RouteCollection; $this->populateRoutes($routes); + return $routes; }); $this->app->singleton('flarum.api.middleware', function (Application $app) { diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php index 93787cf93..4a975aa22 100644 --- a/src/Forum/ForumServiceProvider.php +++ b/src/Forum/ForumServiceProvider.php @@ -46,11 +46,9 @@ class ForumServiceProvider extends AbstractServiceProvider }); $this->app->singleton('flarum.forum.routes', function () { - return new RouteCollection; - }); - - $this->app->afterResolving('flarum.forum.routes', function (RouteCollection $routes) { + $routes = new RouteCollection; $this->populateRoutes($routes); + return $routes; }); $this->app->singleton('flarum.forum.middleware', function (Application $app) { From 0e5f334a0b5777377a6835e54571d7b9bb2e61c2 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 19 Dec 2018 22:07:20 +0100 Subject: [PATCH 15/78] Locale: Don't resolve manager just to configure it Refs #1578. --- src/Locale/LocaleServiceProvider.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Locale/LocaleServiceProvider.php b/src/Locale/LocaleServiceProvider.php index 87150f848..5e10ed770 100644 --- a/src/Locale/LocaleServiceProvider.php +++ b/src/Locale/LocaleServiceProvider.php @@ -26,14 +26,8 @@ class LocaleServiceProvider extends AbstractServiceProvider */ public function boot(Dispatcher $events) { - $locales = $this->app->make('flarum.locales'); - - $locales->addLocale($this->getDefaultLocale(), 'Default'); - - $events->dispatch(new ConfigureLocales($locales)); - - $events->listen(ClearingCache::class, function () use ($locales) { - $locales->clearCache(); + $events->listen(ClearingCache::class, function () { + $this->app->make('flarum.locales')->clearCache(); }); } @@ -43,10 +37,16 @@ class LocaleServiceProvider extends AbstractServiceProvider public function register() { $this->app->singleton(LocaleManager::class, function () { - return new LocaleManager( + $locales = new LocaleManager( $this->app->make('translator'), $this->getCacheDir() ); + + $locales->addLocale($this->getDefaultLocale(), 'Default'); + + event(new ConfigureLocales($locales)); + + return $locales; }); $this->app->alias(LocaleManager::class, 'flarum.locales'); From 9fe671c9bb4d2e0eb04e4fa5daf9b873d01e9b49 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 19 Dec 2018 22:17:44 +0100 Subject: [PATCH 16/78] Fix UpdateServiceProvider - Shorten registration of routes - Do not resolve view factory before booting --- src/Update/UpdateServiceProvider.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Update/UpdateServiceProvider.php b/src/Update/UpdateServiceProvider.php index 7fc93cdc0..4ef233101 100644 --- a/src/Update/UpdateServiceProvider.php +++ b/src/Update/UpdateServiceProvider.php @@ -23,10 +23,10 @@ class UpdateServiceProvider extends AbstractServiceProvider public function register() { $this->app->singleton('flarum.update.routes', function () { - return new RouteCollection; + $routes = new RouteCollection; + $this->populateRoutes($routes); + return $routes; }); - - $this->loadViewsFrom(__DIR__.'/../../views/install', 'flarum.update'); } /** @@ -34,7 +34,7 @@ class UpdateServiceProvider extends AbstractServiceProvider */ public function boot() { - $this->populateRoutes($this->app->make('flarum.update.routes')); + $this->loadViewsFrom(__DIR__.'/../../views/install', 'flarum.update'); } /** From dbe8cba14e87be96c89a087b5f46db1056040242 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 19 Dec 2018 22:19:34 +0100 Subject: [PATCH 17/78] Avoid unnecessary event subscribers Refs #1578. --- src/Discussion/DiscussionRenamedLogger.php | 8 +------- src/Discussion/DiscussionServiceProvider.php | 6 +++++- src/Extension/DefaultLanguagePackGuard.php | 15 +-------------- src/Extension/ExtensionServiceProvider.php | 8 +++++--- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/Discussion/DiscussionRenamedLogger.php b/src/Discussion/DiscussionRenamedLogger.php index 2ab5f91d5..6eacd994c 100644 --- a/src/Discussion/DiscussionRenamedLogger.php +++ b/src/Discussion/DiscussionRenamedLogger.php @@ -15,7 +15,6 @@ use Flarum\Discussion\Event\Renamed; use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; use Flarum\Notification\NotificationSyncer; use Flarum\Post\DiscussionRenamedPost; -use Illuminate\Contracts\Events\Dispatcher; class DiscussionRenamedLogger { @@ -29,12 +28,7 @@ class DiscussionRenamedLogger $this->notifications = $notifications; } - public function subscribe(Dispatcher $events) - { - $events->listen(Renamed::class, [$this, 'whenDiscussionWasRenamed']); - } - - public function whenDiscussionWasRenamed(Renamed $event) + public function handle(Renamed $event) { $post = DiscussionRenamedPost::reply( $event->discussion->id, diff --git a/src/Discussion/DiscussionServiceProvider.php b/src/Discussion/DiscussionServiceProvider.php index e1c0c466a..f71215bc8 100644 --- a/src/Discussion/DiscussionServiceProvider.php +++ b/src/Discussion/DiscussionServiceProvider.php @@ -11,6 +11,7 @@ namespace Flarum\Discussion; +use Flarum\Discussion\Event\Renamed; use Flarum\Foundation\AbstractServiceProvider; class DiscussionServiceProvider extends AbstractServiceProvider @@ -24,6 +25,9 @@ class DiscussionServiceProvider extends AbstractServiceProvider $events->subscribe(DiscussionMetadataUpdater::class); $events->subscribe(DiscussionPolicy::class); - $events->subscribe(DiscussionRenamedLogger::class); + + $events->listen( + Renamed::class, DiscussionRenamedLogger::class + ); } } diff --git a/src/Extension/DefaultLanguagePackGuard.php b/src/Extension/DefaultLanguagePackGuard.php index 88d98c7a8..b40dbd55b 100644 --- a/src/Extension/DefaultLanguagePackGuard.php +++ b/src/Extension/DefaultLanguagePackGuard.php @@ -14,7 +14,6 @@ namespace Flarum\Extension; use Flarum\Extension\Event\Disabling; use Flarum\Http\Exception\ForbiddenException; use Flarum\Settings\SettingsRepositoryInterface; -use Illuminate\Contracts\Events\Dispatcher; class DefaultLanguagePackGuard { @@ -28,19 +27,7 @@ class DefaultLanguagePackGuard $this->settings = $settings; } - /** - * @param Dispatcher $events - */ - public function subscribe(Dispatcher $events) - { - $events->listen(Disabling::class, [$this, 'whenExtensionWillBeDisabled']); - } - - /** - * @param Disabling $event - * @throws ForbiddenException - */ - public function whenExtensionWillBeDisabled(Disabling $event) + public function handle(Disabling $event) { if (! in_array('flarum-locale', $event->extension->extra)) { return; diff --git a/src/Extension/ExtensionServiceProvider.php b/src/Extension/ExtensionServiceProvider.php index fe5135628..4e43fd9b5 100644 --- a/src/Extension/ExtensionServiceProvider.php +++ b/src/Extension/ExtensionServiceProvider.php @@ -11,6 +11,7 @@ namespace Flarum\Extension; +use Flarum\Extension\Event\Disabling; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Container\Container; @@ -38,8 +39,9 @@ class ExtensionServiceProvider extends AbstractServiceProvider */ public function boot() { - $events = $this->app->make('events'); - - $events->subscribe(DefaultLanguagePackGuard::class); + $this->app->make('events')->listen( + Disabling::class, + DefaultLanguagePackGuard::class + ); } } From cb3baf995598acae1e4bad2a9642455db2e32d51 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 19 Dec 2018 22:42:54 +0100 Subject: [PATCH 18/78] Apply fixes from StyleCI (#1713) [ci skip] [skip ci] --- src/Admin/AdminServiceProvider.php | 1 + src/Api/ApiServiceProvider.php | 1 + src/Forum/ForumServiceProvider.php | 1 + src/Update/UpdateServiceProvider.php | 1 + 4 files changed, 4 insertions(+) diff --git a/src/Admin/AdminServiceProvider.php b/src/Admin/AdminServiceProvider.php index f7dcab95a..5e61729bd 100644 --- a/src/Admin/AdminServiceProvider.php +++ b/src/Admin/AdminServiceProvider.php @@ -43,6 +43,7 @@ class AdminServiceProvider extends AbstractServiceProvider $this->app->singleton('flarum.admin.routes', function () { $routes = new RouteCollection; $this->populateRoutes($routes); + return $routes; }); diff --git a/src/Api/ApiServiceProvider.php b/src/Api/ApiServiceProvider.php index f3937e7ec..eb077259c 100644 --- a/src/Api/ApiServiceProvider.php +++ b/src/Api/ApiServiceProvider.php @@ -42,6 +42,7 @@ class ApiServiceProvider extends AbstractServiceProvider $this->app->singleton('flarum.api.routes', function () { $routes = new RouteCollection; $this->populateRoutes($routes); + return $routes; }); diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php index 4a975aa22..fff5aa788 100644 --- a/src/Forum/ForumServiceProvider.php +++ b/src/Forum/ForumServiceProvider.php @@ -48,6 +48,7 @@ class ForumServiceProvider extends AbstractServiceProvider $this->app->singleton('flarum.forum.routes', function () { $routes = new RouteCollection; $this->populateRoutes($routes); + return $routes; }); diff --git a/src/Update/UpdateServiceProvider.php b/src/Update/UpdateServiceProvider.php index 4ef233101..a23a06fa4 100644 --- a/src/Update/UpdateServiceProvider.php +++ b/src/Update/UpdateServiceProvider.php @@ -25,6 +25,7 @@ class UpdateServiceProvider extends AbstractServiceProvider $this->app->singleton('flarum.update.routes', function () { $routes = new RouteCollection; $this->populateRoutes($routes); + return $routes; }); } From ababb8ebef98ca3e8c86170e1127a672acaf8316 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 13 Dec 2018 21:47:01 +0100 Subject: [PATCH 19/78] Don't resolve services when binding listeners Refs #1578. --- src/Forum/ForumServiceProvider.php | 24 ++++-- src/Forum/ValidateCustomLess.php | 7 -- src/User/AccountActivationMailer.php | 105 +++++++++++++++++++++++++++ src/User/EmailConfirmationMailer.php | 31 +------- src/User/SelfDemotionGuard.php | 11 +-- src/User/UserServiceProvider.php | 9 ++- 6 files changed, 132 insertions(+), 55 deletions(-) create mode 100644 src/User/AccountActivationMailer.php diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php index fff5aa788..16a77e884 100644 --- a/src/Forum/ForumServiceProvider.php +++ b/src/Forum/ForumServiceProvider.php @@ -30,6 +30,7 @@ use Flarum\Http\RouteHandlerFactory; use Flarum\Http\UrlGenerator; use Flarum\Locale\LocaleManager; use Flarum\Settings\Event\Saved; +use Flarum\Settings\Event\Saving; use Flarum\Settings\SettingsRepositoryInterface; use Symfony\Component\Translation\TranslatorInterface; use Zend\Stratigility\MiddlewarePipe; @@ -141,15 +142,26 @@ class ForumServiceProvider extends AbstractServiceProvider $this->app->make(LocaleManager::class) ); $recompile->whenSettingsSaved($event); + + $validator = new ValidateCustomLess( + $this->app->make('flarum.assets.forum'), + $this->app->make('flarum.locales'), + $this->app + ); + $validator->whenSettingsSaved($event); } ); - $events->subscribe( - new ValidateCustomLess( - $this->app->make('flarum.assets.forum'), - $this->app->make('flarum.locales'), - $this->app - ) + $events->listen( + Saving::class, + function (Saving $event) { + $validator = new ValidateCustomLess( + $this->app->make('flarum.assets.forum'), + $this->app->make('flarum.locales'), + $this->app + ); + $validator->whenSettingsSaving($event); + } ); } diff --git a/src/Forum/ValidateCustomLess.php b/src/Forum/ValidateCustomLess.php index a2af7f650..7e3d22fe6 100644 --- a/src/Forum/ValidateCustomLess.php +++ b/src/Forum/ValidateCustomLess.php @@ -19,7 +19,6 @@ use Flarum\Settings\Event\Saving; use Flarum\Settings\OverrideSettingsRepository; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Container\Container; -use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Filesystem\FilesystemAdapter; use League\Flysystem\Adapter\NullAdapter; use League\Flysystem\Filesystem; @@ -54,12 +53,6 @@ class ValidateCustomLess $this->container = $container; } - public function subscribe(Dispatcher $events) - { - $events->listen(Saving::class, [$this, 'whenSettingsSaving']); - $events->listen(Saved::class, [$this, 'whenSettingsSaved']); - } - public function whenSettingsSaving(Saving $event) { if (! isset($event->settings['custom_less'])) { diff --git a/src/User/AccountActivationMailer.php b/src/User/AccountActivationMailer.php new file mode 100644 index 000000000..0ce6ed136 --- /dev/null +++ b/src/User/AccountActivationMailer.php @@ -0,0 +1,105 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\User; + +use Flarum\Http\UrlGenerator; +use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\Event\Registered; +use Illuminate\Contracts\Mail\Mailer; +use Illuminate\Contracts\Translation\Translator; +use Illuminate\Mail\Message; + +class AccountActivationMailer +{ + /** + * @var SettingsRepositoryInterface + */ + protected $settings; + + /** + * @var Mailer + */ + protected $mailer; + + /** + * @var UrlGenerator + */ + protected $url; + + /** + * @var Translator + */ + protected $translator; + + /** + * @param \Flarum\Settings\SettingsRepositoryInterface $settings + * @param Mailer $mailer + * @param UrlGenerator $url + * @param Translator $translator + */ + public function __construct(SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, Translator $translator) + { + $this->settings = $settings; + $this->mailer = $mailer; + $this->url = $url; + $this->translator = $translator; + } + + public function handle(Registered $event) + { + $user = $event->user; + + if ($user->is_email_confirmed) { + return; + } + + $data = $this->getEmailData($user, $user->email); + + $body = $this->translator->trans('core.email.activate_account.body', $data); + + $this->mailer->raw($body, function (Message $message) use ($user, $data) { + $message->to($user->email); + $message->subject('['.$data['{forum}'].'] '.$this->translator->trans('core.email.activate_account.subject')); + }); + } + + /** + * @param User $user + * @param string $email + * @return EmailToken + */ + protected function generateToken(User $user, $email) + { + $token = EmailToken::generate($email, $user->id); + $token->save(); + + return $token; + } + + /** + * Get the data that should be made available to email templates. + * + * @param User $user + * @param string $email + * @return array + */ + protected function getEmailData(User $user, $email) + { + $token = $this->generateToken($user, $email); + + return [ + '{username}' => $user->display_name, + '{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->token]), + '{forum}' => $this->settings->get('forum_title') + ]; + } +} diff --git a/src/User/EmailConfirmationMailer.php b/src/User/EmailConfirmationMailer.php index 074a54c26..dfc403da9 100644 --- a/src/User/EmailConfirmationMailer.php +++ b/src/User/EmailConfirmationMailer.php @@ -14,8 +14,6 @@ namespace Flarum\User; use Flarum\Http\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\User\Event\EmailChangeRequested; -use Flarum\User\Event\Registered; -use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Contracts\Translation\Translator; use Illuminate\Mail\Message; @@ -50,34 +48,7 @@ class EmailConfirmationMailer $this->translator = $translator; } - /** - * @param Dispatcher $events - */ - public function subscribe(Dispatcher $events) - { - $events->listen(Registered::class, [$this, 'whenUserWasRegistered']); - $events->listen(EmailChangeRequested::class, [$this, 'whenUserEmailChangeWasRequested']); - } - - public function whenUserWasRegistered(Registered $event) - { - $user = $event->user; - - if ($user->is_email_confirmed) { - return; - } - - $data = $this->getEmailData($user, $user->email); - - $body = $this->translator->trans('core.email.activate_account.body', $data); - - $this->mailer->raw($body, function (Message $message) use ($user, $data) { - $message->to($user->email); - $message->subject('['.$data['{forum}'].'] '.$this->translator->trans('core.email.activate_account.subject')); - }); - } - - public function whenUserEmailChangeWasRequested(EmailChangeRequested $event) + public function handle(EmailChangeRequested $event) { $email = $event->email; $data = $this->getEmailData($event->user, $email); diff --git a/src/User/SelfDemotionGuard.php b/src/User/SelfDemotionGuard.php index 1aec59e6c..7dff1969e 100644 --- a/src/User/SelfDemotionGuard.php +++ b/src/User/SelfDemotionGuard.php @@ -14,24 +14,15 @@ namespace Flarum\User; use Flarum\Group\Group; use Flarum\User\Event\Saving; use Flarum\User\Exception\PermissionDeniedException; -use Illuminate\Contracts\Events\Dispatcher; class SelfDemotionGuard { - /** - * @param Dispatcher $events - */ - public function subscribe(Dispatcher $events) - { - $events->listen(Saving::class, [$this, 'whenUserWillBeSaved']); - } - /** * Prevent an admin from removing their admin permission via the API. * @param Saving $event * @throws PermissionDeniedException */ - public function whenUserWillBeSaved(Saving $event) + public function handle(Saving $event) { // Non-admin users pose no problem if (! $event->actor->isAdmin()) { diff --git a/src/User/UserServiceProvider.php b/src/User/UserServiceProvider.php index 69a42f143..f0dd773b4 100644 --- a/src/User/UserServiceProvider.php +++ b/src/User/UserServiceProvider.php @@ -14,6 +14,9 @@ namespace Flarum\User; use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetPermission; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\User\Event\EmailChangeRequested; +use Flarum\User\Event\Registered; +use Flarum\User\Event\Saving; use Illuminate\Contracts\Auth\Access\Gate as GateContract; use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Filesystem\Factory; @@ -86,8 +89,10 @@ class UserServiceProvider extends AbstractServiceProvider $events = $this->app->make('events'); - $events->subscribe(SelfDemotionGuard::class); - $events->subscribe(EmailConfirmationMailer::class); + $events->listen(Saving::class, SelfDemotionGuard::class); + $events->listen(Registered::class, AccountActivationMailer::class); + $events->listen(EmailChangeRequested::class, EmailConfirmationMailer::class); + $events->subscribe(UserMetadataUpdater::class); $events->subscribe(UserPolicy::class); From 9794a08f39614d3a16a87dcdb2ea86076915d18e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Wed, 19 Dec 2018 22:50:52 +0100 Subject: [PATCH 20/78] updated constraint for 5.7 (#1698) --- composer.json | 29 ++++++++++++++--------------- src/User/Gate.php | 12 ++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 7b3be9996..650790462 100644 --- a/composer.json +++ b/composer.json @@ -26,20 +26,20 @@ "dflydev/fig-cookies": "^1.0.2", "doctrine/dbal": "^2.7", "franzl/whoops-middleware": "^0.4.0", - "illuminate/bus": "5.5.*", - "illuminate/cache": "5.5.*", - "illuminate/config": "5.5.*", - "illuminate/container": "5.5.*", - "illuminate/contracts": "5.5.*", - "illuminate/database": "5.5.*", - "illuminate/events": "5.5.*", - "illuminate/filesystem": "5.5.*", - "illuminate/hashing": "5.5.*", - "illuminate/mail": "5.5.*", - "illuminate/session": "5.5.*", - "illuminate/support": "5.5.*", - "illuminate/validation": "5.5.*", - "illuminate/view": "5.5.*", + "illuminate/bus": "5.7.*", + "illuminate/cache": "5.7.*", + "illuminate/config": "5.7.*", + "illuminate/container": "5.7.*", + "illuminate/contracts": "5.7.*", + "illuminate/database": "5.7.*", + "illuminate/events": "5.7.*", + "illuminate/filesystem": "5.7.*", + "illuminate/hashing": "5.7.*", + "illuminate/mail": "5.7.*", + "illuminate/session": "5.7.*", + "illuminate/support": "5.7.*", + "illuminate/validation": "5.7.*", + "illuminate/view": "5.7.*", "intervention/image": "^2.3.0", "league/flysystem": "^1.0.11", "matthiasmullie/minify": "^1.3", @@ -55,7 +55,6 @@ "s9e/text-formatter": "^1.2.0", "symfony/config": "^3.3", "symfony/console": "^3.3", - "symfony/http-foundation": "^3.3", "symfony/translation": "^3.3", "symfony/yaml": "^3.3", "tobscure/json-api": "^0.3.0", diff --git a/src/User/Gate.php b/src/User/Gate.php index de6bc9709..73cbfe97d 100644 --- a/src/User/Gate.php +++ b/src/User/Gate.php @@ -400,4 +400,16 @@ class Gate implements GateContract { // TODO: Implement abilities() method. } + + /** + * Get the raw result from the authorization callback. + * + * @param string $ability + * @param array|mixed $arguments + * @return mixed + */ + public function raw($ability, $arguments = []) + { + // TODO: Implement raw() method. + } } From ac5e26a254d89e21bd4c115b6cbd40338e2e4b4b Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 20 Dec 2018 13:09:21 +0100 Subject: [PATCH 21/78] Use a custom service provider for email configuration --- src/Foundation/InstalledSite.php | 13 ----- src/Foundation/MailServiceProvider.php | 79 ++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 src/Foundation/MailServiceProvider.php diff --git a/src/Foundation/InstalledSite.php b/src/Foundation/InstalledSite.php index de15623bd..d59a5443f 100644 --- a/src/Foundation/InstalledSite.php +++ b/src/Foundation/InstalledSite.php @@ -40,7 +40,6 @@ use Illuminate\Contracts\Container\Container; use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\FilesystemServiceProvider; use Illuminate\Hashing\HashServiceProvider; -use Illuminate\Mail\MailServiceProvider; use Illuminate\Validation\ValidationServiceProvider; use Illuminate\View\ViewServiceProvider; use Monolog\Formatter\LineFormatter; @@ -118,18 +117,6 @@ class InstalledSite implements SiteInterface $laravel->register(MailServiceProvider::class); $laravel->register(ViewServiceProvider::class); $laravel->register(ValidationServiceProvider::class); - - $settings = $laravel->make(SettingsRepositoryInterface::class); - - $config->set('mail.driver', $settings->get('mail_driver')); - $config->set('mail.host', $settings->get('mail_host')); - $config->set('mail.port', $settings->get('mail_port')); - $config->set('mail.from.address', $settings->get('mail_from')); - $config->set('mail.from.name', $settings->get('forum_title')); - $config->set('mail.encryption', $settings->get('mail_encryption')); - $config->set('mail.username', $settings->get('mail_username')); - $config->set('mail.password', $settings->get('mail_password')); - $laravel->register(DiscussionServiceProvider::class); $laravel->register(FormatterServiceProvider::class); $laravel->register(FrontendServiceProvider::class); diff --git a/src/Foundation/MailServiceProvider.php b/src/Foundation/MailServiceProvider.php new file mode 100644 index 000000000..362832c36 --- /dev/null +++ b/src/Foundation/MailServiceProvider.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Foundation; + +use Flarum\Settings\SettingsRepositoryInterface; +use Illuminate\Mail\Mailer; +use Illuminate\Mail\Transport\LogTransport; +use InvalidArgumentException; +use Psr\Log\LoggerInterface; +use Swift_Mailer; +use Swift_SendmailTransport; +use Swift_SmtpTransport; +use Swift_Transport; + +class MailServiceProvider extends AbstractServiceProvider +{ + public function register() + { + $this->app->singleton('swift.mailer', function ($app) { + $settings = $app->make(SettingsRepositoryInterface::class); + + return new Swift_Mailer( + $this->buildTransport($settings) + ); + }); + + $this->app->singleton('mailer', function ($app) { + $mailer = new Mailer( + $app['view'], $app['swift.mailer'], $app['events'] + ); + + if ($app->bound('queue')) { + $mailer->setQueue($app->make('queue')); + } + + $settings = $app->make(SettingsRepositoryInterface::class); + $mailer->alwaysFrom($settings->get('mail_from'), $settings->get('forum_title')); + + return $mailer; + }); + } + + private function buildTransport(SettingsRepositoryInterface $settings): Swift_Transport + { + switch ($settings->get('mail_driver')) { + case 'smtp': + return $this->buildSmtpTransport($settings); + case 'mail': + return new Swift_SendmailTransport; + case 'log': + return new LogTransport($this->app->make(LoggerInterface::class)); + default: + throw new InvalidArgumentException('Invalid mail driver configuration'); + } + } + + private function buildSmtpTransport(SettingsRepositoryInterface $settings): Swift_Transport + { + $transport = new Swift_SmtpTransport( + $settings->get('mail_host'), + $settings->get('mail_port'), + $settings->get('mail_encryption') + ); + + $transport->setUsername($settings->get('mail_username')); + $transport->setPassword($settings->get('mail_password')); + + return $transport; + } +} From 9db04a4e1988fbddd105bbdce942f20fe09a90b4 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 20 Dec 2018 13:13:04 +0100 Subject: [PATCH 22/78] Register service providers alphabetically Order should not matter - and this is the only one that can realistically stay consistent. --- src/Foundation/InstalledSite.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Foundation/InstalledSite.php b/src/Foundation/InstalledSite.php index d59a5443f..db5df9412 100644 --- a/src/Foundation/InstalledSite.php +++ b/src/Foundation/InstalledSite.php @@ -107,32 +107,30 @@ class InstalledSite implements SiteInterface $this->registerLogger($laravel); $this->registerCache($laravel); - $laravel->register(DatabaseServiceProvider::class); - $laravel->register(MigrationServiceProvider::class); - $laravel->register(SettingsServiceProvider::class); - $laravel->register(LocaleServiceProvider::class); + $laravel->register(AdminServiceProvider::class); + $laravel->register(ApiServiceProvider::class); $laravel->register(BusServiceProvider::class); - $laravel->register(FilesystemServiceProvider::class); - $laravel->register(HashServiceProvider::class); - $laravel->register(MailServiceProvider::class); - $laravel->register(ViewServiceProvider::class); - $laravel->register(ValidationServiceProvider::class); + $laravel->register(DatabaseServiceProvider::class); $laravel->register(DiscussionServiceProvider::class); + $laravel->register(ExtensionServiceProvider::class); + $laravel->register(FilesystemServiceProvider::class); $laravel->register(FormatterServiceProvider::class); + $laravel->register(ForumServiceProvider::class); $laravel->register(FrontendServiceProvider::class); $laravel->register(GroupServiceProvider::class); + $laravel->register(HashServiceProvider::class); + $laravel->register(LocaleServiceProvider::class); + $laravel->register(MailServiceProvider::class); + $laravel->register(MigrationServiceProvider::class); $laravel->register(NotificationServiceProvider::class); $laravel->register(PostServiceProvider::class); $laravel->register(SearchServiceProvider::class); $laravel->register(SessionServiceProvider::class); - $laravel->register(UserServiceProvider::class); + $laravel->register(SettingsServiceProvider::class); $laravel->register(UpdateServiceProvider::class); - - $laravel->register(ApiServiceProvider::class); - $laravel->register(ForumServiceProvider::class); - $laravel->register(AdminServiceProvider::class); - - $laravel->register(ExtensionServiceProvider::class); + $laravel->register(UserServiceProvider::class); + $laravel->register(ValidationServiceProvider::class); + $laravel->register(ViewServiceProvider::class); $laravel->booting(function (Container $app) { // Run all local-site extenders before booting service providers From 8a93f8b6b6a95a44b327c12247884a14a2885891 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 20 Dec 2018 13:13:58 +0100 Subject: [PATCH 23/78] Apply fixes from StyleCI (#1714) [ci skip] [skip ci] --- src/Foundation/InstalledSite.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Foundation/InstalledSite.php b/src/Foundation/InstalledSite.php index db5df9412..bf1de46c5 100644 --- a/src/Foundation/InstalledSite.php +++ b/src/Foundation/InstalledSite.php @@ -26,7 +26,6 @@ use Flarum\Locale\LocaleServiceProvider; use Flarum\Notification\NotificationServiceProvider; use Flarum\Post\PostServiceProvider; use Flarum\Search\SearchServiceProvider; -use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsServiceProvider; use Flarum\Update\UpdateServiceProvider; use Flarum\User\SessionServiceProvider; From 208bad393f37bfdb76007afcddfa4b7451563e9d Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 20 Dec 2018 13:31:28 +0100 Subject: [PATCH 24/78] Mail: Add an array of supported drivers This can be used for e.g. validation, or a dropdown in the frontend. It can also be extended by extensions, such as flagrow/mail-drivers. Refs #1169. --- src/Foundation/MailServiceProvider.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Foundation/MailServiceProvider.php b/src/Foundation/MailServiceProvider.php index 362832c36..19bfb16b9 100644 --- a/src/Foundation/MailServiceProvider.php +++ b/src/Foundation/MailServiceProvider.php @@ -25,6 +25,10 @@ class MailServiceProvider extends AbstractServiceProvider { public function register() { + $this->app->singleton('mail.supported_drivers', function () { + return ['smtp', 'mail', 'log']; + }); + $this->app->singleton('swift.mailer', function ($app) { $settings = $app->make(SettingsRepositoryInterface::class); From 167059027e5a066d618599c90164ef1b5a509148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Tue, 1 Jan 2019 21:02:18 +0100 Subject: [PATCH 25/78] Increasing test coverage (#1711) * added a few more tests, renamed singular to plural to match controller * increase error reporting * removed debugging and wait for tests --- .travis.yml | 3 ++ ....php => ListDiscussionsControllerTest.php} | 2 +- .../Controller/ListGroupsControllerTest.php | 33 +++++++++++++++ .../ListNotificationsControllerTest.php | 40 +++++++++++++++++++ .../Controller/ListUsersControllerTest.php | 40 +++++++++++++++++++ 5 files changed, 117 insertions(+), 1 deletion(-) rename tests/Api/Controller/{ListDiscussionControllerTest.php => ListDiscussionsControllerTest.php} (94%) create mode 100644 tests/Api/Controller/ListGroupsControllerTest.php create mode 100644 tests/Api/Controller/ListNotificationsControllerTest.php create mode 100644 tests/Api/Controller/ListUsersControllerTest.php diff --git a/.travis.yml b/.travis.yml index c62d1e8d6..d4a4effca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,9 @@ install: - composer install - mysql -e 'CREATE DATABASE flarum;' +before_script: + - echo 'error_reporting = E_ALL' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini + script: - vendor/bin/phpunit --coverage-clover=coverage.xml diff --git a/tests/Api/Controller/ListDiscussionControllerTest.php b/tests/Api/Controller/ListDiscussionsControllerTest.php similarity index 94% rename from tests/Api/Controller/ListDiscussionControllerTest.php rename to tests/Api/Controller/ListDiscussionsControllerTest.php index 276d0273a..c7d2abe93 100644 --- a/tests/Api/Controller/ListDiscussionControllerTest.php +++ b/tests/Api/Controller/ListDiscussionsControllerTest.php @@ -14,7 +14,7 @@ namespace Flarum\Tests\Api\Controller; use Flarum\Api\Controller\ListDiscussionsController; use Flarum\Discussion\Discussion; -class ListDiscussionControllerTest extends ApiControllerTestCase +class ListDiscussionsControllerTest extends ApiControllerTestCase { protected $controller = ListDiscussionsController::class; diff --git a/tests/Api/Controller/ListGroupsControllerTest.php b/tests/Api/Controller/ListGroupsControllerTest.php new file mode 100644 index 000000000..34d945a90 --- /dev/null +++ b/tests/Api/Controller/ListGroupsControllerTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Tests\Api\Controller; + +use Flarum\Api\Controller\ListGroupsController; +use Flarum\Group\Group; + +class ListGroupsControllerTest extends ApiControllerTestCase +{ + protected $controller = ListGroupsController::class; + + /** + * @test + */ + public function shows_index_for_guest() + { + $response = $this->callWith(); + + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($response->getBody()->getContents(), true); + + $this->assertEquals(Group::count(), count($data['data'])); + } +} diff --git a/tests/Api/Controller/ListNotificationsControllerTest.php b/tests/Api/Controller/ListNotificationsControllerTest.php new file mode 100644 index 000000000..f269b8da8 --- /dev/null +++ b/tests/Api/Controller/ListNotificationsControllerTest.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Tests\Api\Controller; + +use Flarum\Api\Controller\ListNotificationsController; + +class ListNotificationsControllerTest extends ApiControllerTestCase +{ + protected $controller = ListNotificationsController::class; + + /** + * @test + * @expectedException \Flarum\User\Exception\PermissionDeniedException + */ + public function disallows_index_for_guest() + { + $this->callWith(); + } + + /** + * @test + */ + public function show_index_for_user() + { + $this->actor = $this->getNormalUser(); + + $response = $this->callWith(); + + $this->assertEquals(200, $response->getStatusCode()); + } +} diff --git a/tests/Api/Controller/ListUsersControllerTest.php b/tests/Api/Controller/ListUsersControllerTest.php new file mode 100644 index 000000000..34350db87 --- /dev/null +++ b/tests/Api/Controller/ListUsersControllerTest.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Tests\Api\Controller; + +use Flarum\Api\Controller\ListUsersController; + +class ListUsersControllerTest extends ApiControllerTestCase +{ + protected $controller = ListUsersController::class; + + /** + * @test + * @expectedException \Flarum\User\Exception\PermissionDeniedException + */ + public function disallows_index_for_guest() + { + $this->callWith(); + } + + /** + * @test + */ + public function shows_index_for_admin() + { + $this->actor = $this->getAdminUser(); + + $response = $this->callWith(); + + $this->assertEquals(200, $response->getStatusCode()); + } +} From 390148456c8c8e6cb28943db17216fffc0c91197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Tue, 15 Jan 2019 20:39:38 +0100 Subject: [PATCH 26/78] reverts #96e2824 --- ..._change_access_tokens_add_foreign_keys.php | 5 ---- ...8_01_11_095000_change_api_keys_columns.php | 17 +++--------- ...00_change_discussions_add_foreign_keys.php | 5 ---- ...hange_discussion_user_add_foreign_keys.php | 5 ---- ...0_change_email_tokens_add_foreign_keys.php | 5 ---- ...ange_group_permission_add_foreign_keys.php | 5 ---- ...700_change_group_user_add_foreign_keys.php | 5 ---- ..._change_notifications_add_foreign_keys.php | 5 ---- ...hange_password_tokens_add_foreign_keys.php | 5 ---- ...8_135100_change_posts_add_foreign_keys.php | 5 ---- .../2018_09_15_041340_add_users_indicies.php | 5 ---- ..._09_15_041828_add_discussions_indicies.php | 5 ---- ...09_15_043337_add_notifications_indices.php | 5 ---- .../2018_09_15_043621_add_posts_indices.php | 5 ---- src/Database/Migration.php | 27 ------------------- 15 files changed, 4 insertions(+), 105 deletions(-) diff --git a/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php b/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php index 31a7bf073..7ed9921ce 100644 --- a/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php +++ b/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,16 +25,12 @@ return [ $schema->table('access_tokens', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('access_tokens', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_01_11_095000_change_api_keys_columns.php b/migrations/2018_01_11_095000_change_api_keys_columns.php index 6f2cc0a2e..eaa6246b4 100644 --- a/migrations/2018_01_11_095000_change_api_keys_columns.php +++ b/migrations/2018_01_11_095000_change_api_keys_columns.php @@ -9,21 +9,18 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('api_keys', function (Blueprint $table) use ($schema) { + $schema->table('api_keys', function (Blueprint $table) { $table->dropPrimary(['id']); $table->renameColumn('id', 'key'); $table->unique('key'); - - Migration::fixIndexNames($schema, $table); }); - $schema->table('api_keys', function (Blueprint $table) use ($schema) { + $schema->table('api_keys', function (Blueprint $table) { $table->increments('id'); $table->string('allowed_ips')->nullable(); $table->string('scopes')->nullable(); @@ -32,25 +29,19 @@ return [ $table->dateTime('last_activity_at')->nullable(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { - $schema->table('api_keys', function (Blueprint $table) use ($schema) { + $schema->table('api_keys', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropColumn('id', 'allowed_ips', 'user_id', 'scopes', 'created_at'); - - Migration::fixIndexNames($schema, $table); }); - $schema->table('api_keys', function (Blueprint $table) use ($schema) { + $schema->table('api_keys', function (Blueprint $table) { $table->dropUnique(['key']); $table->renameColumn('key', 'id'); $table->primary('id'); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php b/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php index e71e11680..4c8b68a3d 100644 --- a/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php +++ b/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -40,8 +39,6 @@ return [ $table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('first_post_id')->references('id')->on('posts')->onDelete('set null'); $table->foreign('last_post_id')->references('id')->on('posts')->onDelete('set null'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -52,8 +49,6 @@ return [ $table->dropForeign(['hidden_user_id']); $table->dropForeign(['first_post_id']); $table->dropForeign(['last_post_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php b/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php index f83c196f4..fdbfc22c4 100644 --- a/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php +++ b/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -30,8 +29,6 @@ return [ $schema->table('discussion_user', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -39,8 +36,6 @@ return [ $schema->table('discussion_user', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); $table->dropForeign(['discussion_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php b/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php index 943870e97..7d3053d04 100644 --- a/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php +++ b/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,16 +25,12 @@ return [ $schema->table('email_tokens', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('email_tokens', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php b/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php index 0952bb7b0..b24fc8acb 100644 --- a/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php +++ b/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,16 +25,12 @@ return [ $schema->table('group_permission', function (Blueprint $table) use ($schema) { $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('group_permission', function (Blueprint $table) use ($schema) { $table->dropForeign(['group_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php b/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php index aa7b8785a..5a9bbdb34 100644 --- a/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php +++ b/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -30,8 +29,6 @@ return [ $schema->table('group_user', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -39,8 +36,6 @@ return [ $schema->table('group_user', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); $table->dropForeign(['group_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php b/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php index 043d7e4c6..3f1f18f98 100644 --- a/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php +++ b/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -34,8 +33,6 @@ return [ $schema->table('notifications', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('from_user_id')->references('id')->on('users')->onDelete('set null'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -43,8 +40,6 @@ return [ $schema->table('notifications', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); $table->dropForeign(['from_user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php b/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php index 8d21b9cf3..6004e4049 100644 --- a/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php +++ b/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,16 +25,12 @@ return [ $schema->table('password_tokens', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('password_tokens', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php b/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php index 2a6d0e771..1cc9d84e2 100644 --- a/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php +++ b/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -36,8 +35,6 @@ return [ $table->foreign('user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('edited_user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -47,8 +44,6 @@ return [ $table->dropForeign(['discussion_id']); $table->dropForeign(['edited_user_id']); $table->dropForeign(['hidden_user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_09_15_041340_add_users_indicies.php b/migrations/2018_09_15_041340_add_users_indicies.php index 263198af9..c1ad4c373 100644 --- a/migrations/2018_09_15_041340_add_users_indicies.php +++ b/migrations/2018_09_15_041340_add_users_indicies.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -20,8 +19,6 @@ return [ $table->index('last_seen_at'); $table->index('discussion_count'); $table->index('comment_count'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -31,8 +28,6 @@ return [ $table->dropIndex(['last_seen_at']); $table->dropIndex(['discussion_count']); $table->dropIndex(['comment_count']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_09_15_041828_add_discussions_indicies.php b/migrations/2018_09_15_041828_add_discussions_indicies.php index eb73350ba..04e47415c 100644 --- a/migrations/2018_09_15_041828_add_discussions_indicies.php +++ b/migrations/2018_09_15_041828_add_discussions_indicies.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -23,8 +22,6 @@ return [ $table->index('comment_count'); $table->index('participant_count'); $table->index('hidden_at'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -37,8 +34,6 @@ return [ $table->dropIndex(['comment_count']); $table->dropIndex(['participant_count']); $table->dropIndex(['hidden_at']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_09_15_043337_add_notifications_indices.php b/migrations/2018_09_15_043337_add_notifications_indices.php index 78f123ab2..8aee5d098 100644 --- a/migrations/2018_09_15_043337_add_notifications_indices.php +++ b/migrations/2018_09_15_043337_add_notifications_indices.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -17,16 +16,12 @@ return [ 'up' => function (Builder $schema) { $schema->table('notifications', function (Blueprint $table) use ($schema) { $table->index('user_id'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('notifications', function (Blueprint $table) use ($schema) { $table->dropIndex(['user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/migrations/2018_09_15_043621_add_posts_indices.php b/migrations/2018_09_15_043621_add_posts_indices.php index 419d52a4c..6e67c197d 100644 --- a/migrations/2018_09_15_043621_add_posts_indices.php +++ b/migrations/2018_09_15_043621_add_posts_indices.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -19,8 +18,6 @@ return [ $table->index(['discussion_id', 'number']); $table->index(['discussion_id', 'created_at']); $table->index(['user_id', 'created_at']); - - Migration::fixIndexNames($schema, $table); }); }, @@ -29,8 +26,6 @@ return [ $table->dropIndex(['discussion_id', 'number']); $table->dropIndex(['discussion_id', 'created_at']); $table->dropIndex(['user_id', 'created_at']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/src/Database/Migration.php b/src/Database/Migration.php index 6226bd913..6af42bfdf 100644 --- a/src/Database/Migration.php +++ b/src/Database/Migration.php @@ -31,8 +31,6 @@ abstract class Migration 'up' => function (Builder $schema) use ($name, $definition) { $schema->create($name, function (Blueprint $table) use ($schema, $definition) { $definition($table); - - static::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) use ($name) { @@ -68,8 +66,6 @@ abstract class Migration $type = array_shift($options); $table->addColumn($type, $columnName, $options); } - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) use ($tableName, $columnDefinitions) { @@ -193,27 +189,4 @@ abstract class Migration } ]; } - - /** - * Add a prefix to index names on the given table blueprint. - * - * Laravel 5.5 doesn't automatically add the table prefix to index - * names, but this has been fixed in 5.7. We will manually fix the - * names for now, and we can remove this when we upgrade to 5.7. - */ - public static function fixIndexNames(Builder $schema, Blueprint $table) - { - $indexCommands = [ - 'unique', 'index', 'spatialIndex', 'foreign', - 'dropUnique', 'dropIndex', 'dropSpatialIndex', 'dropForeign' - ]; - - $prefix = $schema->getConnection()->getTablePrefix(); - - foreach ($table->getCommands() as $command) { - if (in_array($command->name, $indexCommands)) { - $command->index = $prefix.$command->index; - } - } - } } From 54fdc40d873f799821a29cf7c72c03ed47ce6985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Tue, 15 Jan 2019 20:49:06 +0100 Subject: [PATCH 27/78] further revert #96e2824 --- ...018_01_11_094000_change_access_tokens_add_foreign_keys.php | 4 ++-- .../2018_01_11_155300_change_discussions_add_foreign_keys.php | 4 ++-- ...8_01_15_071900_change_discussion_user_add_foreign_keys.php | 4 ++-- ...2018_01_15_072700_change_email_tokens_add_foreign_keys.php | 4 ++-- ..._01_18_130500_change_group_permission_add_foreign_keys.php | 4 ++-- .../2018_01_18_130700_change_group_user_add_foreign_keys.php | 4 ++-- ...018_01_18_133100_change_notifications_add_foreign_keys.php | 4 ++-- ...8_01_18_134500_change_password_tokens_add_foreign_keys.php | 4 ++-- .../2018_01_18_135100_change_posts_add_foreign_keys.php | 4 ++-- migrations/2018_09_15_041340_add_users_indicies.php | 4 ++-- migrations/2018_09_15_041828_add_discussions_indicies.php | 4 ++-- migrations/2018_09_15_043337_add_notifications_indices.php | 4 ++-- migrations/2018_09_15_043621_add_posts_indices.php | 4 ++-- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php b/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php index 7ed9921ce..3103a963e 100644 --- a/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php +++ b/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php @@ -23,13 +23,13 @@ return [ }) ->delete(); - $schema->table('access_tokens', function (Blueprint $table) use ($schema) { + $schema->table('access_tokens', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); }, 'down' => function (Builder $schema) { - $schema->table('access_tokens', function (Blueprint $table) use ($schema) { + $schema->table('access_tokens', function (Blueprint $table) { $table->dropForeign(['user_id']); }); } diff --git a/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php b/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php index 4c8b68a3d..24aa03efd 100644 --- a/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php +++ b/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php @@ -33,7 +33,7 @@ return [ 'last_post_id' => $selectId('posts', 'last_post_id'), ]); - $schema->table('discussions', function (Blueprint $table) use ($schema) { + $schema->table('discussions', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('last_posted_user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null'); @@ -43,7 +43,7 @@ return [ }, 'down' => function (Builder $schema) { - $schema->table('discussions', function (Blueprint $table) use ($schema) { + $schema->table('discussions', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropForeign(['last_posted_user_id']); $table->dropForeign(['hidden_user_id']); diff --git a/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php b/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php index fdbfc22c4..e7d8aa99d 100644 --- a/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php +++ b/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php @@ -26,14 +26,14 @@ return [ }) ->delete(); - $schema->table('discussion_user', function (Blueprint $table) use ($schema) { + $schema->table('discussion_user', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); }); }, 'down' => function (Builder $schema) { - $schema->table('discussion_user', function (Blueprint $table) use ($schema) { + $schema->table('discussion_user', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropForeign(['discussion_id']); }); diff --git a/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php b/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php index 7d3053d04..243b706f3 100644 --- a/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php +++ b/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php @@ -23,13 +23,13 @@ return [ }) ->delete(); - $schema->table('email_tokens', function (Blueprint $table) use ($schema) { + $schema->table('email_tokens', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); }, 'down' => function (Builder $schema) { - $schema->table('email_tokens', function (Blueprint $table) use ($schema) { + $schema->table('email_tokens', function (Blueprint $table) { $table->dropForeign(['user_id']); }); } diff --git a/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php b/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php index b24fc8acb..267a09dc0 100644 --- a/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php +++ b/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php @@ -23,13 +23,13 @@ return [ }) ->delete(); - $schema->table('group_permission', function (Blueprint $table) use ($schema) { + $schema->table('group_permission', function (Blueprint $table) { $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); }); }, 'down' => function (Builder $schema) { - $schema->table('group_permission', function (Blueprint $table) use ($schema) { + $schema->table('group_permission', function (Blueprint $table) { $table->dropForeign(['group_id']); }); } diff --git a/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php b/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php index 5a9bbdb34..9358bec93 100644 --- a/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php +++ b/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php @@ -26,14 +26,14 @@ return [ }) ->delete(); - $schema->table('group_user', function (Blueprint $table) use ($schema) { + $schema->table('group_user', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); }); }, 'down' => function (Builder $schema) { - $schema->table('group_user', function (Blueprint $table) use ($schema) { + $schema->table('group_user', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropForeign(['group_id']); }); diff --git a/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php b/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php index 3f1f18f98..f3b1af325 100644 --- a/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php +++ b/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php @@ -30,14 +30,14 @@ return [ }) ->update(['from_user_id' => null]); - $schema->table('notifications', function (Blueprint $table) use ($schema) { + $schema->table('notifications', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('from_user_id')->references('id')->on('users')->onDelete('set null'); }); }, 'down' => function (Builder $schema) { - $schema->table('notifications', function (Blueprint $table) use ($schema) { + $schema->table('notifications', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropForeign(['from_user_id']); }); diff --git a/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php b/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php index 6004e4049..cb7303e71 100644 --- a/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php +++ b/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php @@ -23,13 +23,13 @@ return [ }) ->delete(); - $schema->table('password_tokens', function (Blueprint $table) use ($schema) { + $schema->table('password_tokens', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); }, 'down' => function (Builder $schema) { - $schema->table('password_tokens', function (Blueprint $table) use ($schema) { + $schema->table('password_tokens', function (Blueprint $table) { $table->dropForeign(['user_id']); }); } diff --git a/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php b/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php index 1cc9d84e2..00ef23223 100644 --- a/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php +++ b/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php @@ -31,7 +31,7 @@ return [ 'hidden_user_id' => $selectId('users', 'hidden_user_id'), ]); - $schema->table('posts', function (Blueprint $table) use ($schema) { + $schema->table('posts', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('edited_user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null'); @@ -39,7 +39,7 @@ return [ }, 'down' => function (Builder $schema) { - $schema->table('posts', function (Blueprint $table) use ($schema) { + $schema->table('posts', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropForeign(['discussion_id']); $table->dropForeign(['edited_user_id']); diff --git a/migrations/2018_09_15_041340_add_users_indicies.php b/migrations/2018_09_15_041340_add_users_indicies.php index c1ad4c373..30aebd912 100644 --- a/migrations/2018_09_15_041340_add_users_indicies.php +++ b/migrations/2018_09_15_041340_add_users_indicies.php @@ -14,7 +14,7 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('users', function (Blueprint $table) use ($schema) { + $schema->table('users', function (Blueprint $table) { $table->index('joined_at'); $table->index('last_seen_at'); $table->index('discussion_count'); @@ -23,7 +23,7 @@ return [ }, 'down' => function (Builder $schema) { - $schema->table('users', function (Blueprint $table) use ($schema) { + $schema->table('users', function (Blueprint $table) { $table->dropIndex(['joined_at']); $table->dropIndex(['last_seen_at']); $table->dropIndex(['discussion_count']); diff --git a/migrations/2018_09_15_041828_add_discussions_indicies.php b/migrations/2018_09_15_041828_add_discussions_indicies.php index 04e47415c..15433f0fb 100644 --- a/migrations/2018_09_15_041828_add_discussions_indicies.php +++ b/migrations/2018_09_15_041828_add_discussions_indicies.php @@ -14,7 +14,7 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('discussions', function (Blueprint $table) use ($schema) { + $schema->table('discussions', function (Blueprint $table) { $table->index('last_posted_at'); $table->index('last_posted_user_id'); $table->index('created_at'); @@ -26,7 +26,7 @@ return [ }, 'down' => function (Builder $schema) { - $schema->table('discussions', function (Blueprint $table) use ($schema) { + $schema->table('discussions', function (Blueprint $table) { $table->dropIndex(['last_posted_at']); $table->dropIndex(['last_posted_user_id']); $table->dropIndex(['created_at']); diff --git a/migrations/2018_09_15_043337_add_notifications_indices.php b/migrations/2018_09_15_043337_add_notifications_indices.php index 8aee5d098..724c79eb6 100644 --- a/migrations/2018_09_15_043337_add_notifications_indices.php +++ b/migrations/2018_09_15_043337_add_notifications_indices.php @@ -14,13 +14,13 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('notifications', function (Blueprint $table) use ($schema) { + $schema->table('notifications', function (Blueprint $table) { $table->index('user_id'); }); }, 'down' => function (Builder $schema) { - $schema->table('notifications', function (Blueprint $table) use ($schema) { + $schema->table('notifications', function (Blueprint $table) { $table->dropIndex(['user_id']); }); } diff --git a/migrations/2018_09_15_043621_add_posts_indices.php b/migrations/2018_09_15_043621_add_posts_indices.php index 6e67c197d..484a3b842 100644 --- a/migrations/2018_09_15_043621_add_posts_indices.php +++ b/migrations/2018_09_15_043621_add_posts_indices.php @@ -14,7 +14,7 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('posts', function (Blueprint $table) use ($schema) { + $schema->table('posts', function (Blueprint $table) { $table->index(['discussion_id', 'number']); $table->index(['discussion_id', 'created_at']); $table->index(['user_id', 'created_at']); @@ -22,7 +22,7 @@ return [ }, 'down' => function (Builder $schema) { - $schema->table('posts', function (Blueprint $table) use ($schema) { + $schema->table('posts', function (Blueprint $table) { $table->dropIndex(['discussion_id', 'number']); $table->dropIndex(['discussion_id', 'created_at']); $table->dropIndex(['user_id', 'created_at']); From 1b2d4f1e1deb98cb9305a5a9053b61caefe1f349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Tue, 15 Jan 2019 20:49:33 +0100 Subject: [PATCH 28/78] set prefixing indices to be done automatically, now that illuminate can take care of that --- src/Database/DatabaseServiceProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Database/DatabaseServiceProvider.php b/src/Database/DatabaseServiceProvider.php index 12892f2fb..9ed02d6dc 100644 --- a/src/Database/DatabaseServiceProvider.php +++ b/src/Database/DatabaseServiceProvider.php @@ -30,6 +30,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider $dbConfig = $this->app->config('database'); $dbConfig['engine'] = 'InnoDB'; + $dbConfig['prefix_indexes'] = true; $connection = $factory->make($dbConfig); $connection->setEventDispatcher($this->app->make(Dispatcher::class)); From c67fb2d4b6a128c71d65dc6703310c0b62f91be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Wed, 16 Jan 2019 09:58:22 +0100 Subject: [PATCH 29/78] fixes #1686, unable to edit user password --- js/src/forum/components/EditUserModal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/forum/components/EditUserModal.js b/js/src/forum/components/EditUserModal.js index 99f43a517..5c70b4a94 100644 --- a/js/src/forum/components/EditUserModal.js +++ b/js/src/forum/components/EditUserModal.js @@ -77,7 +77,7 @@ export default class EditUserModal extends Modal {