From 2bd5e3bcc5e9b1ec8bf28f3ef36726c0c0b124ed Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Tue, 17 Apr 2018 11:41:55 +0200 Subject: [PATCH 01/85] restarted the branch using the already created migrations --- ...093900_change_access_tokens_b8_columns.php | 33 ++++++++++ ...okens_make_activity_at_column_datetime.php | 27 ++++++++ ...94900_change_api_keys_rename_id_to_key.php | 29 +++++++++ ...1_11_095000_change_api_keys_b8_columns.php | 35 +++++++++++ ...ame_auth_tokens_to_registration_tokens.php | 14 +++++ ...registration_tokens_rename_id_to_token.php | 27 ++++++++ ...1_155200_change_discussions_b8_columns.php | 45 +++++++++++++ ...nge_user_discussions_discussions_users.php | 22 +++++++ ...00_change_discussions_users_b8_columns.php | 29 +++++++++ ..._072600_change_email_tokens_b8_columns.php | 27 ++++++++ ...ename_permissions_to_group_permissions.php | 14 +++++ ...00_rename_users_groups_to_groups_users.php | 14 +++++ ...132900_create_notifications_from_table.php | 40 ++++++++++++ ...133000_change_notifications_b8_columns.php | 63 +++++++++++++++++++ ...400_change_password_tokens_id_to_token.php | 14 +++++ ...8_01_18_135000_change_posts_b8_columns.php | 42 +++++++++++++ ..._084700_change_settings_value_longblob.php | 26 ++++++++ ..._01_30_220100_create_posts_users_table.php | 29 +++++++++ ...8_01_30_222900_change_users_b8_columns.php | 44 +++++++++++++ ..._01_30_223700_create_users_users_table.php | 29 +++++++++ 20 files changed, 603 insertions(+) create mode 100644 framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php create mode 100644 framework/core/migrations/2018_01_11_094800_change_access_tokens_make_activity_at_column_datetime.php create mode 100644 framework/core/migrations/2018_01_11_094900_change_api_keys_rename_id_to_key.php create mode 100644 framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php create mode 100644 framework/core/migrations/2018_01_11_101800_rename_auth_tokens_to_registration_tokens.php create mode 100644 framework/core/migrations/2018_01_11_102000_change_registration_tokens_rename_id_to_token.php create mode 100644 framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php create mode 100644 framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php create mode 100644 framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php create mode 100644 framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php create mode 100644 framework/core/migrations/2018_01_18_130400_rename_permissions_to_group_permissions.php create mode 100644 framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php create mode 100644 framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php create mode 100644 framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php create mode 100644 framework/core/migrations/2018_01_18_134400_change_password_tokens_id_to_token.php create mode 100644 framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php create mode 100644 framework/core/migrations/2018_01_19_084700_change_settings_value_longblob.php create mode 100644 framework/core/migrations/2018_01_30_220100_create_posts_users_table.php create mode 100644 framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php create mode 100644 framework/core/migrations/2018_01_30_223700_create_users_users_table.php diff --git a/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php b/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php new file mode 100644 index 000000000..9fd9df5fb --- /dev/null +++ b/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('access_tokens', function (Blueprint $table) { + $table->renameColumn('id', 'token'); + $table->renameColumn('lifetime', 'lifetime_seconds'); + $table->renameColumn('last_activity', 'last_activity_at'); + $table->dateTime('created_at'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('access_tokens', function (Blueprint $table) { + $table->renameColumn('lifetime_seconds', 'lifetime'); + $table->renameColumn('last_activity_at', 'last_activity'); + $table->dropColumn('created_at'); + $table->renameColumn('token', 'id'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_11_094800_change_access_tokens_make_activity_at_column_datetime.php b/framework/core/migrations/2018_01_11_094800_change_access_tokens_make_activity_at_column_datetime.php new file mode 100644 index 000000000..3e555f1ca --- /dev/null +++ b/framework/core/migrations/2018_01_11_094800_change_access_tokens_make_activity_at_column_datetime.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('access_tokens', function (Blueprint $table) { + $table->dateTime('last_activity_at')->change(); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('access_tokens', function (Blueprint $table) { + $table->integer('last_activity_at')->change(); + }); + } +]; diff --git a/framework/core/migrations/2018_01_11_094900_change_api_keys_rename_id_to_key.php b/framework/core/migrations/2018_01_11_094900_change_api_keys_rename_id_to_key.php new file mode 100644 index 000000000..7135025a7 --- /dev/null +++ b/framework/core/migrations/2018_01_11_094900_change_api_keys_rename_id_to_key.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('api_keys', function (Blueprint $table) { + $table->renameColumn('id', 'key'); + $table->dropPrimary(['id', 'key']); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('api_keys', function (Blueprint $table) { + $table->renameColumn('key', 'id'); + $table->primary('id'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php b/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php new file mode 100644 index 000000000..478c578cf --- /dev/null +++ b/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('api_keys', function (Blueprint $table) { + $table->increments('id'); + $table->string('allowed_ips')->nullable(); + $table->string('scopes')->nullable(); + $table->integer('user_id')->unsigned()->nullable(); + $table->dateTime('created_at'); + $table->dateTime('last_activity_at')->nullable(); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('api_keys', function (Blueprint $table) { + $table->dropForeign(['user_id']); + $table->dropColumn('id', 'allowed_ips', 'user_id', 'scopes', 'created_at'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_11_101800_rename_auth_tokens_to_registration_tokens.php b/framework/core/migrations/2018_01_11_101800_rename_auth_tokens_to_registration_tokens.php new file mode 100644 index 000000000..eaf176a0d --- /dev/null +++ b/framework/core/migrations/2018_01_11_101800_rename_auth_tokens_to_registration_tokens.php @@ -0,0 +1,14 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameTable('auth_tokens', 'registration_tokens'); diff --git a/framework/core/migrations/2018_01_11_102000_change_registration_tokens_rename_id_to_token.php b/framework/core/migrations/2018_01_11_102000_change_registration_tokens_rename_id_to_token.php new file mode 100644 index 000000000..6a538622b --- /dev/null +++ b/framework/core/migrations/2018_01_11_102000_change_registration_tokens_rename_id_to_token.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('registration_tokens', function (Blueprint $table) { + $table->renameColumn('id', 'token'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('registration_tokens', function (Blueprint $table) { + $table->renameColumn('token', 'id'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php new file mode 100644 index 000000000..c88fa528a --- /dev/null +++ b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('discussions', function (Blueprint $table) { + $table->renameColumn('comments_count', 'comment_count'); + $table->renameColumn('participants_count', 'participant_count'); + $table->renameColumn('number_index', 'post_number_index'); + $table->renameColumn('start_time', 'created_at'); + $table->renameColumn('start_user_id', 'user_id'); + $table->renameColumn('start_post_id', 'first_post_id'); + $table->renameColumn('last_time', 'last_posted_at'); + $table->renameColumn('last_user_id', 'last_posted_user_id'); + $table->renameColumn('hide_time', 'hidden_at'); + $table->renameColumn('hide_user_id', 'hidden_user_id'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('discussions', function (Blueprint $table) { + $table->renameColumn('comment_count', 'comments_count'); + $table->renameColumn('participant_count', 'participants_count'); + $table->renameColumn('post_number_index', 'number_index'); + $table->renameColumn('created_at', 'start_time'); + $table->renameColumn('user_id', 'start_user_id'); + $table->renameColumn('first_post_id', 'start_post_id'); + $table->renameColumn('last_posted_at', 'last_time'); + $table->renameColumn('last_posted_user_id', 'last_user_id'); + $table->renameColumn('hidden_at', 'hide_time'); + $table->renameColumn('hidden_user_id', 'hide_user_id'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php b/framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php new file mode 100644 index 000000000..c0e48bb91 --- /dev/null +++ b/framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->rename('users_discussions', 'discussions_users'); + }, + + 'down' => function (Builder $schema) { + $schema->rename('discussions_users', 'users_discussions'); + } +]; diff --git a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php new file mode 100644 index 000000000..5797a033f --- /dev/null +++ b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('discussions_users', function (Blueprint $table) { + $table->renameColumn('read_time', 'last_read_at'); + $table->renameColumn('read_number', 'last_read_post_number'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('discussions_users', function (Blueprint $table) { + $table->renameColumn('last_read_at', 'read_time'); + $table->renameColumn('last_read_post_number', 'read_number'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php new file mode 100644 index 000000000..4bb891a1f --- /dev/null +++ b/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->renameColumn('id', 'token'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->renameColumn('token', 'id'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_18_130400_rename_permissions_to_group_permissions.php b/framework/core/migrations/2018_01_18_130400_rename_permissions_to_group_permissions.php new file mode 100644 index 000000000..8d8761878 --- /dev/null +++ b/framework/core/migrations/2018_01_18_130400_rename_permissions_to_group_permissions.php @@ -0,0 +1,14 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameTable('permissions', 'groups_permissions'); diff --git a/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php b/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php new file mode 100644 index 000000000..40f4178f9 --- /dev/null +++ b/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php @@ -0,0 +1,14 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameTable('users_groups', 'group_user'); diff --git a/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php b/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php new file mode 100644 index 000000000..83fad7b64 --- /dev/null +++ b/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->create('notifications_from', function (Blueprint $table) { + $table->integer('id')->unsigned(); + $table->integer('from_user_id')->unsigned(); + + $table->foreign('id')->references('id')->on('notifications')->onDelete('cascade'); + $table->foreign('from_user_id')->references('id')->on('users')->onDelete('cascade'); + }); + + $schema->getConnection()->table('notifications')->chunkById(100, function ($notifications) use ($schema) { + foreach ($notifications as $notification) { + $insert = [ + 'id' => $notification->id, + 'from_user_id' => $notification->sender_id + ]; + + $schema->getConnection()->table('notifications_from')->updateOrInsert($insert, $insert); + } + }); + }, + + 'down' => function (Builder $schema) { + $schema->drop('notifications_from'); + } +]; diff --git a/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php b/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php new file mode 100644 index 000000000..2261b0248 --- /dev/null +++ b/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('notifications', function (Blueprint $table) { + $table->dropColumn('sender_id', 'subject_type'); + + $table->renameColumn('time', 'created_at'); + + $table->timestamp('read_at')->nullable(); + $table->timestamp('deleted_at')->nullable(); + }); + + $schema->getConnection()->table('notifications') + ->where('is_read', 1) + ->update(['read_at' => time()]); + + $schema->getConnection()->table('notifications') + ->where('is_deleted', 1) + ->update(['deleted_at' => time()]); + + $schema->table('notifications', function (Blueprint $table) { + $table->dropColumn('is_read'); + $table->dropColumn('is_deleted'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('notifications', function (Blueprint $table) { + $table->integer('sender_id')->unsigned()->nullable(); + $table->string('subject_type', 200)->nullable(); + + $table->renameColumn('created_at', 'time'); + + $table->boolean('is_read'); + $table->boolean('is_deleted'); + }); + + $schema->getConnection()->table('notifications') + ->whereNotNull('read_at') + ->update(['is_read' => 1]); + $schema->getConnection()->table('notifications') + ->whereNotNull('deleted_at') + ->update(['is_deleted' => 1]); + + $schema->table('notifications', function (Blueprint $table) { + $table->dropColumn('read_at'); + $table->dropColumn('deleted_at'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_18_134400_change_password_tokens_id_to_token.php b/framework/core/migrations/2018_01_18_134400_change_password_tokens_id_to_token.php new file mode 100644 index 000000000..e83f8692a --- /dev/null +++ b/framework/core/migrations/2018_01_18_134400_change_password_tokens_id_to_token.php @@ -0,0 +1,14 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameColumn('password_tokens', 'id', 'token'); diff --git a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php new file mode 100644 index 000000000..03b44f92c --- /dev/null +++ b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('posts', function (Blueprint $table) { + $table->renameColumn('time', 'created_at'); + $table->renameColumn('edit_time', 'edited_at'); + $table->renameColumn('hide_time', 'hidden_at'); + + $table->renameColumn('edit_user_id', 'edited_user_id'); + $table->renameColumn('hide_user_id', 'hidden_user_id'); + + $table->longText('content')->change(); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('posts', function (Blueprint $table) { + $table->renameColumn('created_at', 'time'); + $table->renameColumn('edited_at', 'edit_time'); + $table->renameColumn('hidden_at', 'hide_time'); + + $table->renameColumn('edited_user_id', 'edit_user_id'); + $table->renameColumn('edited_user_id', 'hidden_user_id'); + }); + + $prefix = $schema->getConnection()->getTablePrefix(); + $schema->getConnection()->statement('ALTER TABLE '.$prefix.'posts MODIFY content FULLTEXT'); + } +]; diff --git a/framework/core/migrations/2018_01_19_084700_change_settings_value_longblob.php b/framework/core/migrations/2018_01_19_084700_change_settings_value_longblob.php new file mode 100644 index 000000000..b6493cfc4 --- /dev/null +++ b/framework/core/migrations/2018_01_19_084700_change_settings_value_longblob.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $prefix = $schema->getConnection()->getTablePrefix(); +// $schema->getConnection()->statement('ALTER TABLE '.$prefix.'settings MODIFY "value" LONGBLOB'); + }, + + 'down' => function (Builder $schema) { + $schema->table('posts', function (Blueprint $table) { +// $table->longText('value')->nullable()->change(); + }); + } +]; diff --git a/framework/core/migrations/2018_01_30_220100_create_posts_users_table.php b/framework/core/migrations/2018_01_30_220100_create_posts_users_table.php new file mode 100644 index 000000000..ba1d3e952 --- /dev/null +++ b/framework/core/migrations/2018_01_30_220100_create_posts_users_table.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->create('posts_users', function (Blueprint $table) { + $table->integer('post_id')->unsigned(); + $table->integer('user_id')->unsigned(); + + $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->drop('posts_users'); + } +]; diff --git a/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php b/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php new file mode 100644 index 000000000..1826ea34b --- /dev/null +++ b/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->renameColumn('is_activated', 'is_email_confirmed'); + $table->renameColumn('join_time', 'joined_at'); + $table->renameColumn('last_seen_time', 'last_seen_at'); + $table->renameColumn('discussions_count', 'discussion_count'); + $table->renameColumn('comments_count', 'comment_count'); + $table->renameColumn('read_time', 'marked_all_as_read_at'); + $table->renameColumn('notifications_read_time', 'read_notifications_at'); + $table->renameColumn('avatar_path', 'avatar_url'); + $table->dropColumn('bio', 'preferences'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->renameColumn('is_email_confirmed', 'is_activated'); + $table->renameColumn('joined_at', 'join_time'); + $table->renameColumn('last_seen_at', 'last_seen_time'); + $table->renameColumn('discussion_count', 'discussions_count'); + $table->renameColumn('comment_count', 'comments_count'); + $table->renameColumn('marked_all_as_read_at', 'read_time'); + $table->renameColumn('read_notifications_at', 'notifications_read_time'); + $table->renameColumn('avatar_url', 'avatar_path'); + $table->text('bio')->nullable(); + $table->binary('preferences')->nullable(); + }); + } +]; diff --git a/framework/core/migrations/2018_01_30_223700_create_users_users_table.php b/framework/core/migrations/2018_01_30_223700_create_users_users_table.php new file mode 100644 index 000000000..ed74651c1 --- /dev/null +++ b/framework/core/migrations/2018_01_30_223700_create_users_users_table.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->create('users_users', function (Blueprint $table) { + $table->integer('user_id')->unsigned(); + $table->integer('other_user_id')->unsigned(); + + $table->foreign('user_id')->references('id')->on('posts')->onDelete('cascade'); + $table->foreign('other_user_id')->references('id')->on('users')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->drop('users_users'); + } +]; From 0a1c05efbdade3743b1962f28fe8b0a37c16efe4 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Tue, 17 Apr 2018 12:21:55 +0200 Subject: [PATCH 02/85] tables renamed, auth_tokens and permissions --- framework/core/src/Group/Permission.php | 5 +++-- framework/core/src/User/AuthToken.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Group/Permission.php b/framework/core/src/Group/Permission.php index 110c365b0..ae50923d8 100644 --- a/framework/core/src/Group/Permission.php +++ b/framework/core/src/Group/Permission.php @@ -15,14 +15,15 @@ use Flarum\Database\AbstractModel; use Illuminate\Database\Eloquent\Builder; /** - * @todo document database columns with @property + * @property int $group_id + * @property string $permission */ class Permission extends AbstractModel { /** * {@inheritdoc} */ - protected $table = 'permissions'; + protected $table = 'groups_permissions'; /** * Define the relationship with the group that this permission is for. diff --git a/framework/core/src/User/AuthToken.php b/framework/core/src/User/AuthToken.php index 2458baca5..87c91740e 100644 --- a/framework/core/src/User/AuthToken.php +++ b/framework/core/src/User/AuthToken.php @@ -23,7 +23,7 @@ class AuthToken extends AbstractModel /** * {@inheritdoc} */ - protected $table = 'auth_tokens'; + protected $table = 'registration_tokens'; /** * {@inheritdoc} From c30e19de1cc3fd39242b7f8200c2e19cc50b87d3 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Tue, 17 Apr 2018 13:25:11 +0200 Subject: [PATCH 03/85] joined_at renamed to User --- framework/core/src/User/User.php | 70 ++++++++++++++++---------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index fa30ec01a..b4ab2f220 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -34,22 +34,21 @@ use Flarum\User\Event\PasswordChanged; use Flarum\User\Event\Registered; use Flarum\User\Event\Renamed; use Illuminate\Contracts\Hashing\Hasher; -use Illuminate\Contracts\Session\Session; +use Symfony\Component\HttpFoundation\Session\SessionInterface; /** * @property int $id * @property string $username * @property string $email - * @property bool $is_activated + * @property bool $is_email_confirmed * @property string $password * @property string $locale - * @property string|null $avatar_path - * @property string $avatar_url + * @property string|null $avatar_url * @property array $preferences - * @property \Carbon\Carbon|null $join_time - * @property \Carbon\Carbon|null $last_seen_time - * @property \Carbon\Carbon|null $read_time - * @property \Carbon\Carbon|null $notifications_read_time + * @property \Carbon\Carbon|null $joined_at + * @property \Carbon\Carbon|null $last_seen_at + * @property \Carbon\Carbon|null $marked_all_as_read_at + * @property \Carbon\Carbon|null $read_notifications_at * @property int $discussions_count * @property int $comments_count */ @@ -67,10 +66,10 @@ class User extends AbstractModel * {@inheritdoc} */ protected $dates = [ - 'join_time', - 'last_seen_time', - 'read_time', - 'notifications_read_time' + 'joined_at', + 'last_seen_at', + 'marked_all_as_read_at', + 'read_notifications_at' ]; /** @@ -146,7 +145,7 @@ class User extends AbstractModel $user->notifications()->delete(); }); - static::$dispatcher->dispatch( + static::$dispatcher->fire( new ConfigureUserPreferences ); } @@ -166,7 +165,7 @@ class User extends AbstractModel $user->username = $username; $user->email = $email; $user->password = $password; - $user->join_time = time(); + $user->joined_at = time(); $user->raise(new Registered($user)); @@ -270,7 +269,7 @@ class User extends AbstractModel */ public function markAllAsRead() { - $this->read_time = time(); + $this->marked_all_as_read_at = time(); return $this; } @@ -282,7 +281,7 @@ class User extends AbstractModel */ public function markNotificationsAsRead() { - $this->notifications_read_time = time(); + $this->read_notifications_at = time(); return $this; } @@ -295,7 +294,7 @@ class User extends AbstractModel */ public function changeAvatarPath($path) { - $this->avatar_path = $path; + $this->attributes['avatar_url'] = $path; $this->raise(new AvatarChanged($this)); @@ -306,17 +305,16 @@ class User extends AbstractModel * Get the URL of the user's avatar. * * @todo Allow different storage locations to be used + * @param string|null $value * @return string */ - public function getAvatarUrlAttribute() + public function getAvatarUrlAttribute(string $value = null) { - if ($this->avatar_path) { - if (strpos($this->avatar_path, '://') !== false) { - return $this->avatar_path; - } - - return app(UrlGenerator::class)->to('forum')->path('assets/avatars/'.$this->avatar_path); + if ($value && strpos($value, '://') === false) { + return app(UrlGenerator::class)->to('forum')->path('assets/avatars/'.$value); } + + return $value; } /** @@ -365,8 +363,8 @@ class User extends AbstractModel */ public function activate() { - if ($this->is_activated !== true) { - $this->is_activated = true; + if ($this->is_email_confirmed !== true) { + $this->is_email_confirmed = true; $this->raise(new Activated($this)); } @@ -454,8 +452,8 @@ class User extends AbstractModel if (is_null($cached)) { $cached = $this->notifications() ->whereIn('type', $this->getAlertableNotificationTypes()) - ->where('is_read', 0) - ->where('is_deleted', 0) + ->whereNull('read_at') + ->whereNull('deleted_at') ->get(); } @@ -470,7 +468,7 @@ class User extends AbstractModel public function getNewNotificationsCount() { return $this->getUnreadNotifications()->filter(function ($notification) { - return $notification->time > $this->notifications_read_time ?: 0; + return $notification->time > $this->read_notifications_at ?: 0; })->count(); } @@ -569,7 +567,7 @@ class User extends AbstractModel */ public function updateLastSeen() { - $this->last_seen_time = time(); + $this->last_seen_at = time(); return $this; } @@ -611,7 +609,7 @@ class User extends AbstractModel */ public function read() { - return $this->belongsToMany('Flarum\Discussion\Discussion', 'users_discussions'); + return $this->belongsToMany('Flarum\Discussion\Discussion'); } /** @@ -621,7 +619,7 @@ class User extends AbstractModel */ public function groups() { - return $this->belongsToMany('Flarum\Group\Group', 'users_groups'); + return $this->belongsToMany('Flarum\Group\Group'); } /** @@ -648,7 +646,7 @@ class User extends AbstractModel // more than a guest. If they are activated, we can give them the // standard 'member' group, as well as any other groups they've been // assigned to. - if ($this->is_activated) { + if ($this->is_email_confirmed) { $groupIds = array_merge($groupIds, [Group::MEMBER_ID], $this->groups->pluck('id')->all()); } @@ -698,7 +696,7 @@ class User extends AbstractModel } /** - * @return Session + * @return SessionInterface */ public function getSession() { @@ -706,9 +704,9 @@ class User extends AbstractModel } /** - * @param Session $session + * @param SessionInterface $session */ - public function setSession(Session $session) + public function setSession(SessionInterface $session) { $this->session = $session; } From f04eaa1549c637040b41262ccbfefc1534273cd6 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Tue, 17 Apr 2018 14:22:38 +0200 Subject: [PATCH 04/85] went over most of the changed attributes from the other pr --- .../Controller/ListDiscussionsController.php | 2 +- .../Api/Serializer/DiscussionSerializer.php | 12 ++-- framework/core/src/Discussion/Discussion.php | 62 +++++++++---------- .../core/src/Discussion/DiscussionPolicy.php | 14 ++--- .../Discussion/DiscussionRenamedLogger.php | 2 +- .../src/Discussion/DiscussionRepository.php | 2 +- .../Discussion/Search/DiscussionSearch.php | 2 +- .../Discussion/Search/Gambit/AuthorGambit.php | 2 +- .../Search/Gambit/CreatedGambit.php | 4 +- .../Discussion/Search/Gambit/HiddenGambit.php | 4 +- .../Discussion/Search/Gambit/UnreadGambit.php | 4 +- framework/core/src/Discussion/UserState.php | 14 ++--- .../core/src/Notification/Notification.php | 10 +-- .../Notification/NotificationRepository.php | 8 +-- framework/core/src/Post/CommentPost.php | 18 +++--- framework/core/src/Post/Post.php | 18 +++--- framework/core/src/Post/PostPolicy.php | 6 +- framework/core/src/User/AuthToken.php | 28 ++++++--- .../Command/RequestPasswordResetHandler.php | 2 +- framework/core/src/User/PasswordToken.php | 13 +++- framework/core/src/User/User.php | 1 + 21 files changed, 122 insertions(+), 106 deletions(-) diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index 28a6e8bbc..f01e3ace6 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -47,7 +47,7 @@ class ListDiscussionsController extends AbstractListController /** * {@inheritdoc} */ - public $sortFields = ['lastTime', 'commentsCount', 'startTime']; + public $sortFields = ['lastPostedAt', 'commentCount', 'createdAt']; /** * @var DiscussionSearcher diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index 88e5fb8fe..393faaf5d 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -37,10 +37,10 @@ class DiscussionSerializer extends BasicDiscussionSerializer $gate = $this->gate->forUser($this->actor); $attributes = parent::getDefaultAttributes($discussion) + [ - 'commentsCount' => (int) $discussion->comments_count, - 'participantsCount' => (int) $discussion->participants_count, - 'startTime' => $this->formatDate($discussion->start_time), - 'lastTime' => $this->formatDate($discussion->last_time), + 'commentsCount' => (int) $discussion->comment_count, + 'participantsCount' => (int) $discussion->participant_count, + 'startTime' => $this->formatDate($discussion->created_at), + 'lastTime' => $this->formatDate($discussion->last_posted_at), 'lastPostNumber' => (int) $discussion->last_post_number, 'canReply' => $gate->allows('reply', $discussion), 'canRename' => $gate->allows('rename', $discussion), @@ -48,9 +48,9 @@ class DiscussionSerializer extends BasicDiscussionSerializer 'canHide' => $gate->allows('hide', $discussion) ]; - if ($discussion->hide_time) { + if ($discussion->hidden_at) { $attributes['isHidden'] = true; - $attributes['hideTime'] = $this->formatDate($discussion->hide_time); + $attributes['hideTime'] = $this->formatDate($discussion->hidden_at); } Discussion::setStateUser($this->actor); diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 116f1484c..c56d54ef0 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -30,18 +30,18 @@ use Flarum\Util\Str; * @property int $id * @property string $title * @property string $slug - * @property int $comments_count - * @property int $participants_count - * @property int $number_index - * @property \Carbon\Carbon $start_time - * @property int|null $start_user_id - * @property int|null $start_post_id - * @property \Carbon\Carbon|null $last_time - * @property int|null $last_user_id + * @property int $comment_count + * @property int $participant_count + * @property int $post_number_index + * @property \Carbon\Carbon $created_at + * @property int|null $user_id + * @property int|null $first_post_id + * @property \Carbon\Carbon|null $last_posted_at + * @property int|null $last_posted_user_id * @property int|null $last_post_id * @property int|null $last_post_number - * @property \Carbon\Carbon|null $hide_time - * @property int|null $hide_user_id + * @property \Carbon\Carbon|null $hidden_at + * @property int|null $hidden_user_id * @property UserState|null $state * @property \Illuminate\Database\Eloquent\Collection $posts * @property \Illuminate\Database\Eloquent\Collection $comments @@ -73,7 +73,7 @@ class Discussion extends AbstractModel /** * {@inheritdoc} */ - protected $dates = ['start_time', 'last_time', 'hide_time']; + protected $dates = ['created_at', 'last_posted_at', 'hidden_at']; /** * Casts properties to a specific type. @@ -138,8 +138,8 @@ class Discussion extends AbstractModel $discussion = new static; $discussion->title = $title; - $discussion->start_time = time(); - $discussion->start_user_id = $user->id; + $discussion->created_at = time(); + $discussion->user_id = $user->id; $discussion->setRelation('startUser', $user); @@ -174,9 +174,9 @@ class Discussion extends AbstractModel */ public function hide(User $actor = null) { - if (! $this->hide_time) { - $this->hide_time = time(); - $this->hide_user_id = $actor ? $actor->id : null; + if (! $this->hidden_at) { + $this->hidden_at = time(); + $this->hidden_user_id = $actor ? $actor->id : null; $this->raise(new Hidden($this)); } @@ -191,9 +191,9 @@ class Discussion extends AbstractModel */ public function restore() { - if ($this->hide_time !== null) { - $this->hide_time = null; - $this->hide_user_id = null; + if ($this->hidden_at !== null) { + $this->hidden_at = null; + $this->hidden_user_id = null; $this->raise(new Restored($this)); } @@ -209,9 +209,9 @@ class Discussion extends AbstractModel */ public function setStartPost(Post $post) { - $this->start_time = $post->time; - $this->start_user_id = $post->user_id; - $this->start_post_id = $post->id; + $this->created_at = $post->time; + $this->user_id = $post->user_id; + $this->first_post_id = $post->id; return $this; } @@ -224,8 +224,8 @@ class Discussion extends AbstractModel */ public function setLastPost(Post $post) { - $this->last_time = $post->time; - $this->last_user_id = $post->user_id; + $this->last_posted_at = $post->time; + $this->last_posted_user_id = $post->user_id; $this->last_post_id = $post->id; $this->last_post_number = $post->number; @@ -240,7 +240,7 @@ class Discussion extends AbstractModel public function refreshLastPost() { /** @var Post $lastPost */ - if ($lastPost = $this->comments()->latest('time')->first()) { + if ($lastPost = $this->comments()->latest('created_at')->first()) { $this->setLastPost($lastPost); } @@ -254,7 +254,7 @@ class Discussion extends AbstractModel */ public function refreshCommentsCount() { - $this->comments_count = $this->comments()->count(); + $this->comment_count = $this->comments()->count(); return $this; } @@ -266,7 +266,7 @@ class Discussion extends AbstractModel */ public function refreshParticipantsCount() { - $this->participants_count = $this->participants()->count('users.id'); + $this->participant_count = $this->participants()->count('users.id'); return $this; } @@ -286,7 +286,7 @@ class Discussion extends AbstractModel */ public function mergePost(MergeableInterface $post) { - $lastPost = $this->posts()->latest('time')->first(); + $lastPost = $this->posts()->latest('created_at')->first(); $post = $post->saveAfter($lastPost); @@ -322,7 +322,7 @@ class Discussion extends AbstractModel { return $this->posts() ->where('is_private', false) - ->whereNull('hide_time') + ->whereNull('hidden_at') ->where('type', 'comment'); } @@ -349,7 +349,7 @@ class Discussion extends AbstractModel */ public function startPost() { - return $this->belongsTo(Post::class, 'start_post_id'); + return $this->belongsTo(Post::class, 'first_post_id'); } /** @@ -359,7 +359,7 @@ class Discussion extends AbstractModel */ public function startUser() { - return $this->belongsTo(User::class, 'start_user_id'); + return $this->belongsTo(User::class, 'user_id'); } /** diff --git a/framework/core/src/Discussion/DiscussionPolicy.php b/framework/core/src/Discussion/DiscussionPolicy.php index 269648638..33c521838 100644 --- a/framework/core/src/Discussion/DiscussionPolicy.php +++ b/framework/core/src/Discussion/DiscussionPolicy.php @@ -93,7 +93,7 @@ class DiscussionPolicy extends AbstractPolicy if (! $actor->hasPermission('discussion.hide')) { $query->where(function ($query) use ($actor) { $query->whereNull('discussions.hide_time') - ->orWhere('start_user_id', $actor->id) + ->orWhere('user_id', $actor->id) ->orWhere(function ($query) use ($actor) { $this->events->fire( new ScopeModelVisibility($query, $actor, 'hide') @@ -106,8 +106,8 @@ class DiscussionPolicy extends AbstractPolicy // current user, or the user is allowed to edit the discussion's posts. if (! $actor->hasPermission('discussion.editPosts')) { $query->where(function ($query) use ($actor) { - $query->where('comments_count', '>', 0) - ->orWhere('start_user_id', $actor->id) + $query->where('comment_count', '>', 0) + ->orWhere('user_id', $actor->id) ->orWhere(function ($query) use ($actor) { $this->events->dispatch( new ScopeModelVisibility($query, $actor, 'editPosts') @@ -124,12 +124,12 @@ class DiscussionPolicy extends AbstractPolicy */ public function rename(User $actor, Discussion $discussion) { - if ($discussion->start_user_id == $actor->id) { + if ($discussion->user_id == $actor->id) { $allowRenaming = $this->settings->get('allow_renaming'); if ($allowRenaming === '-1' - || ($allowRenaming === 'reply' && $discussion->participants_count <= 1) - || ($discussion->start_time->diffInMinutes(new Carbon) < $allowRenaming)) { + || ($allowRenaming === 'reply' && $discussion->participant_count <= 1) + || ($discussion->created_at->diffInMinutes(new Carbon) < $allowRenaming)) { return true; } } @@ -142,7 +142,7 @@ class DiscussionPolicy extends AbstractPolicy */ public function hide(User $actor, Discussion $discussion) { - if ($discussion->start_user_id == $actor->id && $discussion->participants_count <= 1) { + if ($discussion->user_id == $actor->id && $discussion->participant_count <= 1) { return true; } } diff --git a/framework/core/src/Discussion/DiscussionRenamedLogger.php b/framework/core/src/Discussion/DiscussionRenamedLogger.php index 961bde5fb..ae04e5830 100644 --- a/framework/core/src/Discussion/DiscussionRenamedLogger.php +++ b/framework/core/src/Discussion/DiscussionRenamedLogger.php @@ -54,7 +54,7 @@ class DiscussionRenamedLogger $post = $event->discussion->mergePost($post); - if ($event->discussion->start_user_id !== $event->actor->id) { + if ($event->discussion->user_id !== $event->actor->id) { $blueprint = new DiscussionRenamedBlueprint($post); if ($post->exists) { diff --git a/framework/core/src/Discussion/DiscussionRepository.php b/framework/core/src/Discussion/DiscussionRepository.php index 21abd39a0..68862b5a1 100644 --- a/framework/core/src/Discussion/DiscussionRepository.php +++ b/framework/core/src/Discussion/DiscussionRepository.php @@ -49,7 +49,7 @@ class DiscussionRepository */ public function getReadIds(User $user) { - return Discussion::leftJoin('users_discussions', 'users_discussions.discussion_id', '=', 'discussions.id') + return Discussion::leftJoin('discussions_users', 'discussions_users.discussion_id', '=', 'discussions.id') ->where('user_id', $user->id) ->whereRaw('read_number >= last_post_number') ->pluck('id') diff --git a/framework/core/src/Discussion/Search/DiscussionSearch.php b/framework/core/src/Discussion/Search/DiscussionSearch.php index 8cb886e29..3b1fba7e1 100644 --- a/framework/core/src/Discussion/Search/DiscussionSearch.php +++ b/framework/core/src/Discussion/Search/DiscussionSearch.php @@ -23,7 +23,7 @@ class DiscussionSearch extends AbstractSearch /** * {@inheritdoc} */ - protected $defaultSort = ['lastTime' => 'desc']; + protected $defaultSort = ['lastPostedAt' => 'desc']; /** * @var array diff --git a/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php b/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php index d3f4544ab..0b321448d 100644 --- a/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php @@ -54,6 +54,6 @@ class AuthorGambit extends AbstractRegexGambit $ids[] = $this->users->getIdForUsername($username); } - $search->getQuery()->whereIn('start_user_id', $ids, 'and', $negate); + $search->getQuery()->whereIn('user_id', $ids, 'and', $negate); } } diff --git a/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php b/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php index 6241c0e16..0fb908156 100644 --- a/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php @@ -37,9 +37,9 @@ class CreatedGambit extends AbstractRegexGambit // provided with a YYYY-MM-DD..YYYY-MM-DD range, then find discussions // that were started during that period. if (empty($matches[3])) { - $search->getQuery()->whereDate('start_time', $negate ? '!=' : '=', $matches[1]); + $search->getQuery()->whereDate('created_at', $negate ? '!=' : '=', $matches[1]); } else { - $search->getQuery()->whereBetween('start_time', [$matches[1], $matches[3]], 'and', $negate); + $search->getQuery()->whereBetween('created_at', [$matches[1], $matches[3]], 'and', $negate); } } } diff --git a/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php b/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php index 907991546..95a2bee55 100644 --- a/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php @@ -34,9 +34,9 @@ class HiddenGambit extends AbstractRegexGambit $search->getQuery()->where(function ($query) use ($negate) { if ($negate) { - $query->whereNull('hide_time')->where('comments_count', '>', 0); + $query->whereNull('hidden_at')->where('comment_count', '>', 0); } else { - $query->whereNotNull('hide_time')->orWhere('comments_count', 0); + $query->whereNotNull('hidden_at')->orWhere('comment_count', 0); } }); } diff --git a/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php b/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php index bd9a60629..ef8b202dd 100644 --- a/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php @@ -53,9 +53,9 @@ class UnreadGambit extends AbstractRegexGambit $search->getQuery()->where(function ($query) use ($readIds, $negate, $actor) { if (! $negate) { - $query->whereNotIn('id', $readIds)->where('last_time', '>', $actor->read_time ?: 0); + $query->whereNotIn('id', $readIds)->where('last_posted_at', '>', $actor->marked_all_as_read_at ?: 0); } else { - $query->whereIn('id', $readIds)->orWhere('last_time', '<=', $actor->read_time ?: 0); + $query->whereIn('id', $readIds)->orWhere('last_posted_at', '<=', $actor->marked_all_as_read_at ?: 0); } }); } diff --git a/framework/core/src/Discussion/UserState.php b/framework/core/src/Discussion/UserState.php index a8df0651c..6de1c998e 100644 --- a/framework/core/src/Discussion/UserState.php +++ b/framework/core/src/Discussion/UserState.php @@ -26,8 +26,8 @@ use Illuminate\Database\Eloquent\Builder; * * @property int $user_id * @property int $discussion_id - * @property \Carbon\Carbon|null $read_time - * @property int|null $read_number + * @property \Carbon\Carbon|null $last_read_at + * @property int|null $last_read_post_number * @property Discussion $discussion * @property \Flarum\User\User $user */ @@ -38,12 +38,12 @@ class UserState extends AbstractModel /** * {@inheritdoc} */ - protected $table = 'users_discussions'; + protected $table = 'discussions_users'; /** * {@inheritdoc} */ - protected $dates = ['read_time']; + protected $dates = ['last_read_at']; /** * Mark the discussion as being read up to a certain point. Raises the @@ -54,9 +54,9 @@ class UserState extends AbstractModel */ public function read($number) { - if ($number > $this->read_number) { - $this->read_number = $number; - $this->read_time = time(); + if ($number > $this->last_read_at) { + $this->last_read_at = $number; + $this->last_read_at = time(); $this->raise(new UserRead($this)); } diff --git a/framework/core/src/Notification/Notification.php b/framework/core/src/Notification/Notification.php index ad289ca08..cb906dea2 100644 --- a/framework/core/src/Notification/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -34,9 +34,9 @@ use Flarum\User\User; * @property string $type * @property int|null $subject_id * @property mixed|null $data - * @property \Carbon\Carbon $time - * @property bool $is_read - * @property bool $is_deleted + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $read_at + * @property \Carbon\Carbon $deleted_at * @property \Flarum\User\User|null $user * @property \Flarum\User\User|null $sender * @property \Flarum\Database\AbstractModel|null $subject @@ -51,7 +51,7 @@ class Notification extends AbstractModel /** * {@inheritdoc} */ - protected $dates = ['time']; + protected $dates = ['created_at', 'read_at', 'deleted_at']; /** * A map of notification types and the model classes to use for their @@ -70,7 +70,7 @@ class Notification extends AbstractModel */ public function read() { - $this->is_read = true; + $this->read_at = time(); } /** diff --git a/framework/core/src/Notification/NotificationRepository.php b/framework/core/src/Notification/NotificationRepository.php index ae70ea600..4b0d2b54a 100644 --- a/framework/core/src/Notification/NotificationRepository.php +++ b/framework/core/src/Notification/NotificationRepository.php @@ -27,11 +27,11 @@ class NotificationRepository { $primaries = Notification::select( app('flarum.db')->raw('MAX(id) AS id'), - app('flarum.db')->raw('SUM(is_read = 0) AS unread_count') + app('flarum.db')->raw('SUM(read_at IS NULL) AS unread_count') ) ->where('user_id', $user->id) ->whereIn('type', $user->getAlertableNotificationTypes()) - ->where('is_deleted', false) + ->whereNull('deleted_at') ->groupBy('type', 'subject_id') ->orderByRaw('MAX(time) DESC') ->skip($offset) @@ -40,7 +40,7 @@ class NotificationRepository return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count')) ->mergeBindings($primaries->getQuery()) ->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id')) - ->latest('time') + ->latest('created_at') ->get(); } @@ -53,6 +53,6 @@ class NotificationRepository */ public function markAllAsRead(User $user) { - Notification::where('user_id', $user->id)->update(['is_read' => true]); + Notification::where('user_id', $user->id)->update(['read_at' => time()]); } } diff --git a/framework/core/src/Post/CommentPost.php b/framework/core/src/Post/CommentPost.php index 37ebd0e04..ae171ad23 100644 --- a/framework/core/src/Post/CommentPost.php +++ b/framework/core/src/Post/CommentPost.php @@ -51,7 +51,7 @@ class CommentPost extends Post { $post = new static; - $post->time = time(); + $post->created_at = time(); $post->discussion_id = $discussionId; $post->user_id = $userId; $post->type = static::$type; @@ -77,8 +77,8 @@ class CommentPost extends Post if ($this->content !== $content) { $this->content = $content; - $this->edit_time = time(); - $this->edit_user_id = $actor->id; + $this->edited_at = time(); + $this->edited_user_id = $actor->id; $this->raise(new Revised($this)); } @@ -94,9 +94,9 @@ class CommentPost extends Post */ public function hide(User $actor = null) { - if (! $this->hide_time) { - $this->hide_time = time(); - $this->hide_user_id = $actor ? $actor->id : null; + if (! $this->hidden_at) { + $this->hidden_at = time(); + $this->hidden_user_id = $actor ? $actor->id : null; $this->raise(new Hidden($this)); } @@ -111,9 +111,9 @@ class CommentPost extends Post */ public function restore() { - if ($this->hide_time !== null) { - $this->hide_time = null; - $this->hide_user_id = null; + if ($this->hidden_at !== null) { + $this->hidden_at = null; + $this->hidden_user_id = null; $this->raise(new Restored($this)); } diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php index 2d46283ed..e4df2b0ad 100644 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -24,14 +24,14 @@ use Illuminate\Database\Eloquent\Builder; * @property int $id * @property int $discussion_id * @property int $number - * @property \Carbon\Carbon $time + * @property \Carbon\Carbon $created_at * @property int|null $user_id * @property string|null $type * @property string|null $content - * @property \Carbon\Carbon|null $edit_time - * @property int|null $edit_user_id - * @property \Carbon\Carbon|null $hide_time - * @property int|null $hide_user_id + * @property \Carbon\Carbon|null $edited_at + * @property int|null $edited_user_id + * @property \Carbon\Carbon|null $hidden_at + * @property int|null $hidden_user_id * @property \Flarum\Discussion\Discussion|null $discussion * @property User|null $user * @property User|null $editUser @@ -51,7 +51,7 @@ class Post extends AbstractModel /** * {@inheritdoc} */ - protected $dates = ['time', 'edit_time', 'hide_time']; + protected $dates = ['created_at', 'edited_at', 'hidden_at']; /** * Casts properties to a specific type. @@ -93,7 +93,7 @@ class Post extends AbstractModel // discussion. static::creating(function (Post $post) { $post->type = $post::$type; - $post->number = ++$post->discussion->number_index; + $post->number = ++$post->discussion->post_number_index; $post->discussion->save(); }); @@ -170,7 +170,7 @@ class Post extends AbstractModel */ public function editUser() { - return $this->belongsTo('Flarum\User\User', 'edit_user_id'); + return $this->belongsTo('Flarum\User\User', 'edited_user_id'); } /** @@ -180,7 +180,7 @@ class Post extends AbstractModel */ public function hideUser() { - return $this->belongsTo('Flarum\User\User', 'hide_user_id'); + return $this->belongsTo('Flarum\User\User', 'hidden_user_id'); } /** diff --git a/framework/core/src/Post/PostPolicy.php b/framework/core/src/Post/PostPolicy.php index 3b857a889..0370e775c 100644 --- a/framework/core/src/Post/PostPolicy.php +++ b/framework/core/src/Post/PostPolicy.php @@ -81,7 +81,7 @@ class PostPolicy extends AbstractPolicy // discussion. if (! $actor->hasPermission('discussion.editPosts')) { $query->where(function ($query) use ($actor) { - $query->whereNull('posts.hide_time') + $query->whereNull('posts.hidden_at') ->orWhere('user_id', $actor->id) ->orWhereExists(function ($query) use ($actor) { $query->selectRaw('1') @@ -107,12 +107,12 @@ class PostPolicy extends AbstractPolicy // A post is allowed to be edited if the user has permission to moderate // the discussion which it's in, or if they are the author and the post // hasn't been deleted by someone else. - if ($post->user_id == $actor->id && (! $post->hide_time || $post->hide_user_id == $actor->id)) { + if ($post->user_id == $actor->id && (! $post->hidden_at || $post->hidden_user_id == $actor->id)) { $allowEditing = $this->settings->get('allow_post_editing'); if ($allowEditing === '-1' || ($allowEditing === 'reply' && $post->number >= $post->discussion->last_post_number) - || ($post->time->diffInMinutes(new Carbon) < $allowEditing)) { + || ($post->created_at->diffInMinutes(new Carbon) < $allowEditing)) { return true; } } diff --git a/framework/core/src/User/AuthToken.php b/framework/core/src/User/AuthToken.php index 87c91740e..516dfa3c0 100644 --- a/framework/core/src/User/AuthToken.php +++ b/framework/core/src/User/AuthToken.php @@ -11,12 +11,14 @@ namespace Flarum\User; -use DateTime; +use Carbon\Carbon; use Flarum\Database\AbstractModel; use Flarum\User\Exception\InvalidConfirmationTokenException; /** - * @todo document database columns with @property + * @property string $token + * @property \Carbon\Carbon $created_at + * @property string $payload */ class AuthToken extends AbstractModel { @@ -37,10 +39,15 @@ class AuthToken extends AbstractModel */ public $incrementing = false; + /** + * {@inheritdoc} + */ + protected $primaryKey = 'token'; + /** * Generate an email token for the specified user. * - * @param string $email + * @param string $payload * * @return static */ @@ -48,7 +55,7 @@ class AuthToken extends AbstractModel { $token = new static; - $token->id = str_random(40); + $token->token = str_random(40); $token->payload = $payload; $token->created_at = time(); @@ -80,17 +87,18 @@ class AuthToken extends AbstractModel * Find the token with the given ID, and assert that it has not expired. * * @param \Illuminate\Database\Eloquent\Builder $query - * @param string $id + * @param string $token * - * @throws \Flarum\User\Exception\InvalidConfirmationTokenException + * @throws InvalidConfirmationTokenException * - * @return static + * @return AuthToken */ - public function scopeValidOrFail($query, $id) + public function scopeValidOrFail($query, string $token) { - $token = $query->find($id); + /** @var AuthToken $token */ + $token = $query->find($token); - if (! $token || $token->created_at < new DateTime('-1 day')) { + if (! $token || $token->created_at->lessThan(Carbon::now()->subDay())) { throw new InvalidConfirmationTokenException; } diff --git a/framework/core/src/User/Command/RequestPasswordResetHandler.php b/framework/core/src/User/Command/RequestPasswordResetHandler.php index 357c7963e..6b35d0e4a 100644 --- a/framework/core/src/User/Command/RequestPasswordResetHandler.php +++ b/framework/core/src/User/Command/RequestPasswordResetHandler.php @@ -107,7 +107,7 @@ class RequestPasswordResetHandler $data = [ '{username}' => $user->display_name, - '{url}' => $this->url->to('forum')->route('resetPassword', ['token' => $token->id]), + '{url}' => $this->url->to('forum')->route('resetPassword', ['token' => $token->token]), '{forum}' => $this->settings->get('forum_title'), ]; diff --git a/framework/core/src/User/PasswordToken.php b/framework/core/src/User/PasswordToken.php index 5c8070ead..0597012ce 100644 --- a/framework/core/src/User/PasswordToken.php +++ b/framework/core/src/User/PasswordToken.php @@ -14,7 +14,9 @@ namespace Flarum\User; use Flarum\Database\AbstractModel; /** - * @todo document database columns with @property + * @property string $token + * @property \Carbon\Carbon $created_at + * @property int $user_id */ class PasswordToken extends AbstractModel { @@ -35,17 +37,22 @@ class PasswordToken extends AbstractModel */ public $incrementing = false; + /** + * {@inheritdoc} + */ + protected $primaryKey = 'token'; + /** * Generate a password token for the specified user. * * @param int $userId * @return static */ - public static function generate($userId) + public static function generate(int $userId) { $token = new static; - $token->id = str_random(40); + $token->token = str_random(40); $token->user_id = $userId; $token->created_at = time(); diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index b4ab2f220..33bb30928 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -39,6 +39,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface; /** * @property int $id * @property string $username + * @property string $display_name * @property string $email * @property bool $is_email_confirmed * @property string $password From 8e85d89e72b4f07e4a74ea8fd34698a0b317e560 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Tue, 17 Apr 2018 14:27:52 +0200 Subject: [PATCH 05/85] is email confirmed boolean fixed --- framework/core/src/Install/Console/InstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index f3137454e..fe1f733b6 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -349,7 +349,7 @@ class InstallCommand extends AbstractCommand $admin['password'] ); - $user->is_activated = 1; + $user->is_email_confirmed = 1; $user->save(); $user->groups()->sync([Group::ADMINISTRATOR_ID]); From 80cc03e4f140554a5765ea43d48f0ab0f3d48e63 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Mon, 14 May 2018 11:34:24 +0200 Subject: [PATCH 06/85] fixed several column changes found by tests --- framework/core/src/Discussion/Discussion.php | 2 +- framework/core/src/Post/Floodgate.php | 2 +- framework/core/src/User/EmailToken.php | 7 +++++-- framework/core/src/User/User.php | 4 ++-- framework/core/src/User/UserMetadataUpdater.php | 4 ++-- .../core/tests/Api/Controller/CreateUserControllerTest.php | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index c56d54ef0..021c4e72d 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -399,7 +399,7 @@ class Discussion extends AbstractModel */ public function readers() { - return $this->belongsToMany(User::class, 'users_discussions'); + return $this->belongsToMany(User::class, 'discussions_users'); } /** diff --git a/framework/core/src/Post/Floodgate.php b/framework/core/src/Post/Floodgate.php index d3068053f..f7150d571 100644 --- a/framework/core/src/Post/Floodgate.php +++ b/framework/core/src/Post/Floodgate.php @@ -50,6 +50,6 @@ class Floodgate new CheckingForFlooding($actor) ); - return $isFlooding ?? Post::where('user_id', $actor->id)->where('time', '>=', new DateTime('-10 seconds'))->exists(); + return $isFlooding ?? Post::where('user_id', $actor->id)->where('created_at', '>=', new DateTime('-10 seconds'))->exists(); } } diff --git a/framework/core/src/User/EmailToken.php b/framework/core/src/User/EmailToken.php index 5de96e2e6..0d25df3e7 100644 --- a/framework/core/src/User/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -16,7 +16,10 @@ use Flarum\Database\AbstractModel; use Flarum\User\Exception\InvalidConfirmationTokenException; /** - * @todo document database columns with @property + * @property string $token + * @property int $user_id + * @property \Carbon\Carbon $created_at + * @property string $email */ class EmailToken extends AbstractModel { @@ -49,7 +52,7 @@ class EmailToken extends AbstractModel { $token = new static; - $token->id = str_random(40); + $token->token = str_random(40); $token->user_id = $userId; $token->email = $email; $token->created_at = time(); diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 33bb30928..53057990e 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -50,8 +50,8 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface; * @property \Carbon\Carbon|null $last_seen_at * @property \Carbon\Carbon|null $marked_all_as_read_at * @property \Carbon\Carbon|null $read_notifications_at - * @property int $discussions_count - * @property int $comments_count + * @property int $discussion_count + * @property int $comment_count */ class User extends AbstractModel { diff --git a/framework/core/src/User/UserMetadataUpdater.php b/framework/core/src/User/UserMetadataUpdater.php index a690813dd..737bf2eda 100644 --- a/framework/core/src/User/UserMetadataUpdater.php +++ b/framework/core/src/User/UserMetadataUpdater.php @@ -93,7 +93,7 @@ class UserMetadataUpdater $user = $post->user; if ($user && $user->exists) { - $user->comments_count += $amount; + $user->comment_count += $amount; $user->save(); } } @@ -107,7 +107,7 @@ class UserMetadataUpdater $user = $discussion->startUser; if ($user && $user->exists) { - $user->discussions_count += $amount; + $user->discussion_count += $amount; $user->save(); } } diff --git a/framework/core/tests/Api/Controller/CreateUserControllerTest.php b/framework/core/tests/Api/Controller/CreateUserControllerTest.php index 285b2a53a..f7e4f0bd8 100644 --- a/framework/core/tests/Api/Controller/CreateUserControllerTest.php +++ b/framework/core/tests/Api/Controller/CreateUserControllerTest.php @@ -74,7 +74,7 @@ class CreateUserControllerTest extends ApiControllerTestCase /** @var User $user */ $user = User::where('username', 'test')->firstOrFail(); - $this->assertEquals(1, $user->is_activated); + $this->assertEquals(1, $user->is_email_confirmed); } /** From 32c7f1ee5d195cbfc7ce4677d3a807db57bbf76b Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Mon, 14 May 2018 11:52:01 +0200 Subject: [PATCH 07/85] fixed the created_at issue from the policy caused by the setStartPost setting created_at to null --- .../src/Discussion/Command/StartDiscussion.php | 14 +++++++++++--- framework/core/src/Discussion/Discussion.php | 7 ++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/framework/core/src/Discussion/Command/StartDiscussion.php b/framework/core/src/Discussion/Command/StartDiscussion.php index 3b564c0f1..adb99a34e 100644 --- a/framework/core/src/Discussion/Command/StartDiscussion.php +++ b/framework/core/src/Discussion/Command/StartDiscussion.php @@ -30,10 +30,18 @@ class StartDiscussion public $data; /** - * @param User $actor The user authoring the discussion. - * @param array $data The discussion attributes. + * The current ip address of the actor. + * + * @var string */ - public function __construct(User $actor, array $data, $ipAddress) + public $ipAddress; + + /** + * @param User $actor The user authoring the discussion. + * @param array $data The discussion attributes. + * @param string $ipAddress The current ip address of the actor. + */ + public function __construct(User $actor, array $data, string $ipAddress) { $this->actor = $actor; $this->data = $data; diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 021c4e72d..de44636a1 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -11,6 +11,7 @@ namespace Flarum\Discussion; +use Carbon\Carbon; use Flarum\Database\AbstractModel; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Discussion\Event\Deleted; @@ -138,7 +139,7 @@ class Discussion extends AbstractModel $discussion = new static; $discussion->title = $title; - $discussion->created_at = time(); + $discussion->created_at = Carbon::now(); $discussion->user_id = $user->id; $discussion->setRelation('startUser', $user); @@ -209,7 +210,7 @@ class Discussion extends AbstractModel */ public function setStartPost(Post $post) { - $this->created_at = $post->time; + $this->created_at = $post->created_at; $this->user_id = $post->user_id; $this->first_post_id = $post->id; @@ -224,7 +225,7 @@ class Discussion extends AbstractModel */ public function setLastPost(Post $post) { - $this->last_posted_at = $post->time; + $this->last_posted_at = $post->created_at; $this->last_posted_user_id = $post->user_id; $this->last_post_id = $post->id; $this->last_post_number = $post->number; From f1e5c11e1f096c207a6c6d029c73020f0d35bc07 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Mon, 14 May 2018 13:49:52 +0200 Subject: [PATCH 08/85] fixed more attributes to match beta 8 --- .../src/Api/Controller/CreatePostController.php | 2 +- .../core/src/Api/Serializer/BasicPostSerializer.php | 2 +- .../src/Api/Serializer/CurrentUserSerializer.php | 7 ++++--- .../src/Api/Serializer/DiscussionSerializer.php | 4 ++-- .../src/Api/Serializer/NotificationSerializer.php | 7 +++++-- .../core/src/Api/Serializer/PostSerializer.php | 8 ++++---- .../core/src/Api/Serializer/UserSerializer.php | 13 +++++++------ framework/core/src/Discussion/Discussion.php | 2 +- framework/core/src/Discussion/DiscussionPolicy.php | 2 +- framework/core/src/Discussion/UserState.php | 3 ++- framework/core/src/Http/AccessToken.php | 5 +++-- framework/core/src/Http/CookieFactory.php | 3 ++- .../core/src/Http/Middleware/CollectGarbage.php | 7 +++++-- framework/core/src/Notification/Notification.php | 3 ++- .../src/Notification/NotificationRepository.php | 3 ++- .../core/src/Post/Command/PostReplyHandler.php | 6 +++--- framework/core/src/Post/CommentPost.php | 7 ++++--- framework/core/src/Post/DiscussionRenamedPost.php | 4 +++- framework/core/src/User/AuthToken.php | 2 +- framework/core/src/User/EmailToken.php | 6 ++++-- framework/core/src/User/PasswordToken.php | 3 ++- framework/core/src/User/User.php | 11 ++++++----- 22 files changed, 65 insertions(+), 45 deletions(-) diff --git a/framework/core/src/Api/Controller/CreatePostController.php b/framework/core/src/Api/Controller/CreatePostController.php index b4c881137..4cdae617e 100644 --- a/framework/core/src/Api/Controller/CreatePostController.php +++ b/framework/core/src/Api/Controller/CreatePostController.php @@ -84,7 +84,7 @@ class CreatePostController extends AbstractCreateController } $discussion = $post->discussion; - $discussion->posts = $discussion->posts()->whereVisibleTo($actor)->orderBy('time')->pluck('id'); + $discussion->posts = $discussion->posts()->whereVisibleTo($actor)->orderBy('created_at')->pluck('id'); return $post; } diff --git a/framework/core/src/Api/Serializer/BasicPostSerializer.php b/framework/core/src/Api/Serializer/BasicPostSerializer.php index 103bd8a06..fcd689136 100644 --- a/framework/core/src/Api/Serializer/BasicPostSerializer.php +++ b/framework/core/src/Api/Serializer/BasicPostSerializer.php @@ -39,7 +39,7 @@ class BasicPostSerializer extends AbstractSerializer $attributes = [ 'id' => (int) $post->id, 'number' => (int) $post->number, - 'time' => $this->formatDate($post->time), + 'time' => $this->formatDate($post->created_at), 'contentType' => $post->type ]; diff --git a/framework/core/src/Api/Serializer/CurrentUserSerializer.php b/framework/core/src/Api/Serializer/CurrentUserSerializer.php index 87dd1490c..d4d6bdcbf 100644 --- a/framework/core/src/Api/Serializer/CurrentUserSerializer.php +++ b/framework/core/src/Api/Serializer/CurrentUserSerializer.php @@ -14,16 +14,17 @@ namespace Flarum\Api\Serializer; class CurrentUserSerializer extends UserSerializer { /** - * {@inheritdoc} + * @param \Flarum\User\User $user + * @return array */ protected function getDefaultAttributes($user) { $attributes = parent::getDefaultAttributes($user); $attributes += [ - 'isActivated' => (bool) $user->is_activated, + 'isActivated' => (bool) $user->is_email_confirmed, 'email' => $user->email, - 'readTime' => $this->formatDate($user->read_time), + 'readTime' => $this->formatDate($user->read_notifications_at), 'unreadNotificationsCount' => (int) $user->getUnreadNotificationsCount(), 'newNotificationsCount' => (int) $user->getNewNotificationsCount(), 'preferences' => (array) $user->preferences diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index 393faaf5d..e99d5522b 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -57,8 +57,8 @@ class DiscussionSerializer extends BasicDiscussionSerializer if ($state = $discussion->state) { $attributes += [ - 'readTime' => $this->formatDate($state->read_time), - 'readNumber' => (int) $state->read_number + 'readTime' => $this->formatDate($state->last_read_at), + 'readNumber' => (int) $state->last_read_post_number ]; } diff --git a/framework/core/src/Api/Serializer/NotificationSerializer.php b/framework/core/src/Api/Serializer/NotificationSerializer.php index 55b809079..03a8d898a 100644 --- a/framework/core/src/Api/Serializer/NotificationSerializer.php +++ b/framework/core/src/Api/Serializer/NotificationSerializer.php @@ -47,12 +47,13 @@ class NotificationSerializer extends AbstractSerializer 'id' => (int) $notification->id, 'contentType' => $notification->type, 'content' => $notification->data, - 'time' => $this->formatDate($notification->time), - 'isRead' => (bool) $notification->is_read + 'time' => $this->formatDate($notification->created_at), + 'isRead' => (bool) $notification->read_at ]; } /** + * @param Notification $notification * @return \Tobscure\JsonApi\Relationship */ protected function user($notification) @@ -61,6 +62,7 @@ class NotificationSerializer extends AbstractSerializer } /** + * @param Notification $notification * @return \Tobscure\JsonApi\Relationship */ protected function sender($notification) @@ -69,6 +71,7 @@ class NotificationSerializer extends AbstractSerializer } /** + * @param Notification $notification * @return \Tobscure\JsonApi\Relationship */ protected function subject($notification) diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index ee807374b..871826d3a 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -55,13 +55,13 @@ class PostSerializer extends BasicPostSerializer $attributes['content'] = $post->content; } - if ($post->edit_time) { - $attributes['editTime'] = $this->formatDate($post->edit_time); + if ($post->edited_at) { + $attributes['editTime'] = $this->formatDate($post->edited_at); } - if ($post->hide_time) { + if ($post->hidden_at) { $attributes['isHidden'] = true; - $attributes['hideTime'] = $this->formatDate($post->hide_time); + $attributes['hideTime'] = $this->formatDate($post->hidden_at); } $attributes += [ diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 8a521f6cb..106c39d7a 100644 --- a/framework/core/src/Api/Serializer/UserSerializer.php +++ b/framework/core/src/Api/Serializer/UserSerializer.php @@ -29,7 +29,8 @@ class UserSerializer extends BasicUserSerializer } /** - * {@inheritdoc} + * @param \Flarum\User\User $user + * @return array */ protected function getDefaultAttributes($user) { @@ -40,22 +41,22 @@ class UserSerializer extends BasicUserSerializer $canEdit = $gate->allows('edit', $user); $attributes += [ - 'joinTime' => $this->formatDate($user->join_time), - 'discussionsCount' => (int) $user->discussions_count, - 'commentsCount' => (int) $user->comments_count, + 'joinTime' => $this->formatDate($user->joined_at), + 'discussionsCount' => (int) $user->discussion_count, + 'commentsCount' => (int) $user->comment_count, 'canEdit' => $canEdit, 'canDelete' => $gate->allows('delete', $user), ]; if ($user->getPreference('discloseOnline')) { $attributes += [ - 'lastSeenTime' => $this->formatDate($user->last_seen_time) + 'lastSeenTime' => $this->formatDate($user->last_seen_at) ]; } if ($canEdit || $this->actor->id === $user->id) { $attributes += [ - 'isActivated' => (bool) $user->is_activated, + 'isActivated' => (bool) $user->is_email_confirmed, 'email' => $user->email ]; } diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index de44636a1..e48825d09 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -176,7 +176,7 @@ class Discussion extends AbstractModel public function hide(User $actor = null) { if (! $this->hidden_at) { - $this->hidden_at = time(); + $this->hidden_at = Carbon::now(); $this->hidden_user_id = $actor ? $actor->id : null; $this->raise(new Hidden($this)); diff --git a/framework/core/src/Discussion/DiscussionPolicy.php b/framework/core/src/Discussion/DiscussionPolicy.php index 33c521838..73f7fbc0d 100644 --- a/framework/core/src/Discussion/DiscussionPolicy.php +++ b/framework/core/src/Discussion/DiscussionPolicy.php @@ -92,7 +92,7 @@ class DiscussionPolicy extends AbstractPolicy // user, or the current user has permission to view hidden discussions. if (! $actor->hasPermission('discussion.hide')) { $query->where(function ($query) use ($actor) { - $query->whereNull('discussions.hide_time') + $query->whereNull('discussions.hidden_at') ->orWhere('user_id', $actor->id) ->orWhere(function ($query) use ($actor) { $this->events->fire( diff --git a/framework/core/src/Discussion/UserState.php b/framework/core/src/Discussion/UserState.php index 6de1c998e..4840b00b7 100644 --- a/framework/core/src/Discussion/UserState.php +++ b/framework/core/src/Discussion/UserState.php @@ -11,6 +11,7 @@ namespace Flarum\Discussion; +use Carbon\Carbon; use Flarum\Database\AbstractModel; use Flarum\Discussion\Event\UserRead; use Flarum\Foundation\EventGeneratorTrait; @@ -56,7 +57,7 @@ class UserState extends AbstractModel { if ($number > $this->last_read_at) { $this->last_read_at = $number; - $this->last_read_at = time(); + $this->last_read_at = Carbon::now(); $this->raise(new UserRead($this)); } diff --git a/framework/core/src/Http/AccessToken.php b/framework/core/src/Http/AccessToken.php index dad24ae3b..7b181bef6 100644 --- a/framework/core/src/Http/AccessToken.php +++ b/framework/core/src/Http/AccessToken.php @@ -11,6 +11,7 @@ namespace Flarum\Http; +use Carbon\Carbon; use Flarum\Database\AbstractModel; /** @@ -47,7 +48,7 @@ class AccessToken extends AbstractModel $token->id = str_random(40); $token->user_id = $userId; - $token->last_activity = time(); + $token->last_activity = Carbon::now(); $token->lifetime = $lifetime; return $token; @@ -55,7 +56,7 @@ class AccessToken extends AbstractModel public function touch() { - $this->last_activity = time(); + $this->last_activity = Carbon::now(); return $this->save(); } diff --git a/framework/core/src/Http/CookieFactory.php b/framework/core/src/Http/CookieFactory.php index 0ddb3de4c..f8ebd70e5 100644 --- a/framework/core/src/Http/CookieFactory.php +++ b/framework/core/src/Http/CookieFactory.php @@ -11,6 +11,7 @@ namespace Flarum\Http; +use Carbon\Carbon; use Dflydev\FigCookies\SetCookie; use Flarum\Foundation\Application; @@ -79,7 +80,7 @@ class CookieFactory if ($maxAge) { $cookie = $cookie ->withMaxAge($maxAge) - ->withExpires(time() + $maxAge); + ->withExpires(Carbon::now()->timestamp + $maxAge); } if ($this->domain != null) { diff --git a/framework/core/src/Http/Middleware/CollectGarbage.php b/framework/core/src/Http/Middleware/CollectGarbage.php index f4882c9fb..0075fe0ea 100644 --- a/framework/core/src/Http/Middleware/CollectGarbage.php +++ b/framework/core/src/Http/Middleware/CollectGarbage.php @@ -11,6 +11,7 @@ namespace Flarum\Http\Middleware; +use Carbon\Carbon; use Flarum\Http\AccessToken; use Flarum\User\AuthToken; use Flarum\User\EmailToken; @@ -54,9 +55,11 @@ class CollectGarbage implements MiddlewareInterface return; } - AccessToken::whereRaw('last_activity <= ? - lifetime', [time()])->delete(); + $time = Carbon::now()->timestamp; - $earliestToKeep = date('Y-m-d H:i:s', time() - 24 * 60 * 60); + AccessToken::whereRaw('last_activity <= ? - lifetime', [$time])->delete(); + + $earliestToKeep = date('Y-m-d H:i:s', $time - 24 * 60 * 60); EmailToken::where('created_at', '<=', $earliestToKeep)->delete(); PasswordToken::where('created_at', '<=', $earliestToKeep)->delete(); diff --git a/framework/core/src/Notification/Notification.php b/framework/core/src/Notification/Notification.php index cb906dea2..6a87ad692 100644 --- a/framework/core/src/Notification/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -11,6 +11,7 @@ namespace Flarum\Notification; +use Carbon\Carbon; use Flarum\Database\AbstractModel; use Flarum\User\User; @@ -70,7 +71,7 @@ class Notification extends AbstractModel */ public function read() { - $this->read_at = time(); + $this->read_at = Carbon::now(); } /** diff --git a/framework/core/src/Notification/NotificationRepository.php b/framework/core/src/Notification/NotificationRepository.php index 4b0d2b54a..57ed3b02a 100644 --- a/framework/core/src/Notification/NotificationRepository.php +++ b/framework/core/src/Notification/NotificationRepository.php @@ -11,6 +11,7 @@ namespace Flarum\Notification; +use Carbon\Carbon; use Flarum\User\User; class NotificationRepository @@ -53,6 +54,6 @@ class NotificationRepository */ public function markAllAsRead(User $user) { - Notification::where('user_id', $user->id)->update(['read_at' => time()]); + Notification::where('user_id', $user->id)->update(['read_at' => Carbon::now()]); } } diff --git a/framework/core/src/Post/Command/PostReplyHandler.php b/framework/core/src/Post/Command/PostReplyHandler.php index a3e066c50..816448da5 100644 --- a/framework/core/src/Post/Command/PostReplyHandler.php +++ b/framework/core/src/Post/Command/PostReplyHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Post\Command; -use DateTime; +use Carbon\Carbon; use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; use Flarum\Notification\NotificationSyncer; @@ -77,7 +77,7 @@ class PostReplyHandler // If this is the first post in the discussion, it's technically not a // "reply", so we won't check for that permission. - if ($discussion->number_index > 0) { + if ($discussion->post_number_index > 0) { $this->assertCan($actor, 'reply', $discussion); } @@ -92,7 +92,7 @@ class PostReplyHandler ); if ($actor->isAdmin() && ($time = array_get($command->data, 'attributes.time'))) { - $post->time = new DateTime($time); + $post->created_at = new Carbon($time); } $this->events->dispatch( diff --git a/framework/core/src/Post/CommentPost.php b/framework/core/src/Post/CommentPost.php index ae171ad23..4c0a58cb4 100644 --- a/framework/core/src/Post/CommentPost.php +++ b/framework/core/src/Post/CommentPost.php @@ -11,6 +11,7 @@ namespace Flarum\Post; +use Carbon\Carbon; use Flarum\Formatter\Formatter; use Flarum\Post\Event\Hidden; use Flarum\Post\Event\Posted; @@ -51,7 +52,7 @@ class CommentPost extends Post { $post = new static; - $post->created_at = time(); + $post->created_at = Carbon::now(); $post->discussion_id = $discussionId; $post->user_id = $userId; $post->type = static::$type; @@ -77,7 +78,7 @@ class CommentPost extends Post if ($this->content !== $content) { $this->content = $content; - $this->edited_at = time(); + $this->edited_at = Carbon::now(); $this->edited_user_id = $actor->id; $this->raise(new Revised($this)); @@ -95,7 +96,7 @@ class CommentPost extends Post public function hide(User $actor = null) { if (! $this->hidden_at) { - $this->hidden_at = time(); + $this->hidden_at = Carbon::now(); $this->hidden_user_id = $actor ? $actor->id : null; $this->raise(new Hidden($this)); diff --git a/framework/core/src/Post/DiscussionRenamedPost.php b/framework/core/src/Post/DiscussionRenamedPost.php index 21243d902..3feb96e5d 100644 --- a/framework/core/src/Post/DiscussionRenamedPost.php +++ b/framework/core/src/Post/DiscussionRenamedPost.php @@ -11,6 +11,8 @@ namespace Flarum\Post; +use Carbon\Carbon; + /** * A post which indicates that a discussion's title was changed. * @@ -64,7 +66,7 @@ class DiscussionRenamedPost extends AbstractEventPost implements MergeableInterf $post = new static; $post->content = static::buildContent($oldTitle, $newTitle); - $post->time = time(); + $post->created_at = Carbon::now(); $post->discussion_id = $discussionId; $post->user_id = $userId; diff --git a/framework/core/src/User/AuthToken.php b/framework/core/src/User/AuthToken.php index 516dfa3c0..d13fd4e3e 100644 --- a/framework/core/src/User/AuthToken.php +++ b/framework/core/src/User/AuthToken.php @@ -57,7 +57,7 @@ class AuthToken extends AbstractModel $token->token = str_random(40); $token->payload = $payload; - $token->created_at = time(); + $token->created_at = Carbon::now(); return $token; } diff --git a/framework/core/src/User/EmailToken.php b/framework/core/src/User/EmailToken.php index 0d25df3e7..5e73c7f53 100644 --- a/framework/core/src/User/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -11,6 +11,7 @@ namespace Flarum\User; +use Carbon\Carbon; use DateTime; use Flarum\Database\AbstractModel; use Flarum\User\Exception\InvalidConfirmationTokenException; @@ -55,7 +56,7 @@ class EmailToken extends AbstractModel $token->token = str_random(40); $token->user_id = $userId; $token->email = $email; - $token->created_at = time(); + $token->created_at = Carbon::now(); return $token; } @@ -80,9 +81,10 @@ class EmailToken extends AbstractModel */ public function scopeValidOrFail($query, $id) { + /** @var EmailToken $token */ $token = $query->find($id); - if (! $token || $token->created_at < new DateTime('-1 day')) { + if (! $token || $token->created_at->diffInDays() >= 1) { throw new InvalidConfirmationTokenException; } diff --git a/framework/core/src/User/PasswordToken.php b/framework/core/src/User/PasswordToken.php index 0597012ce..cda750209 100644 --- a/framework/core/src/User/PasswordToken.php +++ b/framework/core/src/User/PasswordToken.php @@ -11,6 +11,7 @@ namespace Flarum\User; +use Carbon\Carbon; use Flarum\Database\AbstractModel; /** @@ -54,7 +55,7 @@ class PasswordToken extends AbstractModel $token->token = str_random(40); $token->user_id = $userId; - $token->created_at = time(); + $token->created_at = Carbon::now(); return $token; } diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 53057990e..446d5d107 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -11,6 +11,7 @@ namespace Flarum\User; +use Carbon\Carbon; use DomainException; use Flarum\Database\AbstractModel; use Flarum\Database\ScopeVisibilityTrait; @@ -166,7 +167,7 @@ class User extends AbstractModel $user->username = $username; $user->email = $email; $user->password = $password; - $user->joined_at = time(); + $user->joined_at = Carbon::now(); $user->raise(new Registered($user)); @@ -270,7 +271,7 @@ class User extends AbstractModel */ public function markAllAsRead() { - $this->marked_all_as_read_at = time(); + $this->marked_all_as_read_at = Carbon::now(); return $this; } @@ -282,7 +283,7 @@ class User extends AbstractModel */ public function markNotificationsAsRead() { - $this->read_notifications_at = time(); + $this->read_notifications_at = Carbon::now(); return $this; } @@ -469,7 +470,7 @@ class User extends AbstractModel public function getNewNotificationsCount() { return $this->getUnreadNotifications()->filter(function ($notification) { - return $notification->time > $this->read_notifications_at ?: 0; + return $notification->created_at > $this->read_notifications_at ?: 0; })->count(); } @@ -568,7 +569,7 @@ class User extends AbstractModel */ public function updateLastSeen() { - $this->last_seen_at = time(); + $this->last_seen_at = Carbon::now(); return $this; } From 231c5e8da0c97c8e5e37b60b9751473fd9198cae Mon Sep 17 00:00:00 2001 From: luceos Date: Mon, 14 May 2018 11:50:06 +0000 Subject: [PATCH 09/85] Apply fixes from StyleCI [ci skip] [skip ci] --- framework/core/src/User/EmailToken.php | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/core/src/User/EmailToken.php b/framework/core/src/User/EmailToken.php index 5e73c7f53..ab0f610a0 100644 --- a/framework/core/src/User/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -12,7 +12,6 @@ namespace Flarum\User; use Carbon\Carbon; -use DateTime; use Flarum\Database\AbstractModel; use Flarum\User\Exception\InvalidConfirmationTokenException; From 523acba2aaf55a3d4afaebcad9f2556d00fc637d Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Wed, 16 May 2018 09:36:04 +0200 Subject: [PATCH 10/85] new api tests uncovered more issues, fixed tokens and discussion posts --- .../Controller/ShowDiscussionController.php | 4 ++-- .../src/Api/Controller/TokenController.php | 2 +- framework/core/src/Http/AccessToken.php | 21 ++++++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index ba1c43684..33fc20477 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -118,7 +118,7 @@ class ShowDiscussionController extends AbstractShowController */ private function loadPostIds(Discussion $discussion, User $actor) { - return $discussion->posts()->whereVisibleTo($actor)->orderBy('time')->pluck('id')->all(); + return $discussion->posts()->whereVisibleTo($actor)->orderBy('created_at')->pluck('id')->all(); } /** @@ -172,7 +172,7 @@ class ShowDiscussionController extends AbstractShowController { $query = $discussion->posts()->whereVisibleTo($actor); - $query->orderBy('time')->skip($offset)->take($limit)->with($include); + $query->orderBy('created_at')->skip($offset)->take($limit)->with($include); $posts = $query->get()->all(); diff --git a/framework/core/src/Api/Controller/TokenController.php b/framework/core/src/Api/Controller/TokenController.php index e0f6f6464..dd854c98b 100644 --- a/framework/core/src/Api/Controller/TokenController.php +++ b/framework/core/src/Api/Controller/TokenController.php @@ -70,7 +70,7 @@ class TokenController implements ControllerInterface $token->save(); return new JsonResponse([ - 'token' => $token->id, + 'token' => $token->token, 'userId' => $user->id ]); } diff --git a/framework/core/src/Http/AccessToken.php b/framework/core/src/Http/AccessToken.php index 7b181bef6..cd0c6aea4 100644 --- a/framework/core/src/Http/AccessToken.php +++ b/framework/core/src/Http/AccessToken.php @@ -13,12 +13,13 @@ namespace Flarum\Http; use Carbon\Carbon; use Flarum\Database\AbstractModel; +use Flarum\User\User; /** - * @property string $id + * @property string $token * @property int $user_id - * @property int $last_activity - * @property int $lifetime + * @property int $last_activity_at + * @property int $lifetime_seconds * @property \Flarum\User\User|null $user */ class AccessToken extends AbstractModel @@ -35,6 +36,10 @@ class AccessToken extends AbstractModel */ public $incrementing = false; + protected $primaryKey = 'token'; + + protected $dates = ['last_activity_at']; + /** * Generate an access token for the specified user. * @@ -46,17 +51,17 @@ class AccessToken extends AbstractModel { $token = new static; - $token->id = str_random(40); + $token->token = str_random(40); $token->user_id = $userId; - $token->last_activity = Carbon::now(); - $token->lifetime = $lifetime; + $token->last_activity_at = Carbon::now(); + $token->lifetime_seconds = $lifetime; return $token; } public function touch() { - $this->last_activity = Carbon::now(); + $this->last_activity_at = Carbon::now(); return $this->save(); } @@ -68,6 +73,6 @@ class AccessToken extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\User\User'); + return $this->belongsTo(User::class); } } From 88d2e345b1409b19d549eb39c399bf3fdaa680b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Mon, 21 May 2018 21:19:38 +0200 Subject: [PATCH 11/85] undo session interface change --- framework/core/src/User/User.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 446d5d107..16bf9fb64 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -35,7 +35,7 @@ use Flarum\User\Event\PasswordChanged; use Flarum\User\Event\Registered; use Flarum\User\Event\Renamed; use Illuminate\Contracts\Hashing\Hasher; -use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Illuminate\Contracts\Session\Session; /** * @property int $id @@ -82,7 +82,7 @@ class User extends AbstractModel protected $permissions = null; /** - * @var SessionInterface + * @var Session */ protected $session; @@ -698,7 +698,7 @@ class User extends AbstractModel } /** - * @return SessionInterface + * @return Session */ public function getSession() { @@ -706,9 +706,9 @@ class User extends AbstractModel } /** - * @param SessionInterface $session + * @param Session $session */ - public function setSession(SessionInterface $session) + public function setSession(Session $session) { $this->session = $session; } From a3c6833b54af705ff139743630aeccb194e8ad47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Tue, 12 Jun 2018 21:33:17 +0200 Subject: [PATCH 12/85] migrating user preferences obviously works on empty table --- ..._create_notification_preferences_table.php | 30 +++++++++++ ...create_users_table_preferences_columns.php | 27 ++++++++++ ...igrate_users_table_preferences_columns.php | 51 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 framework/core/migrations/2018_01_30_222800_create_notification_preferences_table.php create mode 100644 framework/core/migrations/2018_01_30_222800_create_users_table_preferences_columns.php create mode 100644 framework/core/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php diff --git a/framework/core/migrations/2018_01_30_222800_create_notification_preferences_table.php b/framework/core/migrations/2018_01_30_222800_create_notification_preferences_table.php new file mode 100644 index 000000000..17f1b8b62 --- /dev/null +++ b/framework/core/migrations/2018_01_30_222800_create_notification_preferences_table.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->create('notification_preferences', function (Blueprint $table) { + $table->integer('user_id')->unsigned(); + $table->string('type'); + $table->string('channel'); + $table->boolean('enabled')->default(false); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->drop('notification_preferences'); + } +]; diff --git a/framework/core/migrations/2018_01_30_222800_create_users_table_preferences_columns.php b/framework/core/migrations/2018_01_30_222800_create_users_table_preferences_columns.php new file mode 100644 index 000000000..6fa9b5c93 --- /dev/null +++ b/framework/core/migrations/2018_01_30_222800_create_users_table_preferences_columns.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->boolean('disclose_online')->default(false); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->dropColumn('disclose_online'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php b/framework/core/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php new file mode 100644 index 000000000..c95c10654 --- /dev/null +++ b/framework/core/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Schema\Builder; +use Illuminate\Support\Arr; + +return [ + 'up' => function (Builder $builder) { + $db = $builder->getConnection(); + + $db->table('users') + ->whereNotNull('preferences') + ->orderBy('id') + ->chunk(50, function (Collection $users) use ($db) { + $users->each(function ($user) use ($db) { + collect(json_decode(Arr::get($user, 'preferences', '{}'))) + ->each(function ($value, $key) use ($user, $db) { + if ($key === 'discloses_online') { + $db->table('users') + ->where('id', $user['id']) + ->update(['discloses_online' => (bool) $value]); + } + if (preg_match('/^notify_(?[^_]+)_(?.*)$/', $key, $matches)) { + $db->table('notification_preferences') + ->insert([ + 'user_id' => $user['id'], + 'type' => $matches['type'], + 'channel' => $matches['channel'], + 'enabled' => (bool) $value + ]); + } + }); + }); + }); + }, + + 'down' => function (Builder $builder) { + $db = $builder->getConnection(); + + $db->table('notification_preferences')->truncate(); + } +]; From 0fb5572f2040cd6c5b1ca66155f96617b8e26c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Fri, 22 Jun 2018 23:43:37 +0200 Subject: [PATCH 13/85] we need to leave the preferences column for now --- .../migrations/2018_01_30_222900_change_users_b8_columns.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php b/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php index 1826ea34b..c00dbb449 100644 --- a/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php +++ b/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php @@ -23,7 +23,7 @@ return [ $table->renameColumn('read_time', 'marked_all_as_read_at'); $table->renameColumn('notifications_read_time', 'read_notifications_at'); $table->renameColumn('avatar_path', 'avatar_url'); - $table->dropColumn('bio', 'preferences'); + $table->dropColumn('bio'); }); }, @@ -38,7 +38,6 @@ return [ $table->renameColumn('read_notifications_at', 'notifications_read_time'); $table->renameColumn('avatar_url', 'avatar_path'); $table->text('bio')->nullable(); - $table->binary('preferences')->nullable(); }); } ]; From 7b23e4625068877e72ae874f572273974dc63675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Wed, 27 Jun 2018 21:09:32 +0200 Subject: [PATCH 14/85] not dropping bio due to not having a replacement --- .../migrations/2018_01_30_222900_change_users_b8_columns.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php b/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php index c00dbb449..e7bb77c9e 100644 --- a/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php +++ b/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php @@ -23,7 +23,6 @@ return [ $table->renameColumn('read_time', 'marked_all_as_read_at'); $table->renameColumn('notifications_read_time', 'read_notifications_at'); $table->renameColumn('avatar_path', 'avatar_url'); - $table->dropColumn('bio'); }); }, @@ -37,7 +36,6 @@ return [ $table->renameColumn('marked_all_as_read_at', 'read_time'); $table->renameColumn('read_notifications_at', 'notifications_read_time'); $table->renameColumn('avatar_url', 'avatar_path'); - $table->text('bio')->nullable(); }); } ]; From 36608b31bec6934ffcfe87002120615dfaac68e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Wed, 27 Jun 2018 21:22:28 +0200 Subject: [PATCH 15/85] Revert "migrating user preferences obviously works on empty table" This reverts commit a3c6833b54af705ff139743630aeccb194e8ad47. --- ..._create_notification_preferences_table.php | 30 ----------- ...create_users_table_preferences_columns.php | 27 ---------- ...igrate_users_table_preferences_columns.php | 51 ------------------- 3 files changed, 108 deletions(-) delete mode 100644 framework/core/migrations/2018_01_30_222800_create_notification_preferences_table.php delete mode 100644 framework/core/migrations/2018_01_30_222800_create_users_table_preferences_columns.php delete mode 100644 framework/core/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php diff --git a/framework/core/migrations/2018_01_30_222800_create_notification_preferences_table.php b/framework/core/migrations/2018_01_30_222800_create_notification_preferences_table.php deleted file mode 100644 index 17f1b8b62..000000000 --- a/framework/core/migrations/2018_01_30_222800_create_notification_preferences_table.php +++ /dev/null @@ -1,30 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $schema->create('notification_preferences', function (Blueprint $table) { - $table->integer('user_id')->unsigned(); - $table->string('type'); - $table->string('channel'); - $table->boolean('enabled')->default(false); - - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('notification_preferences'); - } -]; diff --git a/framework/core/migrations/2018_01_30_222800_create_users_table_preferences_columns.php b/framework/core/migrations/2018_01_30_222800_create_users_table_preferences_columns.php deleted file mode 100644 index 6fa9b5c93..000000000 --- a/framework/core/migrations/2018_01_30_222800_create_users_table_preferences_columns.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $schema->table('users', function (Blueprint $table) { - $table->boolean('disclose_online')->default(false); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('users', function (Blueprint $table) { - $table->dropColumn('disclose_online'); - }); - } -]; diff --git a/framework/core/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php b/framework/core/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php deleted file mode 100644 index c95c10654..000000000 --- a/framework/core/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php +++ /dev/null @@ -1,51 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Eloquent\Collection; -use Illuminate\Database\Schema\Builder; -use Illuminate\Support\Arr; - -return [ - 'up' => function (Builder $builder) { - $db = $builder->getConnection(); - - $db->table('users') - ->whereNotNull('preferences') - ->orderBy('id') - ->chunk(50, function (Collection $users) use ($db) { - $users->each(function ($user) use ($db) { - collect(json_decode(Arr::get($user, 'preferences', '{}'))) - ->each(function ($value, $key) use ($user, $db) { - if ($key === 'discloses_online') { - $db->table('users') - ->where('id', $user['id']) - ->update(['discloses_online' => (bool) $value]); - } - if (preg_match('/^notify_(?[^_]+)_(?.*)$/', $key, $matches)) { - $db->table('notification_preferences') - ->insert([ - 'user_id' => $user['id'], - 'type' => $matches['type'], - 'channel' => $matches['channel'], - 'enabled' => (bool) $value - ]); - } - }); - }); - }); - }, - - 'down' => function (Builder $builder) { - $db = $builder->getConnection(); - - $db->table('notification_preferences')->truncate(); - } -]; From 993513b9c403908a33d71068ab4f709a229f7c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Wed, 27 Jun 2018 21:33:53 +0200 Subject: [PATCH 16/85] fixed some migration names and used helper where appropriate --- ...nge_user_discussions_discussions_users.php | 12 ++------- ..._072600_change_email_tokens_b8_columns.php | 27 ------------------- ...change_email_tokens_rename_id_to_token.php | 14 ++++++++++ ...ame_permissions_to_groups_permissions.php} | 0 ...00_rename_users_groups_to_groups_users.php | 2 +- ...ge_password_tokens_rename_id_to_token.php} | 0 6 files changed, 17 insertions(+), 38 deletions(-) delete mode 100644 framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php create mode 100644 framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php rename framework/core/migrations/{2018_01_18_130400_rename_permissions_to_group_permissions.php => 2018_01_18_130400_rename_permissions_to_groups_permissions.php} (100%) rename framework/core/migrations/{2018_01_18_134400_change_password_tokens_id_to_token.php => 2018_01_18_134400_change_password_tokens_rename_id_to_token.php} (100%) diff --git a/framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php b/framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php index c0e48bb91..e1ac5e026 100644 --- a/framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php +++ b/framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php @@ -9,14 +9,6 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Schema\Builder; +use Flarum\Database\Migration; -return [ - 'up' => function (Builder $schema) { - $schema->rename('users_discussions', 'discussions_users'); - }, - - 'down' => function (Builder $schema) { - $schema->rename('discussions_users', 'users_discussions'); - } -]; +return Migration::renameTable('users_discussions', 'discussions_users'); diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php deleted file mode 100644 index 4bb891a1f..000000000 --- a/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $schema->table('email_tokens', function (Blueprint $table) { - $table->renameColumn('id', 'token'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('email_tokens', function (Blueprint $table) { - $table->renameColumn('token', 'id'); - }); - } -]; diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php new file mode 100644 index 000000000..e62a842c6 --- /dev/null +++ b/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php @@ -0,0 +1,14 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameColumn('email_tokens', 'id','token'); diff --git a/framework/core/migrations/2018_01_18_130400_rename_permissions_to_group_permissions.php b/framework/core/migrations/2018_01_18_130400_rename_permissions_to_groups_permissions.php similarity index 100% rename from framework/core/migrations/2018_01_18_130400_rename_permissions_to_group_permissions.php rename to framework/core/migrations/2018_01_18_130400_rename_permissions_to_groups_permissions.php diff --git a/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php b/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php index 40f4178f9..32b110e19 100644 --- a/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php +++ b/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php @@ -11,4 +11,4 @@ use Flarum\Database\Migration; -return Migration::renameTable('users_groups', 'group_user'); +return Migration::renameTable('users_groups', 'group_users'); diff --git a/framework/core/migrations/2018_01_18_134400_change_password_tokens_id_to_token.php b/framework/core/migrations/2018_01_18_134400_change_password_tokens_rename_id_to_token.php similarity index 100% rename from framework/core/migrations/2018_01_18_134400_change_password_tokens_id_to_token.php rename to framework/core/migrations/2018_01_18_134400_change_password_tokens_rename_id_to_token.php From ea2e1fe1baa006b167d4cecffb979845c70895b0 Mon Sep 17 00:00:00 2001 From: luceos Date: Wed, 27 Jun 2018 19:34:07 +0000 Subject: [PATCH 17/85] Apply fixes from StyleCI [ci skip] [skip ci] --- ...2018_01_15_072600_change_email_tokens_rename_id_to_token.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php index e62a842c6..64586a4aa 100644 --- a/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php +++ b/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php @@ -11,4 +11,4 @@ use Flarum\Database\Migration; -return Migration::renameColumn('email_tokens', 'id','token'); +return Migration::renameColumn('email_tokens', 'id', 'token'); From c8a9e8425ea382a2792937a2ec01bad4ec8309bb Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Mon, 9 Jul 2018 11:53:59 +0200 Subject: [PATCH 18/85] reset the relation table naming from groups_users to adhere to laravel convention group_user --- ... => 2018_01_18_130400_rename_users_groups_to_group_user.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename framework/core/migrations/{2018_01_18_130400_rename_users_groups_to_groups_users.php => 2018_01_18_130400_rename_users_groups_to_group_user.php} (80%) diff --git a/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php b/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_group_user.php similarity index 80% rename from framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php rename to framework/core/migrations/2018_01_18_130400_rename_users_groups_to_group_user.php index 32b110e19..40f4178f9 100644 --- a/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_groups_users.php +++ b/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_group_user.php @@ -11,4 +11,4 @@ use Flarum\Database\Migration; -return Migration::renameTable('users_groups', 'group_users'); +return Migration::renameTable('users_groups', 'group_user'); From 66d32f2efb2784e8c8068ef124850a47e83f9dc9 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Thu, 19 Jul 2018 09:15:59 +0200 Subject: [PATCH 19/85] undo carbon change as proposed in review --- framework/core/src/Http/CookieFactory.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/core/src/Http/CookieFactory.php b/framework/core/src/Http/CookieFactory.php index f8ebd70e5..0ddb3de4c 100644 --- a/framework/core/src/Http/CookieFactory.php +++ b/framework/core/src/Http/CookieFactory.php @@ -11,7 +11,6 @@ namespace Flarum\Http; -use Carbon\Carbon; use Dflydev\FigCookies\SetCookie; use Flarum\Foundation\Application; @@ -80,7 +79,7 @@ class CookieFactory if ($maxAge) { $cookie = $cookie ->withMaxAge($maxAge) - ->withExpires(Carbon::now()->timestamp + $maxAge); + ->withExpires(time() + $maxAge); } if ($this->domain != null) { From 66ddbfb94d6b36320502c2ad947f4739d8fabf9f Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Thu, 19 Jul 2018 09:22:34 +0200 Subject: [PATCH 20/85] split up the migration to create and seed notifications_from --- ...132900_create_notifications_from_table.php | 11 ------- ...8_132901_seed_notifications_from_table.php | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php diff --git a/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php b/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php index 83fad7b64..63fa38c8b 100644 --- a/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php +++ b/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php @@ -21,17 +21,6 @@ return [ $table->foreign('id')->references('id')->on('notifications')->onDelete('cascade'); $table->foreign('from_user_id')->references('id')->on('users')->onDelete('cascade'); }); - - $schema->getConnection()->table('notifications')->chunkById(100, function ($notifications) use ($schema) { - foreach ($notifications as $notification) { - $insert = [ - 'id' => $notification->id, - 'from_user_id' => $notification->sender_id - ]; - - $schema->getConnection()->table('notifications_from')->updateOrInsert($insert, $insert); - } - }); }, 'down' => function (Builder $schema) { diff --git a/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php b/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php new file mode 100644 index 000000000..c12fd4c22 --- /dev/null +++ b/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->getConnection()->table('notifications')->chunkById(100, function ($notifications) use ($schema) { + foreach ($notifications as $notification) { + $insert = [ + 'id' => $notification->id, + 'from_user_id' => $notification->sender_id + ]; + + $schema->getConnection()->table('notifications_from')->updateOrInsert($insert, $insert); + } + }); + }, + + 'down' => function (Builder $schema) { + $schema->getConnection()->table('notifications_from')->truncate(); + } +]; From cb89203ac52fb7437bd2d528da65d468b413fe0c Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Thu, 19 Jul 2018 09:45:29 +0200 Subject: [PATCH 21/85] remove migration (initially was intended) to change settings.value to longblob --- ..._084700_change_settings_value_longblob.php | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 framework/core/migrations/2018_01_19_084700_change_settings_value_longblob.php diff --git a/framework/core/migrations/2018_01_19_084700_change_settings_value_longblob.php b/framework/core/migrations/2018_01_19_084700_change_settings_value_longblob.php deleted file mode 100644 index b6493cfc4..000000000 --- a/framework/core/migrations/2018_01_19_084700_change_settings_value_longblob.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $prefix = $schema->getConnection()->getTablePrefix(); -// $schema->getConnection()->statement('ALTER TABLE '.$prefix.'settings MODIFY "value" LONGBLOB'); - }, - - 'down' => function (Builder $schema) { - $schema->table('posts', function (Blueprint $table) { -// $table->longText('value')->nullable()->change(); - }); - } -]; From ccd472901172a675e7204c65dc486a50d9172dc7 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Thu, 19 Jul 2018 09:52:20 +0200 Subject: [PATCH 22/85] instead of changing fulltext, use medium text schema builder change on posts.content --- .../migrations/2018_01_18_135000_change_posts_b8_columns.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php index 03b44f92c..406210a81 100644 --- a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php +++ b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php @@ -34,9 +34,8 @@ return [ $table->renameColumn('edited_user_id', 'edit_user_id'); $table->renameColumn('edited_user_id', 'hidden_user_id'); - }); - $prefix = $schema->getConnection()->getTablePrefix(); - $schema->getConnection()->statement('ALTER TABLE '.$prefix.'posts MODIFY content FULLTEXT'); + $table->mediumText('content')->change(); + }); } ]; From aca0f3c57a556689ef70c695ca2477d535dc5128 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Thu, 19 Jul 2018 10:36:46 +0200 Subject: [PATCH 23/85] added constraints, discussions_first_post_id_foreign blocks here --- ...093900_change_access_tokens_b8_columns.php | 4 +++ ...1_155200_change_discussions_b8_columns.php | 11 +++++++ ...00_change_discussions_users_b8_columns.php | 5 +++ ..._072600_change_email_tokens_b8_columns.php | 31 +++++++++++++++++++ ...change_email_tokens_rename_id_to_token.php | 14 --------- ...133000_change_notifications_b8_columns.php | 4 +++ ...8_01_18_135000_change_posts_b8_columns.php | 10 ++++++ ...18_07_19_101300_constraints_group_user.php | 28 +++++++++++++++++ ..._101301_constraints_groups_permissions.php | 27 ++++++++++++++++ ..._19_101301_constraints_password_tokens.php | 27 ++++++++++++++++ 10 files changed, 147 insertions(+), 14 deletions(-) create mode 100644 framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php delete mode 100644 framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php create mode 100644 framework/core/migrations/2018_07_19_101300_constraints_group_user.php create mode 100644 framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php create mode 100644 framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php diff --git a/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php b/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php index 9fd9df5fb..823c827d4 100644 --- a/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php +++ b/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php @@ -19,6 +19,8 @@ return [ $table->renameColumn('lifetime', 'lifetime_seconds'); $table->renameColumn('last_activity', 'last_activity_at'); $table->dateTime('created_at'); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); }, @@ -28,6 +30,8 @@ return [ $table->renameColumn('last_activity_at', 'last_activity'); $table->dropColumn('created_at'); $table->renameColumn('token', 'id'); + + $table->dropForeign('access_tokens_user_id_foreign'); }); } ]; diff --git a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php index c88fa528a..5ef86a15d 100644 --- a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php +++ b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php @@ -25,6 +25,12 @@ return [ $table->renameColumn('last_user_id', 'last_posted_user_id'); $table->renameColumn('hide_time', 'hidden_at'); $table->renameColumn('hide_user_id', 'hidden_user_id'); + + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('last_posted_user_id')->references('id')->on('users'); + $table->foreign('hidden_user_id')->references('id')->on('users'); + $table->foreign('first_post_id')->references('id')->on('posts'); + $table->foreign('last_post_id')->references('id')->on('posts'); }); }, @@ -40,6 +46,11 @@ return [ $table->renameColumn('last_posted_user_id', 'last_user_id'); $table->renameColumn('hidden_at', 'hide_time'); $table->renameColumn('hidden_user_id', 'hide_user_id'); + + $table->dropForeign([ + 'discussions_user_id_foreign', 'discussions_last_posted_user_id', 'hidden_user_id', + 'first_post_id', 'last_post_id' + ]); }); } ]; diff --git a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php index 5797a033f..1fc3ccd43 100644 --- a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php +++ b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php @@ -17,6 +17,9 @@ return [ $schema->table('discussions_users', function (Blueprint $table) { $table->renameColumn('read_time', 'last_read_at'); $table->renameColumn('read_number', 'last_read_post_number'); + + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); }); }, @@ -24,6 +27,8 @@ return [ $schema->table('discussions_users', function (Blueprint $table) { $table->renameColumn('last_read_at', 'read_time'); $table->renameColumn('last_read_post_number', 'read_number'); + + $table->dropForeign(['discussions_users_user_id_foreign', 'discussions_users_discussion_id_foreign']); }); } ]; diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php new file mode 100644 index 000000000..aa8153b22 --- /dev/null +++ b/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->renameColumn('id', 'token'); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->renameColumn('token', 'id'); + + $table->dropForeign('email_tokens_user_id_foreign'); + }); + } +]; diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php deleted file mode 100644 index 64586a4aa..000000000 --- a/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php +++ /dev/null @@ -1,14 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Flarum\Database\Migration; - -return Migration::renameColumn('email_tokens', 'id', 'token'); diff --git a/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php b/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php index 2261b0248..aa3e739e6 100644 --- a/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php +++ b/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php @@ -21,6 +21,8 @@ return [ $table->timestamp('read_at')->nullable(); $table->timestamp('deleted_at')->nullable(); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); $schema->getConnection()->table('notifications') @@ -46,6 +48,8 @@ return [ $table->boolean('is_read'); $table->boolean('is_deleted'); + + $table->dropForeign('notifications_user_id_foreign'); }); $schema->getConnection()->table('notifications') diff --git a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php index 406210a81..659699a71 100644 --- a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php +++ b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php @@ -23,6 +23,11 @@ return [ $table->renameColumn('hide_user_id', 'hidden_user_id'); $table->longText('content')->change(); + + $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('edited_user_id')->references('id')->on('users'); + $table->foreign('hidden_user_id')->references('id')->on('users'); }); }, @@ -36,6 +41,11 @@ return [ $table->renameColumn('edited_user_id', 'hidden_user_id'); $table->mediumText('content')->change(); + + $table->dropForeign([ + 'posts_user_id_foreign', 'posts_discussion_id_foreign', + 'posts_edited_user_id_foreign', 'posts_hidden_user_id_foreign' + ]); }); } ]; diff --git a/framework/core/migrations/2018_07_19_101300_constraints_group_user.php b/framework/core/migrations/2018_07_19_101300_constraints_group_user.php new file mode 100644 index 000000000..1f2b60564 --- /dev/null +++ b/framework/core/migrations/2018_07_19_101300_constraints_group_user.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $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) { + $table->dropForeign(['group_user_user_id_foreign', 'group_user_group_id_foreign']); + }); + } +]; diff --git a/framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php b/framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php new file mode 100644 index 000000000..2e46377b6 --- /dev/null +++ b/framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('groups_permissions', function (Blueprint $table) { + $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('group_user', function (Blueprint $table) { + $table->dropForeign('group_user_group_id_foreign'); + }); + } +]; diff --git a/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php b/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php new file mode 100644 index 000000000..d4b5e530d --- /dev/null +++ b/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $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) { + $table->dropForeign('password_tokens_user_id_foreign'); + }); + } +]; From cbc95e42ddeede4cc3a5afe810df6c96ba9e3b9e Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Fri, 20 Jul 2018 08:41:01 +0200 Subject: [PATCH 24/85] decided to leave the posts.discussion_id foreign key constraint to discussions out for now --- .../2018_01_11_155200_change_discussions_b8_columns.php | 6 +++--- ...18_01_15_071800_change_discussions_users_b8_columns.php | 2 +- ..._18_130400_rename_permissions_to_groups_permissions.php | 2 +- .../2018_01_18_135000_change_posts_b8_columns.php | 7 +++---- ... => 2018_07_19_101301_constraints_group_permission.php} | 6 +++--- framework/core/src/Discussion/Discussion.php | 2 +- framework/core/src/Group/Group.php | 2 +- framework/core/src/Group/Permission.php | 2 +- 8 files changed, 14 insertions(+), 15 deletions(-) rename framework/core/migrations/{2018_07_19_101301_constraints_groups_permissions.php => 2018_07_19_101301_constraints_group_permission.php} (71%) diff --git a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php index 5ef86a15d..fbd04da1d 100644 --- a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php +++ b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php @@ -26,9 +26,9 @@ return [ $table->renameColumn('hide_time', 'hidden_at'); $table->renameColumn('hide_user_id', 'hidden_user_id'); - $table->foreign('user_id')->references('id')->on('users'); - $table->foreign('last_posted_user_id')->references('id')->on('users'); - $table->foreign('hidden_user_id')->references('id')->on('users'); + $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'); $table->foreign('first_post_id')->references('id')->on('posts'); $table->foreign('last_post_id')->references('id')->on('posts'); }); diff --git a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php index 1fc3ccd43..c48874a6c 100644 --- a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php +++ b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php @@ -18,7 +18,7 @@ return [ $table->renameColumn('read_time', 'last_read_at'); $table->renameColumn('read_number', 'last_read_post_number'); - $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); }); }, diff --git a/framework/core/migrations/2018_01_18_130400_rename_permissions_to_groups_permissions.php b/framework/core/migrations/2018_01_18_130400_rename_permissions_to_groups_permissions.php index 8d8761878..c36d11e4e 100644 --- a/framework/core/migrations/2018_01_18_130400_rename_permissions_to_groups_permissions.php +++ b/framework/core/migrations/2018_01_18_130400_rename_permissions_to_groups_permissions.php @@ -11,4 +11,4 @@ use Flarum\Database\Migration; -return Migration::renameTable('permissions', 'groups_permissions'); +return Migration::renameTable('permissions', 'group_permission'); diff --git a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php index 659699a71..2ac9c1af0 100644 --- a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php +++ b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php @@ -24,10 +24,9 @@ return [ $table->longText('content')->change(); - $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); - $table->foreign('user_id')->references('id')->on('users'); - $table->foreign('edited_user_id')->references('id')->on('users'); - $table->foreign('hidden_user_id')->references('id')->on('users'); + $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'); }); }, diff --git a/framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php b/framework/core/migrations/2018_07_19_101301_constraints_group_permission.php similarity index 71% rename from framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php rename to framework/core/migrations/2018_07_19_101301_constraints_group_permission.php index 2e46377b6..4ed7a3a85 100644 --- a/framework/core/migrations/2018_07_19_101301_constraints_groups_permissions.php +++ b/framework/core/migrations/2018_07_19_101301_constraints_group_permission.php @@ -14,14 +14,14 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('groups_permissions', function (Blueprint $table) { + $schema->table('group_permission', function (Blueprint $table) { $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); }); }, 'down' => function (Builder $schema) { - $schema->table('group_user', function (Blueprint $table) { - $table->dropForeign('group_user_group_id_foreign'); + $schema->table('group_permission', function (Blueprint $table) { + $table->dropForeign('group_permission_group_id_foreign'); }); } ]; diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index e48825d09..1b1bfc194 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -400,7 +400,7 @@ class Discussion extends AbstractModel */ public function readers() { - return $this->belongsToMany(User::class, 'discussions_users'); + return $this->belongsToMany(User::class); } /** diff --git a/framework/core/src/Group/Group.php b/framework/core/src/Group/Group.php index 14daf1b69..0ce9741a2 100644 --- a/framework/core/src/Group/Group.php +++ b/framework/core/src/Group/Group.php @@ -121,7 +121,7 @@ class Group extends AbstractModel */ public function users() { - return $this->belongsToMany(User::class, 'users_groups'); + return $this->belongsToMany(User::class); } /** diff --git a/framework/core/src/Group/Permission.php b/framework/core/src/Group/Permission.php index ae50923d8..e5e4d872f 100644 --- a/framework/core/src/Group/Permission.php +++ b/framework/core/src/Group/Permission.php @@ -23,7 +23,7 @@ class Permission extends AbstractModel /** * {@inheritdoc} */ - protected $table = 'groups_permissions'; + protected $table = 'group_permission'; /** * Define the relationship with the group that this permission is for. From 9d13aae115acc92b2b5089f3d28f117c0c7b28fb Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Fri, 20 Jul 2018 09:23:03 +0200 Subject: [PATCH 25/85] forgot to name a few constraints properly on the dropForeign statement --- .../2018_01_11_155200_change_discussions_b8_columns.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php index fbd04da1d..ff81a0463 100644 --- a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php +++ b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php @@ -48,8 +48,8 @@ return [ $table->renameColumn('hidden_user_id', 'hide_user_id'); $table->dropForeign([ - 'discussions_user_id_foreign', 'discussions_last_posted_user_id', 'hidden_user_id', - 'first_post_id', 'last_post_id' + 'discussions_user_id_foreign', 'discussions_last_posted_user_id_foreign', 'discussions_hidden_user_id_foreign', + 'discussions_first_post_id_foreign', 'discussions_last_post_id_foreign' ]); }); } From 34e7355c58dc1c89f5f490623f73028eb7d30980 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Fri, 20 Jul 2018 09:24:42 +0200 Subject: [PATCH 26/85] fixed another foreign key drop with incorrect name --- .../migrations/2018_01_11_095000_change_api_keys_b8_columns.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php b/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php index 478c578cf..4322e2dc8 100644 --- a/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php +++ b/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php @@ -28,7 +28,7 @@ return [ 'down' => function (Builder $schema) { $schema->table('api_keys', function (Blueprint $table) { - $table->dropForeign(['user_id']); + $table->dropForeign('api_keys_user_id_foreign'); $table->dropColumn('id', 'allowed_ips', 'user_id', 'scopes', 'created_at'); }); } From 39501f1dd01e6fcc9509f49b01bddf15a5d9cb52 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Fri, 20 Jul 2018 09:35:16 +0200 Subject: [PATCH 27/85] resetting to short annotation for dropping foreign key constraint, as per docs, must use array notation for this to work --- .../2018_01_11_093900_change_access_tokens_b8_columns.php | 2 +- .../2018_01_11_095000_change_api_keys_b8_columns.php | 2 +- .../2018_01_11_155200_change_discussions_b8_columns.php | 4 ++-- .../2018_01_15_071800_change_discussions_users_b8_columns.php | 2 +- .../2018_01_15_072600_change_email_tokens_b8_columns.php | 2 +- .../2018_01_18_133000_change_notifications_b8_columns.php | 2 +- .../migrations/2018_01_18_135000_change_posts_b8_columns.php | 4 ++-- .../migrations/2018_07_19_101300_constraints_group_user.php | 2 +- .../2018_07_19_101301_constraints_group_permission.php | 2 +- .../2018_07_19_101301_constraints_password_tokens.php | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php b/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php index 823c827d4..4e4965d3b 100644 --- a/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php +++ b/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php @@ -31,7 +31,7 @@ return [ $table->dropColumn('created_at'); $table->renameColumn('token', 'id'); - $table->dropForeign('access_tokens_user_id_foreign'); + $table->dropForeign(['user_id']); }); } ]; diff --git a/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php b/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php index 4322e2dc8..478c578cf 100644 --- a/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php +++ b/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php @@ -28,7 +28,7 @@ return [ 'down' => function (Builder $schema) { $schema->table('api_keys', function (Blueprint $table) { - $table->dropForeign('api_keys_user_id_foreign'); + $table->dropForeign(['user_id']); $table->dropColumn('id', 'allowed_ips', 'user_id', 'scopes', 'created_at'); }); } diff --git a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php index ff81a0463..6485fdcab 100644 --- a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php +++ b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php @@ -48,8 +48,8 @@ return [ $table->renameColumn('hidden_user_id', 'hide_user_id'); $table->dropForeign([ - 'discussions_user_id_foreign', 'discussions_last_posted_user_id_foreign', 'discussions_hidden_user_id_foreign', - 'discussions_first_post_id_foreign', 'discussions_last_post_id_foreign' + 'user_id', 'last_posted_user_id', 'hidden_user_id', + 'first_post_id', 'last_post_id' ]); }); } diff --git a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php index c48874a6c..a0176f29d 100644 --- a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php +++ b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php @@ -28,7 +28,7 @@ return [ $table->renameColumn('last_read_at', 'read_time'); $table->renameColumn('last_read_post_number', 'read_number'); - $table->dropForeign(['discussions_users_user_id_foreign', 'discussions_users_discussion_id_foreign']); + $table->dropForeign(['users_user_id', 'users_discussion_id']); }); } ]; diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php index aa8153b22..afcd3306f 100644 --- a/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php +++ b/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php @@ -25,7 +25,7 @@ return [ $schema->table('email_tokens', function (Blueprint $table) { $table->renameColumn('token', 'id'); - $table->dropForeign('email_tokens_user_id_foreign'); + $table->dropForeign(['user_id']); }); } ]; diff --git a/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php b/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php index aa3e739e6..01f2e34d6 100644 --- a/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php +++ b/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php @@ -49,7 +49,7 @@ return [ $table->boolean('is_read'); $table->boolean('is_deleted'); - $table->dropForeign('notifications_user_id_foreign'); + $table->dropForeign(['user_id']); }); $schema->getConnection()->table('notifications') diff --git a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php index 2ac9c1af0..bc7d57271 100644 --- a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php +++ b/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php @@ -42,8 +42,8 @@ return [ $table->mediumText('content')->change(); $table->dropForeign([ - 'posts_user_id_foreign', 'posts_discussion_id_foreign', - 'posts_edited_user_id_foreign', 'posts_hidden_user_id_foreign' + 'user_id', 'discussion_id', + 'edited_user_id', 'hidden_user_id' ]); }); } diff --git a/framework/core/migrations/2018_07_19_101300_constraints_group_user.php b/framework/core/migrations/2018_07_19_101300_constraints_group_user.php index 1f2b60564..9f11a9f2a 100644 --- a/framework/core/migrations/2018_07_19_101300_constraints_group_user.php +++ b/framework/core/migrations/2018_07_19_101300_constraints_group_user.php @@ -22,7 +22,7 @@ return [ 'down' => function (Builder $schema) { $schema->table('group_user', function (Blueprint $table) { - $table->dropForeign(['group_user_user_id_foreign', 'group_user_group_id_foreign']); + $table->dropForeign(['user_id', 'group_id']); }); } ]; diff --git a/framework/core/migrations/2018_07_19_101301_constraints_group_permission.php b/framework/core/migrations/2018_07_19_101301_constraints_group_permission.php index 4ed7a3a85..0f3092f64 100644 --- a/framework/core/migrations/2018_07_19_101301_constraints_group_permission.php +++ b/framework/core/migrations/2018_07_19_101301_constraints_group_permission.php @@ -21,7 +21,7 @@ return [ 'down' => function (Builder $schema) { $schema->table('group_permission', function (Blueprint $table) { - $table->dropForeign('group_permission_group_id_foreign'); + $table->dropForeign(['group_id']); }); } ]; diff --git a/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php b/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php index d4b5e530d..b5f499f87 100644 --- a/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php +++ b/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php @@ -21,7 +21,7 @@ return [ 'down' => function (Builder $schema) { $schema->table('password_tokens', function (Blueprint $table) { - $table->dropForeign('password_tokens_user_id_foreign'); + $table->dropForeign(['user_id']); }); } ]; From 33973fdb78c81bbf96bfeffe62e5053d1b3de9b3 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 15:23:37 +0930 Subject: [PATCH 28/85] Clean up migrations * Make filenames and order more consistent * Split foreign keys into their own migrations, add statements to ensure data integrity prior to adding them * Add renameColumns helper, use other helpers where possible --- ...1_093900_change_access_tokens_columns.php} | 16 ++++-- ...change_access_tokens_add_foreign_keys.php} | 13 ++++- ...94900_change_api_keys_rename_id_to_key.php | 29 ---------- ..._01_11_095000_change_api_keys_columns.php} | 12 ++++ ...registration_tokens_rename_id_to_token.php | 17 +----- ...1_155200_change_discussions_b8_columns.php | 56 ------------------- ...5200_change_discussions_rename_columns.php | 25 +++++++++ ...00_change_discussions_add_foreign_keys.php | 53 ++++++++++++++++++ ..._users_discussions_to_discussion_user.php} | 2 +- ..._change_discussion_user_rename_columns.php | 17 ++++++ ...00_change_discussions_users_b8_columns.php | 34 ----------- ...hange_discussion_user_add_foreign_keys.php | 40 +++++++++++++ ...change_email_tokens_rename_id_to_token.php | 14 +++++ ..._change_email_tokens_add_foreign_keys.php} | 13 +++-- ...ename_permissions_to_group_permission.php} | 0 ...nge_group_permission_add_foreign_keys.php} | 9 +++ ...600_rename_users_groups_to_group_user.php} | 0 ...00_change_group_user_add_foreign_keys.php} | 12 ++++ ...132900_create_notifications_from_table.php | 23 +++----- ...8_132901_seed_notifications_from_table.php | 21 ++++--- ...8_133000_change_notifications_columns.php} | 5 +- ..._change_notifications_add_foreign_keys.php | 36 ++++++++++++ ...ange_password_tokens_add_foreign_keys.php} | 9 +++ ..._18_135000_change_posts_rename_columns.php | 20 +++++++ ..._135100_change_posts_add_foreign_keys.php} | 35 ++++++------ ...18_01_30_220100_create_post_user_table.php | 26 +++++++++ ..._01_30_220100_create_posts_users_table.php | 29 ---------- ...8_01_30_222900_change_users_b8_columns.php | 41 -------------- ..._30_222900_change_users_rename_columns.php | 23 ++++++++ ...18_01_30_223700_create_user_user_table.php | 24 ++++++++ ..._01_30_223700_create_users_users_table.php | 29 ---------- framework/core/src/Database/Migration.php | 24 ++++++-- 32 files changed, 412 insertions(+), 295 deletions(-) rename framework/core/migrations/{2018_01_11_093900_change_access_tokens_b8_columns.php => 2018_01_11_093900_change_access_tokens_columns.php} (67%) rename framework/core/migrations/{2018_01_11_094800_change_access_tokens_make_activity_at_column_datetime.php => 2018_01_11_094000_change_access_tokens_add_foreign_keys.php} (53%) delete mode 100644 framework/core/migrations/2018_01_11_094900_change_api_keys_rename_id_to_key.php rename framework/core/migrations/{2018_01_11_095000_change_api_keys_b8_columns.php => 2018_01_11_095000_change_api_keys_columns.php} (73%) delete mode 100644 framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php create mode 100644 framework/core/migrations/2018_01_11_155200_change_discussions_rename_columns.php create mode 100644 framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php rename framework/core/migrations/{2018_01_15_071700_change_user_discussions_discussions_users.php => 2018_01_15_071700_rename_users_discussions_to_discussion_user.php} (77%) create mode 100644 framework/core/migrations/2018_01_15_071800_change_discussion_user_rename_columns.php delete mode 100644 framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php create mode 100644 framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php create mode 100644 framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php rename framework/core/migrations/{2018_01_15_072600_change_email_tokens_b8_columns.php => 2018_01_15_072700_change_email_tokens_add_foreign_keys.php} (66%) rename framework/core/migrations/{2018_01_18_130400_rename_permissions_to_groups_permissions.php => 2018_01_18_130400_rename_permissions_to_group_permission.php} (100%) rename framework/core/migrations/{2018_07_19_101301_constraints_group_permission.php => 2018_01_18_130500_change_group_permission_add_foreign_keys.php} (66%) rename framework/core/migrations/{2018_01_18_130400_rename_users_groups_to_group_user.php => 2018_01_18_130600_rename_users_groups_to_group_user.php} (100%) rename framework/core/migrations/{2018_07_19_101300_constraints_group_user.php => 2018_01_18_130700_change_group_user_add_foreign_keys.php} (61%) rename framework/core/migrations/{2018_01_18_133000_change_notifications_b8_columns.php => 2018_01_18_133000_change_notifications_columns.php} (93%) create mode 100644 framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php rename framework/core/migrations/{2018_07_19_101301_constraints_password_tokens.php => 2018_01_18_134500_change_password_tokens_add_foreign_keys.php} (65%) create mode 100644 framework/core/migrations/2018_01_18_135000_change_posts_rename_columns.php rename framework/core/migrations/{2018_01_18_135000_change_posts_b8_columns.php => 2018_01_18_135100_change_posts_add_foreign_keys.php} (57%) create mode 100644 framework/core/migrations/2018_01_30_220100_create_post_user_table.php delete mode 100644 framework/core/migrations/2018_01_30_220100_create_posts_users_table.php delete mode 100644 framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php create mode 100644 framework/core/migrations/2018_01_30_222900_change_users_rename_columns.php create mode 100644 framework/core/migrations/2018_01_30_223700_create_user_user_table.php delete mode 100644 framework/core/migrations/2018_01_30_223700_create_users_users_table.php diff --git a/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php b/framework/core/migrations/2018_01_11_093900_change_access_tokens_columns.php similarity index 67% rename from framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php rename to framework/core/migrations/2018_01_11_093900_change_access_tokens_columns.php index 4e4965d3b..a27bad442 100644 --- a/framework/core/migrations/2018_01_11_093900_change_access_tokens_b8_columns.php +++ b/framework/core/migrations/2018_01_11_093900_change_access_tokens_columns.php @@ -19,19 +19,27 @@ return [ $table->renameColumn('lifetime', 'lifetime_seconds'); $table->renameColumn('last_activity', 'last_activity_at'); $table->dateTime('created_at'); + $table->integer('user_id')->unsigned()->change(); + }); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + // Use a separate schema instance because this column gets renamed + // in the first one. + $schema->table('access_tokens', function (Blueprint $table) { + $table->dateTime('last_activity_at')->change(); }); }, 'down' => function (Builder $schema) { $schema->table('access_tokens', function (Blueprint $table) { + $table->integer('last_activity_at')->change(); + }); + + $schema->table('access_tokens', function (Blueprint $table) { + $table->renameColumn('token', 'id'); $table->renameColumn('lifetime_seconds', 'lifetime'); $table->renameColumn('last_activity_at', 'last_activity'); $table->dropColumn('created_at'); - $table->renameColumn('token', 'id'); - - $table->dropForeign(['user_id']); + $table->integer('user_id')->change(); }); } ]; diff --git a/framework/core/migrations/2018_01_11_094800_change_access_tokens_make_activity_at_column_datetime.php b/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php similarity index 53% rename from framework/core/migrations/2018_01_11_094800_change_access_tokens_make_activity_at_column_datetime.php rename to framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php index 3e555f1ca..b6125506d 100644 --- a/framework/core/migrations/2018_01_11_094800_change_access_tokens_make_activity_at_column_datetime.php +++ b/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php @@ -14,14 +14,23 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { + // Delete rows with non-existent users so that we will be able to create + // foreign keys without any issues. + $schema->getConnection() + ->table('access_tokens') + ->whereNotExists(function ($query) { + $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + }) + ->delete(); + $schema->table('access_tokens', function (Blueprint $table) { - $table->dateTime('last_activity_at')->change(); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); }, 'down' => function (Builder $schema) { $schema->table('access_tokens', function (Blueprint $table) { - $table->integer('last_activity_at')->change(); + $table->dropForeign(['user_id']); }); } ]; diff --git a/framework/core/migrations/2018_01_11_094900_change_api_keys_rename_id_to_key.php b/framework/core/migrations/2018_01_11_094900_change_api_keys_rename_id_to_key.php deleted file mode 100644 index 7135025a7..000000000 --- a/framework/core/migrations/2018_01_11_094900_change_api_keys_rename_id_to_key.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $schema->table('api_keys', function (Blueprint $table) { - $table->renameColumn('id', 'key'); - $table->dropPrimary(['id', 'key']); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('api_keys', function (Blueprint $table) { - $table->renameColumn('key', 'id'); - $table->primary('id'); - }); - } -]; diff --git a/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php b/framework/core/migrations/2018_01_11_095000_change_api_keys_columns.php similarity index 73% rename from framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php rename to framework/core/migrations/2018_01_11_095000_change_api_keys_columns.php index 478c578cf..eaa6246b4 100644 --- a/framework/core/migrations/2018_01_11_095000_change_api_keys_b8_columns.php +++ b/framework/core/migrations/2018_01_11_095000_change_api_keys_columns.php @@ -14,6 +14,12 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { + $schema->table('api_keys', function (Blueprint $table) { + $table->dropPrimary(['id']); + $table->renameColumn('id', 'key'); + $table->unique('key'); + }); + $schema->table('api_keys', function (Blueprint $table) { $table->increments('id'); $table->string('allowed_ips')->nullable(); @@ -31,5 +37,11 @@ return [ $table->dropForeign(['user_id']); $table->dropColumn('id', 'allowed_ips', 'user_id', 'scopes', 'created_at'); }); + + $schema->table('api_keys', function (Blueprint $table) { + $table->dropUnique(['key']); + $table->renameColumn('key', 'id'); + $table->primary('id'); + }); } ]; diff --git a/framework/core/migrations/2018_01_11_102000_change_registration_tokens_rename_id_to_token.php b/framework/core/migrations/2018_01_11_102000_change_registration_tokens_rename_id_to_token.php index 6a538622b..3a630513e 100644 --- a/framework/core/migrations/2018_01_11_102000_change_registration_tokens_rename_id_to_token.php +++ b/framework/core/migrations/2018_01_11_102000_change_registration_tokens_rename_id_to_token.php @@ -9,19 +9,6 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; +use Flarum\Database\Migration; -return [ - 'up' => function (Builder $schema) { - $schema->table('registration_tokens', function (Blueprint $table) { - $table->renameColumn('id', 'token'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('registration_tokens', function (Blueprint $table) { - $table->renameColumn('token', 'id'); - }); - } -]; +return Migration::renameColumn('registration_tokens', 'id', 'token'); diff --git a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php b/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php deleted file mode 100644 index 6485fdcab..000000000 --- a/framework/core/migrations/2018_01_11_155200_change_discussions_b8_columns.php +++ /dev/null @@ -1,56 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $schema->table('discussions', function (Blueprint $table) { - $table->renameColumn('comments_count', 'comment_count'); - $table->renameColumn('participants_count', 'participant_count'); - $table->renameColumn('number_index', 'post_number_index'); - $table->renameColumn('start_time', 'created_at'); - $table->renameColumn('start_user_id', 'user_id'); - $table->renameColumn('start_post_id', 'first_post_id'); - $table->renameColumn('last_time', 'last_posted_at'); - $table->renameColumn('last_user_id', 'last_posted_user_id'); - $table->renameColumn('hide_time', 'hidden_at'); - $table->renameColumn('hide_user_id', 'hidden_user_id'); - - $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'); - $table->foreign('first_post_id')->references('id')->on('posts'); - $table->foreign('last_post_id')->references('id')->on('posts'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('discussions', function (Blueprint $table) { - $table->renameColumn('comment_count', 'comments_count'); - $table->renameColumn('participant_count', 'participants_count'); - $table->renameColumn('post_number_index', 'number_index'); - $table->renameColumn('created_at', 'start_time'); - $table->renameColumn('user_id', 'start_user_id'); - $table->renameColumn('first_post_id', 'start_post_id'); - $table->renameColumn('last_posted_at', 'last_time'); - $table->renameColumn('last_posted_user_id', 'last_user_id'); - $table->renameColumn('hidden_at', 'hide_time'); - $table->renameColumn('hidden_user_id', 'hide_user_id'); - - $table->dropForeign([ - 'user_id', 'last_posted_user_id', 'hidden_user_id', - 'first_post_id', 'last_post_id' - ]); - }); - } -]; diff --git a/framework/core/migrations/2018_01_11_155200_change_discussions_rename_columns.php b/framework/core/migrations/2018_01_11_155200_change_discussions_rename_columns.php new file mode 100644 index 000000000..3d4e7467d --- /dev/null +++ b/framework/core/migrations/2018_01_11_155200_change_discussions_rename_columns.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameColumns('discussions', [ + 'comments_count' => 'comment_count', + 'participants_count' => 'participant_count', + 'number_index' => 'post_number_index', + 'start_time' => 'created_at', + 'start_user_id' => 'user_id', + 'start_post_id' => 'first_post_id', + 'last_time' => 'last_posted_at', + 'last_user_id' => 'last_posted_user_id', + 'hide_time' => 'hidden_at', + 'hide_user_id' => 'hidden_user_id' +]); diff --git a/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php b/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php new file mode 100644 index 000000000..6cf2adc44 --- /dev/null +++ b/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Query\Expression; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + // Set non-existent entity IDs to NULL so that we will be able to create + // foreign keys without any issues. + $connection = $schema->getConnection(); + + $selectId = function ($table, $column) use ($connection) { + return new Expression( + '('.$connection->table($table)->whereRaw("id = $column")->select('id')->toSql().')' + ); + }; + + $connection->table('discussions')->update([ + 'user_id' => $selectId('users', 'user_id'), + 'last_posted_user_id' => $selectId('users', 'last_posted_user_id'), + 'hidden_user_id' => $selectId('users', 'hidden_user_id'), + 'first_post_id' => $selectId('posts', 'first_post_id'), + 'last_post_id' => $selectId('posts', 'last_post_id'), + ]); + + $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'); + $table->foreign('first_post_id')->references('id')->on('posts'); + $table->foreign('last_post_id')->references('id')->on('posts'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('discussions', function (Blueprint $table) { + $table->dropForeign([ + 'user_id', 'last_posted_user_id', 'hidden_user_id', + 'first_post_id', 'last_post_id' + ]); + }); + } +]; diff --git a/framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php b/framework/core/migrations/2018_01_15_071700_rename_users_discussions_to_discussion_user.php similarity index 77% rename from framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php rename to framework/core/migrations/2018_01_15_071700_rename_users_discussions_to_discussion_user.php index e1ac5e026..eaa51709d 100644 --- a/framework/core/migrations/2018_01_15_071700_change_user_discussions_discussions_users.php +++ b/framework/core/migrations/2018_01_15_071700_rename_users_discussions_to_discussion_user.php @@ -11,4 +11,4 @@ use Flarum\Database\Migration; -return Migration::renameTable('users_discussions', 'discussions_users'); +return Migration::renameTable('users_discussions', 'discussion_user'); diff --git a/framework/core/migrations/2018_01_15_071800_change_discussion_user_rename_columns.php b/framework/core/migrations/2018_01_15_071800_change_discussion_user_rename_columns.php new file mode 100644 index 000000000..5fff7ea1e --- /dev/null +++ b/framework/core/migrations/2018_01_15_071800_change_discussion_user_rename_columns.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameColumns('discussion_user', [ + 'read_time' => 'last_read_at', + 'read_number' => 'last_read_post_number' +]); diff --git a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php b/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php deleted file mode 100644 index a0176f29d..000000000 --- a/framework/core/migrations/2018_01_15_071800_change_discussions_users_b8_columns.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $schema->table('discussions_users', function (Blueprint $table) { - $table->renameColumn('read_time', 'last_read_at'); - $table->renameColumn('read_number', 'last_read_post_number'); - - $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('discussions_users', function (Blueprint $table) { - $table->renameColumn('last_read_at', 'read_time'); - $table->renameColumn('last_read_post_number', 'read_number'); - - $table->dropForeign(['users_user_id', 'users_discussion_id']); - }); - } -]; diff --git a/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php b/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php new file mode 100644 index 000000000..4a9d69a07 --- /dev/null +++ b/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + // Delete rows with non-existent entities so that we will be able to create + // foreign keys without any issues. + $connection = $schema->getConnection(); + $connection->table('discussion_user') + ->whereNotExists(function ($query) { + $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + }) + ->orWhereNotExists(function ($query) { + $query->selectRaw(1)->from('discussions')->whereRaw('id = discussion_id'); + }) + ->delete(); + + $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) { + $table->dropForeign(['user_id', 'discussion_id']); + }); + } +]; diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php b/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php new file mode 100644 index 000000000..64586a4aa --- /dev/null +++ b/framework/core/migrations/2018_01_15_072600_change_email_tokens_rename_id_to_token.php @@ -0,0 +1,14 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameColumn('email_tokens', 'id', 'token'); diff --git a/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php b/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php similarity index 66% rename from framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php rename to framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php index afcd3306f..c840045e6 100644 --- a/framework/core/migrations/2018_01_15_072600_change_email_tokens_b8_columns.php +++ b/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php @@ -14,17 +14,22 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('email_tokens', function (Blueprint $table) { - $table->renameColumn('id', 'token'); + // Delete rows with non-existent users so that we will be able to create + // foreign keys without any issues. + $schema->getConnection() + ->table('email_tokens') + ->whereNotExists(function ($query) { + $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + }) + ->delete(); + $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) { - $table->renameColumn('token', 'id'); - $table->dropForeign(['user_id']); }); } diff --git a/framework/core/migrations/2018_01_18_130400_rename_permissions_to_groups_permissions.php b/framework/core/migrations/2018_01_18_130400_rename_permissions_to_group_permission.php similarity index 100% rename from framework/core/migrations/2018_01_18_130400_rename_permissions_to_groups_permissions.php rename to framework/core/migrations/2018_01_18_130400_rename_permissions_to_group_permission.php diff --git a/framework/core/migrations/2018_07_19_101301_constraints_group_permission.php b/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php similarity index 66% rename from framework/core/migrations/2018_07_19_101301_constraints_group_permission.php rename to framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php index 0f3092f64..f783547a6 100644 --- a/framework/core/migrations/2018_07_19_101301_constraints_group_permission.php +++ b/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php @@ -14,6 +14,15 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { + // Delete rows with non-existent groups so that we will be able to create + // foreign keys without any issues. + $schema->getConnection() + ->table('group_permission') + ->whereNotExists(function ($query) { + $query->selectRaw(1)->from('groups')->whereRaw('id = group_id'); + }) + ->delete(); + $schema->table('group_permission', function (Blueprint $table) { $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); }); diff --git a/framework/core/migrations/2018_01_18_130400_rename_users_groups_to_group_user.php b/framework/core/migrations/2018_01_18_130600_rename_users_groups_to_group_user.php similarity index 100% rename from framework/core/migrations/2018_01_18_130400_rename_users_groups_to_group_user.php rename to framework/core/migrations/2018_01_18_130600_rename_users_groups_to_group_user.php diff --git a/framework/core/migrations/2018_07_19_101300_constraints_group_user.php b/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php similarity index 61% rename from framework/core/migrations/2018_07_19_101300_constraints_group_user.php rename to framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php index 9f11a9f2a..028b35e94 100644 --- a/framework/core/migrations/2018_07_19_101300_constraints_group_user.php +++ b/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php @@ -14,6 +14,18 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { + // Delete rows with non-existent entities so that we will be able to create + // foreign keys without any issues. + $schema->getConnection() + ->table('group_user') + ->whereNotExists(function ($query) { + $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + }) + ->orWhereNotExists(function ($query) { + $query->selectRaw(1)->from('groups')->whereRaw('id = group_id'); + }) + ->delete(); + $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'); diff --git a/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php b/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php index 63fa38c8b..9ee23e2ed 100644 --- a/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php +++ b/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php @@ -9,21 +9,16 @@ * 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->create('notifications_from', function (Blueprint $table) { - $table->integer('id')->unsigned(); - $table->integer('from_user_id')->unsigned(); +return Migration::createTable( + 'notifications_from', + function (Blueprint $table) { + $table->integer('id')->unsigned(); + $table->integer('from_user_id')->unsigned(); - $table->foreign('id')->references('id')->on('notifications')->onDelete('cascade'); - $table->foreign('from_user_id')->references('id')->on('users')->onDelete('cascade'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('notifications_from'); + $table->foreign('id')->references('id')->on('notifications')->onDelete('cascade'); + $table->foreign('from_user_id')->references('id')->on('users')->onDelete('cascade'); } -]; +); diff --git a/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php b/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php index c12fd4c22..c58ba7df2 100644 --- a/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php +++ b/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php @@ -13,16 +13,19 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->getConnection()->table('notifications')->chunkById(100, function ($notifications) use ($schema) { - foreach ($notifications as $notification) { - $insert = [ - 'id' => $notification->id, - 'from_user_id' => $notification->sender_id - ]; + $query = $schema->getConnection()->table('notifications') + ->whereExists(function ($query) { + $query->selectRaw(1)->from('users')->whereRaw('id = sender_id'); + }); - $schema->getConnection()->table('notifications_from')->updateOrInsert($insert, $insert); - } - }); + foreach ($query->cursor() as $notification) { + $insert = [ + 'id' => $notification->id, + 'from_user_id' => $notification->sender_id + ]; + + $schema->getConnection()->table('notifications_from')->updateOrInsert($insert, $insert); + } }, 'down' => function (Builder $schema) { diff --git a/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php b/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php similarity index 93% rename from framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php rename to framework/core/migrations/2018_01_18_133000_change_notifications_columns.php index 01f2e34d6..963844b02 100644 --- a/framework/core/migrations/2018_01_18_133000_change_notifications_b8_columns.php +++ b/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php @@ -21,8 +21,6 @@ return [ $table->timestamp('read_at')->nullable(); $table->timestamp('deleted_at')->nullable(); - - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); $schema->getConnection()->table('notifications') @@ -48,13 +46,12 @@ return [ $table->boolean('is_read'); $table->boolean('is_deleted'); - - $table->dropForeign(['user_id']); }); $schema->getConnection()->table('notifications') ->whereNotNull('read_at') ->update(['is_read' => 1]); + $schema->getConnection()->table('notifications') ->whereNotNull('deleted_at') ->update(['is_deleted' => 1]); diff --git a/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php b/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php new file mode 100644 index 000000000..c71327d10 --- /dev/null +++ b/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + // Delete rows with non-existent users so that we will be able to create + // foreign keys without any issues. + $schema->getConnection() + ->table('notifications') + ->whereNotExists(function ($query) { + $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + }) + ->delete(); + + $schema->table('notifications', function (Blueprint $table) { + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('notifications', function (Blueprint $table) { + $table->dropForeign(['user_id']); + }); + } +]; diff --git a/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php b/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php similarity index 65% rename from framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php rename to framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php index b5f499f87..7e3c3c6d4 100644 --- a/framework/core/migrations/2018_07_19_101301_constraints_password_tokens.php +++ b/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php @@ -14,6 +14,15 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { + // Delete rows with non-existent users so that we will be able to create + // foreign keys without any issues. + $connection = $schema->getConnection(); + $connection->table('password_tokens') + ->whereNotExists(function ($query) { + $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + }) + ->delete(); + $schema->table('password_tokens', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); diff --git a/framework/core/migrations/2018_01_18_135000_change_posts_rename_columns.php b/framework/core/migrations/2018_01_18_135000_change_posts_rename_columns.php new file mode 100644 index 000000000..701c58aa1 --- /dev/null +++ b/framework/core/migrations/2018_01_18_135000_change_posts_rename_columns.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameColumns('posts', [ + 'time' => 'created_at', + 'edit_time' => 'edited_at', + 'hide_time' => 'hidden_at', + 'edit_user_id' => 'edited_user_id', + 'hide_user_id' => 'hidden_user_id' +]); diff --git a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php b/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php similarity index 57% rename from framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php rename to framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php index bc7d57271..2a0623052 100644 --- a/framework/core/migrations/2018_01_18_135000_change_posts_b8_columns.php +++ b/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php @@ -9,21 +9,29 @@ * file that was distributed with this source code. */ +use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { + // Set non-existent entity IDs to NULL so that we will be able to create + // foreign keys without any issues. + $connection = $schema->getConnection(); + + $selectId = function ($table, $column) use ($connection) { + return new Expression( + '('.$connection->table($table)->whereRaw("id = $column")->select('id')->toSql().')' + ); + }; + + $connection->table('posts')->update([ + 'user_id' => $selectId('users', 'user_id'), + 'edited_user_id' => $selectId('users', 'edited_user_id'), + 'hidden_user_id' => $selectId('users', 'hidden_user_id'), + ]); + $schema->table('posts', function (Blueprint $table) { - $table->renameColumn('time', 'created_at'); - $table->renameColumn('edit_time', 'edited_at'); - $table->renameColumn('hide_time', 'hidden_at'); - - $table->renameColumn('edit_user_id', 'edited_user_id'); - $table->renameColumn('hide_user_id', 'hidden_user_id'); - - $table->longText('content')->change(); - $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'); @@ -32,15 +40,6 @@ return [ 'down' => function (Builder $schema) { $schema->table('posts', function (Blueprint $table) { - $table->renameColumn('created_at', 'time'); - $table->renameColumn('edited_at', 'edit_time'); - $table->renameColumn('hidden_at', 'hide_time'); - - $table->renameColumn('edited_user_id', 'edit_user_id'); - $table->renameColumn('edited_user_id', 'hidden_user_id'); - - $table->mediumText('content')->change(); - $table->dropForeign([ 'user_id', 'discussion_id', 'edited_user_id', 'hidden_user_id' diff --git a/framework/core/migrations/2018_01_30_220100_create_post_user_table.php b/framework/core/migrations/2018_01_30_220100_create_post_user_table.php new file mode 100644 index 000000000..577ce3511 --- /dev/null +++ b/framework/core/migrations/2018_01_30_220100_create_post_user_table.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; +use Illuminate\Database\Schema\Blueprint; + +return Migration::createTable( + 'post_user', + function (Blueprint $table) { + $table->integer('post_id')->unsigned(); + $table->integer('user_id')->unsigned(); + + $table->primary(['post_id', 'user_id']); + + $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } +); diff --git a/framework/core/migrations/2018_01_30_220100_create_posts_users_table.php b/framework/core/migrations/2018_01_30_220100_create_posts_users_table.php deleted file mode 100644 index ba1d3e952..000000000 --- a/framework/core/migrations/2018_01_30_220100_create_posts_users_table.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $schema->create('posts_users', function (Blueprint $table) { - $table->integer('post_id')->unsigned(); - $table->integer('user_id')->unsigned(); - - $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('posts_users'); - } -]; diff --git a/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php b/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php deleted file mode 100644 index e7bb77c9e..000000000 --- a/framework/core/migrations/2018_01_30_222900_change_users_b8_columns.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $schema->table('users', function (Blueprint $table) { - $table->renameColumn('is_activated', 'is_email_confirmed'); - $table->renameColumn('join_time', 'joined_at'); - $table->renameColumn('last_seen_time', 'last_seen_at'); - $table->renameColumn('discussions_count', 'discussion_count'); - $table->renameColumn('comments_count', 'comment_count'); - $table->renameColumn('read_time', 'marked_all_as_read_at'); - $table->renameColumn('notifications_read_time', 'read_notifications_at'); - $table->renameColumn('avatar_path', 'avatar_url'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('users', function (Blueprint $table) { - $table->renameColumn('is_email_confirmed', 'is_activated'); - $table->renameColumn('joined_at', 'join_time'); - $table->renameColumn('last_seen_at', 'last_seen_time'); - $table->renameColumn('discussion_count', 'discussions_count'); - $table->renameColumn('comment_count', 'comments_count'); - $table->renameColumn('marked_all_as_read_at', 'read_time'); - $table->renameColumn('read_notifications_at', 'notifications_read_time'); - $table->renameColumn('avatar_url', 'avatar_path'); - }); - } -]; diff --git a/framework/core/migrations/2018_01_30_222900_change_users_rename_columns.php b/framework/core/migrations/2018_01_30_222900_change_users_rename_columns.php new file mode 100644 index 000000000..4b6965bde --- /dev/null +++ b/framework/core/migrations/2018_01_30_222900_change_users_rename_columns.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; + +return Migration::renameColumns('users', [ + 'is_activated' => 'is_email_confirmed', + 'join_time' => 'joined_at', + 'last_seen_time' => 'last_seen_at', + 'discussions_count' => 'discussion_count', + 'comments_count' => 'comment_count', + 'read_time' => 'marked_all_as_read_at', + 'notifications_read_time' => 'read_notifications_at', + 'avatar_path' => 'avatar_url' +]); diff --git a/framework/core/migrations/2018_01_30_223700_create_user_user_table.php b/framework/core/migrations/2018_01_30_223700_create_user_user_table.php new file mode 100644 index 000000000..60c845ff6 --- /dev/null +++ b/framework/core/migrations/2018_01_30_223700_create_user_user_table.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Database\Migration; +use Illuminate\Database\Schema\Blueprint; + +return Migration::createTable( + 'user_user', + function (Blueprint $table) { + $table->integer('user_id')->unsigned(); + $table->integer('other_user_id')->unsigned(); + + $table->foreign('user_id')->references('id')->on('posts')->onDelete('cascade'); + $table->foreign('other_user_id')->references('id')->on('users')->onDelete('cascade'); + } +); diff --git a/framework/core/migrations/2018_01_30_223700_create_users_users_table.php b/framework/core/migrations/2018_01_30_223700_create_users_users_table.php deleted file mode 100644 index ed74651c1..000000000 --- a/framework/core/migrations/2018_01_30_223700_create_users_users_table.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $schema->create('users_users', function (Blueprint $table) { - $table->integer('user_id')->unsigned(); - $table->integer('other_user_id')->unsigned(); - - $table->foreign('user_id')->references('id')->on('posts')->onDelete('cascade'); - $table->foreign('other_user_id')->references('id')->on('users')->onDelete('cascade'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('users_users'); - } -]; diff --git a/framework/core/src/Database/Migration.php b/framework/core/src/Database/Migration.php index 79332813d..6469b847f 100644 --- a/framework/core/src/Database/Migration.php +++ b/framework/core/src/Database/Migration.php @@ -78,16 +78,28 @@ abstract class Migration * Rename a column. */ public static function renameColumn($tableName, $from, $to) + { + return static::renameColumns($tableName, [$from => $to]); + } + + /** + * Rename multiple columns. + */ + public static function renameColumns($tableName, array $columnNames) { return [ - 'up' => function (Builder $schema) use ($tableName, $from, $to) { - $schema->table($tableName, function (Blueprint $table) use ($from, $to) { - $table->renameColumn($from, $to); + 'up' => function (Builder $schema) use ($tableName, $columnNames) { + $schema->table($tableName, function (Blueprint $table) use ($columnNames) { + foreach ($columnNames as $from => $to) { + $table->renameColumn($from, $to); + } }); }, - 'down' => function (Builder $schema) use ($tableName, $from, $to) { - $schema->table($tableName, function (Blueprint $table) use ($from, $to) { - $table->renameColumn($to, $from); + 'down' => function (Builder $schema) use ($tableName, $columnNames) { + $schema->table($tableName, function (Blueprint $table) use ($columnNames) { + foreach ($columnNames as $to => $from) { + $table->renameColumn($from, $to); + } }); } ]; From 5443dc7ce2c10275ee2f8ac7cca428a8df8cc21e Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 15:24:33 +0930 Subject: [PATCH 29/85] Fix table name --- framework/core/src/Discussion/UserState.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Discussion/UserState.php b/framework/core/src/Discussion/UserState.php index 4840b00b7..221663099 100644 --- a/framework/core/src/Discussion/UserState.php +++ b/framework/core/src/Discussion/UserState.php @@ -39,7 +39,7 @@ class UserState extends AbstractModel /** * {@inheritdoc} */ - protected $table = 'discussions_users'; + protected $table = 'discussion_user'; /** * {@inheritdoc} @@ -72,7 +72,7 @@ class UserState extends AbstractModel */ public function discussion() { - return $this->belongsTo(Discussion::class, 'discussion_id'); + return $this->belongsTo(Discussion::class); } /** @@ -82,7 +82,7 @@ class UserState extends AbstractModel */ public function user() { - return $this->belongsTo(User::class, 'user_id'); + return $this->belongsTo(User::class); } /** From cd31f11b6432dfc4d23c2e1faa1f077506b7989e Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 15:24:51 +0930 Subject: [PATCH 30/85] Fix column names --- framework/core/src/Discussion/Discussion.php | 2 +- framework/core/src/Notification/NotificationRepository.php | 2 +- framework/core/src/Post/PostRepository.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 1b1bfc194..e73be2dad 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -380,7 +380,7 @@ class Discussion extends AbstractModel */ public function lastUser() { - return $this->belongsTo(User::class, 'last_user_id'); + return $this->belongsTo(User::class, 'last_posted_user_id'); } /** diff --git a/framework/core/src/Notification/NotificationRepository.php b/framework/core/src/Notification/NotificationRepository.php index 57ed3b02a..629fe8792 100644 --- a/framework/core/src/Notification/NotificationRepository.php +++ b/framework/core/src/Notification/NotificationRepository.php @@ -34,7 +34,7 @@ class NotificationRepository ->whereIn('type', $user->getAlertableNotificationTypes()) ->whereNull('deleted_at') ->groupBy('type', 'subject_id') - ->orderByRaw('MAX(time) DESC') + ->orderByRaw('MAX(created_at) DESC') ->skip($offset) ->take($limit); diff --git a/framework/core/src/Post/PostRepository.php b/framework/core/src/Post/PostRepository.php index 8213be5e8..f6ed861c5 100644 --- a/framework/core/src/Post/PostRepository.php +++ b/framework/core/src/Post/PostRepository.php @@ -136,8 +136,8 @@ class PostRepository $query = Discussion::find($discussionId) ->posts() ->whereVisibleTo($actor) - ->where('time', '<', function ($query) use ($discussionId, $number) { - $query->select('time') + ->where('created_at', '<', function ($query) use ($discussionId, $number) { + $query->select('created_at') ->from('posts') ->where('discussion_id', $discussionId) ->whereNotNull('number') From a44d4bfef35b4f2137b58338941c6b4456e0e16d Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 15:26:12 +0930 Subject: [PATCH 31/85] Fix to ensure we can rename columns in tables with enums See https://github.com/laravel/framework/issues/1186 --- framework/core/src/Database/Migrator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/framework/core/src/Database/Migrator.php b/framework/core/src/Database/Migrator.php index 2c1272fc0..8d411887c 100644 --- a/framework/core/src/Database/Migrator.php +++ b/framework/core/src/Database/Migrator.php @@ -63,6 +63,9 @@ class Migrator $this->repository = $repository; $this->schemaBuilder = $connection->getSchemaBuilder(); + + // Workaround for https://github.com/laravel/framework/issues/1186 + $connection->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); } /** From 6b6e8827700524a14297fff1faa728cef2224b62 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:06:42 +0930 Subject: [PATCH 32/85] Clean up Eloquent definitions --- framework/core/src/Api/ApiKey.php | 20 +++++++------------ framework/core/src/Discussion/Discussion.php | 11 ++++------ framework/core/src/Discussion/UserState.php | 4 +++- framework/core/src/Group/Group.php | 5 ----- framework/core/src/Group/Permission.php | 2 +- framework/core/src/Http/AccessToken.php | 5 ----- .../core/src/Notification/Notification.php | 9 +++------ framework/core/src/Post/Post.php | 17 ++++++++-------- framework/core/src/User/AuthToken.php | 4 +++- framework/core/src/User/EmailToken.php | 14 +++++++------ framework/core/src/User/PasswordToken.php | 9 +++------ framework/core/src/User/User.php | 9 +++------ 12 files changed, 43 insertions(+), 66 deletions(-) diff --git a/framework/core/src/Api/ApiKey.php b/framework/core/src/Api/ApiKey.php index baae2c01e..ffd8d591c 100644 --- a/framework/core/src/Api/ApiKey.php +++ b/framework/core/src/Api/ApiKey.php @@ -14,22 +14,16 @@ namespace Flarum\Api; use Flarum\Database\AbstractModel; /** - * @property string $id + * @property int $id + * @property string $key + * @property string|null $allowed_ips + * @property string|null $scopes + * @property int|null $user_id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon|null $last_activity_at */ class ApiKey extends AbstractModel { - /** - * {@inheritdoc} - */ - protected $table = 'api_keys'; - - /** - * Use a custom primary key for this model. - * - * @var bool - */ - public $incrementing = false; - /** * Generate an API key. * diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index e73be2dad..cfad12d27 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -59,11 +59,6 @@ class Discussion extends AbstractModel use EventGeneratorTrait; use ScopeVisibilityTrait; - /** - * {@inheritdoc} - */ - protected $table = 'discussions'; - /** * An array of posts that have been modified during this request. * @@ -72,12 +67,14 @@ class Discussion extends AbstractModel protected $modifiedPosts = []; /** - * {@inheritdoc} + * The attributes that should be mutated to dates. + * + * @var array */ protected $dates = ['created_at', 'last_posted_at', 'hidden_at']; /** - * Casts properties to a specific type. + * The attributes that should be cast to native types. * * @var array */ diff --git a/framework/core/src/Discussion/UserState.php b/framework/core/src/Discussion/UserState.php index 221663099..ee856cff5 100644 --- a/framework/core/src/Discussion/UserState.php +++ b/framework/core/src/Discussion/UserState.php @@ -42,7 +42,9 @@ class UserState extends AbstractModel protected $table = 'discussion_user'; /** - * {@inheritdoc} + * The attributes that should be mutated to dates. + * + * @var array */ protected $dates = ['last_read_at']; diff --git a/framework/core/src/Group/Group.php b/framework/core/src/Group/Group.php index 0ce9741a2..19f1b19fd 100644 --- a/framework/core/src/Group/Group.php +++ b/framework/core/src/Group/Group.php @@ -33,11 +33,6 @@ class Group extends AbstractModel use EventGeneratorTrait; use ScopeVisibilityTrait; - /** - * {@inheritdoc} - */ - protected $table = 'groups'; - /** * The ID of the administrator group. */ diff --git a/framework/core/src/Group/Permission.php b/framework/core/src/Group/Permission.php index e5e4d872f..745022567 100644 --- a/framework/core/src/Group/Permission.php +++ b/framework/core/src/Group/Permission.php @@ -32,7 +32,7 @@ class Permission extends AbstractModel */ public function group() { - return $this->belongsTo(Group::class, 'group_id'); + return $this->belongsTo(Group::class); } /** diff --git a/framework/core/src/Http/AccessToken.php b/framework/core/src/Http/AccessToken.php index cd0c6aea4..f3d573710 100644 --- a/framework/core/src/Http/AccessToken.php +++ b/framework/core/src/Http/AccessToken.php @@ -24,11 +24,6 @@ use Flarum\User\User; */ class AccessToken extends AbstractModel { - /** - * {@inheritdoc} - */ - protected $table = 'access_tokens'; - /** * Use a custom primary key for this model. * diff --git a/framework/core/src/Notification/Notification.php b/framework/core/src/Notification/Notification.php index 6a87ad692..bbae7c4ff 100644 --- a/framework/core/src/Notification/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -45,12 +45,9 @@ use Flarum\User\User; class Notification extends AbstractModel { /** - * {@inheritdoc} - */ - protected $table = 'notifications'; - - /** - * {@inheritdoc} + * The attributes that should be mutated to dates. + * + * @var array */ protected $dates = ['created_at', 'read_at', 'deleted_at']; diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php index e4df2b0ad..6f6a131bc 100644 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -43,18 +43,17 @@ class Post extends AbstractModel { use EventGeneratorTrait; - /** - * {@inheritdoc} - */ protected $table = 'posts'; /** - * {@inheritdoc} + * The attributes that should be mutated to dates. + * + * @var array */ protected $dates = ['created_at', 'edited_at', 'hidden_at']; /** - * Casts properties to a specific type. + * The attributes that should be cast to native types. * * @var array */ @@ -150,7 +149,7 @@ class Post extends AbstractModel */ public function discussion() { - return $this->belongsTo('Flarum\Discussion\Discussion', 'discussion_id'); + return $this->belongsTo(Discussion::class); } /** @@ -160,7 +159,7 @@ class Post extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\User\User', 'user_id'); + return $this->belongsTo(User::class); } /** @@ -170,7 +169,7 @@ class Post extends AbstractModel */ public function editUser() { - return $this->belongsTo('Flarum\User\User', 'edited_user_id'); + return $this->belongsTo(User::class, 'edited_user_id'); } /** @@ -180,7 +179,7 @@ class Post extends AbstractModel */ public function hideUser() { - return $this->belongsTo('Flarum\User\User', 'hidden_user_id'); + return $this->belongsTo(User::class, 'hidden_user_id'); } /** diff --git a/framework/core/src/User/AuthToken.php b/framework/core/src/User/AuthToken.php index d13fd4e3e..877cd7c24 100644 --- a/framework/core/src/User/AuthToken.php +++ b/framework/core/src/User/AuthToken.php @@ -28,7 +28,9 @@ class AuthToken extends AbstractModel protected $table = 'registration_tokens'; /** - * {@inheritdoc} + * The attributes that should be mutated to dates. + * + * @var array */ protected $dates = ['created_at']; diff --git a/framework/core/src/User/EmailToken.php b/framework/core/src/User/EmailToken.php index ab0f610a0..085efb101 100644 --- a/framework/core/src/User/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -24,12 +24,9 @@ use Flarum\User\Exception\InvalidConfirmationTokenException; class EmailToken extends AbstractModel { /** - * {@inheritdoc} - */ - protected $table = 'email_tokens'; - - /** - * {@inheritdoc} + * The attributes that should be mutated to dates. + * + * @var array */ protected $dates = ['created_at']; @@ -40,6 +37,11 @@ class EmailToken extends AbstractModel */ public $incrementing = false; + /** + * {@inheritdoc} + */ + protected $primaryKey = 'token'; + /** * Generate an email token for the specified user. * diff --git a/framework/core/src/User/PasswordToken.php b/framework/core/src/User/PasswordToken.php index cda750209..54c9694b0 100644 --- a/framework/core/src/User/PasswordToken.php +++ b/framework/core/src/User/PasswordToken.php @@ -22,12 +22,9 @@ use Flarum\Database\AbstractModel; class PasswordToken extends AbstractModel { /** - * {@inheritdoc} - */ - protected $table = 'password_tokens'; - - /** - * {@inheritdoc} + * The attributes that should be mutated to dates. + * + * @var array */ protected $dates = ['created_at']; diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 16bf9fb64..aad9c5f0b 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -60,12 +60,9 @@ class User extends AbstractModel use ScopeVisibilityTrait; /** - * {@inheritdoc} - */ - protected $table = 'users'; - - /** - * {@inheritdoc} + * The attributes that should be mutated to dates. + * + * @var array */ protected $dates = [ 'joined_at', From 15901fbf5ab05cda2e4fc7c9d443334612da8a01 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:08:11 +0930 Subject: [PATCH 33/85] Fix email confirmation links --- .../core/src/Api/Controller/SendConfirmationEmailController.php | 2 +- framework/core/src/User/EmailConfirmationMailer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Api/Controller/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index 54bde47db..91244dd01 100644 --- a/framework/core/src/Api/Controller/SendConfirmationEmailController.php +++ b/framework/core/src/Api/Controller/SendConfirmationEmailController.php @@ -81,7 +81,7 @@ class SendConfirmationEmailController implements RequestHandlerInterface $data = [ '{username}' => $actor->username, - '{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->id]), + '{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->token]), '{forum}' => $this->settings->get('forum_title') ]; diff --git a/framework/core/src/User/EmailConfirmationMailer.php b/framework/core/src/User/EmailConfirmationMailer.php index 642a641a3..0bf96c4c2 100644 --- a/framework/core/src/User/EmailConfirmationMailer.php +++ b/framework/core/src/User/EmailConfirmationMailer.php @@ -128,7 +128,7 @@ class EmailConfirmationMailer return [ '{username}' => $user->display_name, - '{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->id]), + '{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->token]), '{forum}' => $this->settings->get('forum_title') ]; } From 0c93e13ebd1c66d8913b61ca7f0dfac55509e5c2 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:10:02 +0930 Subject: [PATCH 34/85] Fix discussion and post list sorting --- framework/core/js/src/forum/components/DiscussionList.js | 8 ++++---- framework/core/js/src/forum/components/PostsUserPage.js | 2 +- framework/core/src/Api/Controller/ListPostsController.php | 4 ++-- framework/core/src/Forum/Controller/IndexController.php | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/framework/core/js/src/forum/components/DiscussionList.js b/framework/core/js/src/forum/components/DiscussionList.js index d393665bd..72fc707e0 100644 --- a/framework/core/js/src/forum/components/DiscussionList.js +++ b/framework/core/js/src/forum/components/DiscussionList.js @@ -112,10 +112,10 @@ export default class DiscussionList extends Component { if (this.props.params.q) { map.relevance = ''; } - map.latest = '-lastTime'; - map.top = '-commentsCount'; - map.newest = '-startTime'; - map.oldest = 'startTime'; + map.latest = '-lastPostedAt'; + map.top = '-commentCount'; + map.newest = '-createdAt'; + map.oldest = 'createdAt'; return map; } diff --git a/framework/core/js/src/forum/components/PostsUserPage.js b/framework/core/js/src/forum/components/PostsUserPage.js index ca48652ec..95b9ed73c 100644 --- a/framework/core/js/src/forum/components/PostsUserPage.js +++ b/framework/core/js/src/forum/components/PostsUserPage.js @@ -114,7 +114,7 @@ export default class PostsUserPage extends UserPage { type: 'comment' }, page: {offset, limit: this.loadLimit}, - sort: '-time' + sort: '-createdAt' }); } diff --git a/framework/core/src/Api/Controller/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index 4818b54e9..609839fa4 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -40,7 +40,7 @@ class ListPostsController extends AbstractListController /** * {@inheritdoc} */ - public $sortFields = ['time']; + public $sortFields = ['createdAt']; /** * @var \Flarum\Post\PostRepository @@ -120,7 +120,7 @@ class ListPostsController extends AbstractListController $query->skip($offset)->take($limit); foreach ((array) $sort as $field => $order) { - $query->orderBy($field, $order); + $query->orderBy(snake_case($field), $order); } return $query->pluck('id')->all(); diff --git a/framework/core/src/Forum/Controller/IndexController.php b/framework/core/src/Forum/Controller/IndexController.php index 028b716e7..544b68944 100644 --- a/framework/core/src/Forum/Controller/IndexController.php +++ b/framework/core/src/Forum/Controller/IndexController.php @@ -30,10 +30,10 @@ class IndexController extends FrontendController * @var array */ private $sortMap = [ - 'latest' => '-lastTime', - 'top' => '-commentsCount', - 'newest' => '-startTime', - 'oldest' => 'startTime' + 'latest' => '-lastPostedAt', + 'top' => '-commentCount', + 'newest' => '-createdAt', + 'oldest' => 'createdAt' ]; /** From 36b272d1835bed3493488e298c1629abcba75634 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:12:51 +0930 Subject: [PATCH 35/85] Change TIMESTAMP columns to DATETIME --- ...stration_tokens_created_at_to_datetime.php | 27 +++++++++++++++++++ ...ge_email_tokens_created_at_to_datetime.php | 27 +++++++++++++++++++ ...password_tokens_created_at_to_datetime.php | 27 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php create mode 100644 framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php create mode 100644 framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php diff --git a/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php b/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php new file mode 100644 index 000000000..7a5dc8cf6 --- /dev/null +++ b/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('registration_tokens', function (Blueprint $table) { + $table->dateTime('created_at')->change(); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('registration_tokens', function (Blueprint $table) { + $table->timestamp('created_at')->change(); + }); + } +]; diff --git a/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php b/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php new file mode 100644 index 000000000..7a4c8e218 --- /dev/null +++ b/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->dateTime('created_at')->change(); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('email_tokens', function (Blueprint $table) { + $table->timestamp('created_at')->change(); + }); + } +]; diff --git a/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php b/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php new file mode 100644 index 000000000..f552e9cf9 --- /dev/null +++ b/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $schema->table('password_tokens', function (Blueprint $table) { + $table->dateTime('created_at')->change(); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('password_tokens', function (Blueprint $table) { + $table->timestamp('created_at')->change(); + }); + } +]; From f52d5f2ccf01962124d9dce7dd5d911302a739e2 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:13:51 +0930 Subject: [PATCH 36/85] No need for deleted_at in notifications table --- ...1_18_133000_change_notifications_columns.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php b/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php index 963844b02..56fef9ec8 100644 --- a/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php +++ b/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php @@ -9,6 +9,7 @@ * file that was distributed with this source code. */ +use Carbon\Carbon; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -19,21 +20,15 @@ return [ $table->renameColumn('time', 'created_at'); - $table->timestamp('read_at')->nullable(); - $table->timestamp('deleted_at')->nullable(); + $table->dateTime('read_at')->nullable(); }); $schema->getConnection()->table('notifications') ->where('is_read', 1) - ->update(['read_at' => time()]); - - $schema->getConnection()->table('notifications') - ->where('is_deleted', 1) - ->update(['deleted_at' => time()]); + ->update(['read_at' => Carbon::now()]); $schema->table('notifications', function (Blueprint $table) { $table->dropColumn('is_read'); - $table->dropColumn('is_deleted'); }); }, @@ -45,20 +40,14 @@ return [ $table->renameColumn('created_at', 'time'); $table->boolean('is_read'); - $table->boolean('is_deleted'); }); $schema->getConnection()->table('notifications') ->whereNotNull('read_at') ->update(['is_read' => 1]); - $schema->getConnection()->table('notifications') - ->whereNotNull('deleted_at') - ->update(['is_deleted' => 1]); - $schema->table('notifications', function (Blueprint $table) { $table->dropColumn('read_at'); - $table->dropColumn('deleted_at'); }); } ]; From bcd74ff09bd81bb924931231ae9697425e65116a Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:14:15 +0930 Subject: [PATCH 37/85] Fix API key generation --- framework/core/src/Api/ApiKey.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Api/ApiKey.php b/framework/core/src/Api/ApiKey.php index ffd8d591c..e8ebb48ec 100644 --- a/framework/core/src/Api/ApiKey.php +++ b/framework/core/src/Api/ApiKey.php @@ -31,8 +31,10 @@ class ApiKey extends AbstractModel */ public static function generate() { - return new static([ - 'id' => str_random(40) - ]); + $key = new static; + + $key->key = str_random(40); + + return $key; } } From e8cd2d4111ce9b561485d8052a310f3bb5ddede8 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:18:40 +0930 Subject: [PATCH 38/85] Fix entity deletion Foreign keys take care of most of this for us! --- ...55300_change_discussions_add_foreign_keys.php | 4 ++-- framework/core/src/Discussion/Discussion.php | 15 --------------- framework/core/src/Group/Group.php | 2 -- framework/core/src/User/User.php | 16 ---------------- 4 files changed, 2 insertions(+), 35 deletions(-) diff --git a/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php b/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php index 6cf2adc44..3e33b765c 100644 --- a/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php @@ -37,8 +37,8 @@ return [ $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'); - $table->foreign('first_post_id')->references('id')->on('posts'); - $table->foreign('last_post_id')->references('id')->on('posts'); + $table->foreign('first_post_id')->references('id')->on('posts')->onDelete('set null'); + $table->foreign('last_post_id')->references('id')->on('posts')->onDelete('set null'); }); }, diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index cfad12d27..d9feb4b6c 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -100,21 +100,6 @@ class Discussion extends AbstractModel static::deleted(function (Discussion $discussion) { $discussion->raise(new Deleted($discussion)); - - // Delete all of the posts in the discussion. Before we delete them - // in a big batch query, we will loop through them and raise a - // PostWasDeleted event for each post. - $posts = $discussion->posts()->allTypes(); - - foreach ($posts->cursor() as $post) { - $discussion->raise(new PostDeleted($post)); - } - - $posts->delete(); - - // Delete all of the 'state' records for all of the users who have - // read the discussion. - $discussion->readers()->detach(); }); static::saving(function (Discussion $discussion) { diff --git a/framework/core/src/Group/Group.php b/framework/core/src/Group/Group.php index 19f1b19fd..103dd4fea 100644 --- a/framework/core/src/Group/Group.php +++ b/framework/core/src/Group/Group.php @@ -64,8 +64,6 @@ class Group extends AbstractModel static::deleted(function (Group $group) { $group->raise(new Deleted($group)); - - $group->permissions()->delete(); }); } diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index aad9c5f0b..4ad6e1476 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -126,22 +126,6 @@ class User extends AbstractModel static::deleted(function (User $user) { $user->raise(new Deleted($user)); - - // Delete all of the posts by the user. Before we delete them - // in a big batch query, we will loop through them and raise a - // PostWasDeleted event for each post. - $posts = $user->posts()->allTypes(); - - foreach ($posts->cursor() as $post) { - $user->raise(new PostDeleted($post)); - } - - $posts->delete(); - - $user->read()->detach(); - $user->groups()->detach(); - $user->accessTokens()->delete(); - $user->notifications()->delete(); }); static::$dispatcher->fire( From a7a0a2ca863de60cab9d742e530b92966604fc26 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:19:15 +0930 Subject: [PATCH 39/85] Fix some incorrect attribute names --- framework/core/src/Api/Serializer/CurrentUserSerializer.php | 2 +- framework/core/src/Discussion/DiscussionRepository.php | 2 +- framework/core/src/Discussion/UserState.php | 4 ++-- framework/core/src/Http/Middleware/CollectGarbage.php | 2 +- framework/core/src/Http/Rememberer.php | 4 ++-- .../core/src/Notification/Command/ReadNotificationHandler.php | 3 ++- framework/core/src/Notification/NotificationSyncer.php | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/framework/core/src/Api/Serializer/CurrentUserSerializer.php b/framework/core/src/Api/Serializer/CurrentUserSerializer.php index d4d6bdcbf..667cd3592 100644 --- a/framework/core/src/Api/Serializer/CurrentUserSerializer.php +++ b/framework/core/src/Api/Serializer/CurrentUserSerializer.php @@ -24,7 +24,7 @@ class CurrentUserSerializer extends UserSerializer $attributes += [ 'isActivated' => (bool) $user->is_email_confirmed, 'email' => $user->email, - 'readTime' => $this->formatDate($user->read_notifications_at), + 'readTime' => $this->formatDate($user->marked_all_as_read_at), 'unreadNotificationsCount' => (int) $user->getUnreadNotificationsCount(), 'newNotificationsCount' => (int) $user->getNewNotificationsCount(), 'preferences' => (array) $user->preferences diff --git a/framework/core/src/Discussion/DiscussionRepository.php b/framework/core/src/Discussion/DiscussionRepository.php index 68862b5a1..de0b7ee36 100644 --- a/framework/core/src/Discussion/DiscussionRepository.php +++ b/framework/core/src/Discussion/DiscussionRepository.php @@ -51,7 +51,7 @@ class DiscussionRepository { return Discussion::leftJoin('discussions_users', 'discussions_users.discussion_id', '=', 'discussions.id') ->where('user_id', $user->id) - ->whereRaw('read_number >= last_post_number') + ->whereRaw('last_read_post_number >= last_post_number') ->pluck('id') ->all(); } diff --git a/framework/core/src/Discussion/UserState.php b/framework/core/src/Discussion/UserState.php index ee856cff5..fc964d450 100644 --- a/framework/core/src/Discussion/UserState.php +++ b/framework/core/src/Discussion/UserState.php @@ -57,8 +57,8 @@ class UserState extends AbstractModel */ public function read($number) { - if ($number > $this->last_read_at) { - $this->last_read_at = $number; + if ($number > $this->last_read_post_number) { + $this->last_read_post_number = $number; $this->last_read_at = Carbon::now(); $this->raise(new UserRead($this)); diff --git a/framework/core/src/Http/Middleware/CollectGarbage.php b/framework/core/src/Http/Middleware/CollectGarbage.php index 361ec172c..9b0da016c 100644 --- a/framework/core/src/Http/Middleware/CollectGarbage.php +++ b/framework/core/src/Http/Middleware/CollectGarbage.php @@ -58,7 +58,7 @@ class CollectGarbage implements Middleware $time = Carbon::now()->timestamp; - AccessToken::whereRaw('last_activity <= ? - lifetime', [$time])->delete(); + AccessToken::whereRaw('last_activity_at <= ? - lifetime_seconds', [$time])->delete(); $earliestToKeep = date('Y-m-d H:i:s', $time - 24 * 60 * 60); diff --git a/framework/core/src/Http/Rememberer.php b/framework/core/src/Http/Rememberer.php index 1d25df007..17b1673d2 100644 --- a/framework/core/src/Http/Rememberer.php +++ b/framework/core/src/Http/Rememberer.php @@ -33,12 +33,12 @@ class Rememberer public function remember(ResponseInterface $response, AccessToken $token) { - $token->lifetime = 5 * 365 * 24 * 60 * 60; // 5 years + $token->lifetime_seconds = 5 * 365 * 24 * 60 * 60; // 5 years $token->save(); return FigResponseCookies::set( $response, - $this->cookie->make(self::COOKIE_NAME, $token->id, $token->lifetime) + $this->cookie->make(self::COOKIE_NAME, $token->token, $token->lifetime_seconds) ); } diff --git a/framework/core/src/Notification/Command/ReadNotificationHandler.php b/framework/core/src/Notification/Command/ReadNotificationHandler.php index 41da8e781..f26cb7712 100644 --- a/framework/core/src/Notification/Command/ReadNotificationHandler.php +++ b/framework/core/src/Notification/Command/ReadNotificationHandler.php @@ -11,6 +11,7 @@ namespace Flarum\Notification\Command; +use Carbon\Carbon; use Flarum\Notification\Notification; use Flarum\User\AssertPermissionTrait; @@ -36,7 +37,7 @@ class ReadNotificationHandler 'type' => $notification->type, 'subject_id' => $notification->subject_id ]) - ->update(['is_read' => true]); + ->update(['read_at' => Carbon::now()]); $notification->is_read = true; diff --git a/framework/core/src/Notification/NotificationSyncer.php b/framework/core/src/Notification/NotificationSyncer.php index b8cd39b48..e4b21af80 100644 --- a/framework/core/src/Notification/NotificationSyncer.php +++ b/framework/core/src/Notification/NotificationSyncer.php @@ -179,7 +179,7 @@ class NotificationSyncer array_map(function (User $user) use ($attributes, $now) { return $attributes + [ 'user_id' => $user->id, - 'time' => $now + 'created_at' => $now ]; }, $recipients) ); From 9ca95afafeccde42e29a5702f4c23ad8e3bdce4e Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:21:08 +0930 Subject: [PATCH 40/85] Use Eloquent's `latest` and `oldest` --- .../core/src/Api/Controller/UpdateDiscussionController.php | 2 +- framework/core/src/Discussion/Discussion.php | 4 ++-- framework/core/src/Notification/NotificationRepository.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Api/Controller/UpdateDiscussionController.php b/framework/core/src/Api/Controller/UpdateDiscussionController.php index 86b0f8152..68e196e21 100644 --- a/framework/core/src/Api/Controller/UpdateDiscussionController.php +++ b/framework/core/src/Api/Controller/UpdateDiscussionController.php @@ -64,7 +64,7 @@ class UpdateDiscussionController extends AbstractShowController if ($posts = $discussion->getModifiedPosts()) { $posts = (new Collection($posts))->load('discussion', 'user'); - $discussionPosts = $discussion->posts()->whereVisibleTo($actor)->orderBy('time')->pluck('id')->all(); + $discussionPosts = $discussion->posts()->whereVisibleTo($actor)->oldest()->pluck('id')->all(); foreach ($discussionPosts as &$id) { foreach ($posts as $post) { diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index d9feb4b6c..982bcccb3 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -223,7 +223,7 @@ class Discussion extends AbstractModel public function refreshLastPost() { /** @var Post $lastPost */ - if ($lastPost = $this->comments()->latest('created_at')->first()) { + if ($lastPost = $this->comments()->latest()->first()) { $this->setLastPost($lastPost); } @@ -269,7 +269,7 @@ class Discussion extends AbstractModel */ public function mergePost(MergeableInterface $post) { - $lastPost = $this->posts()->latest('created_at')->first(); + $lastPost = $this->posts()->latest()->first(); $post = $post->saveAfter($lastPost); diff --git a/framework/core/src/Notification/NotificationRepository.php b/framework/core/src/Notification/NotificationRepository.php index 629fe8792..726206cb3 100644 --- a/framework/core/src/Notification/NotificationRepository.php +++ b/framework/core/src/Notification/NotificationRepository.php @@ -41,7 +41,7 @@ class NotificationRepository return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count')) ->mergeBindings($primaries->getQuery()) ->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id')) - ->latest('created_at') + ->latest() ->get(); } From 97a94a8c603e73353194670695de47ed4c7088f5 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:21:37 +0930 Subject: [PATCH 41/85] Specify ambiguous column names --- framework/core/src/Discussion/DiscussionPolicy.php | 6 +++--- framework/core/src/Post/PostPolicy.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Discussion/DiscussionPolicy.php b/framework/core/src/Discussion/DiscussionPolicy.php index d59e37637..d2bbd74f1 100644 --- a/framework/core/src/Discussion/DiscussionPolicy.php +++ b/framework/core/src/Discussion/DiscussionPolicy.php @@ -92,7 +92,7 @@ class DiscussionPolicy extends AbstractPolicy if (! $actor->hasPermission('discussion.hide')) { $query->where(function ($query) use ($actor) { $query->whereNull('discussions.hidden_at') - ->orWhere('user_id', $actor->id) + ->orWhere('discussions.user_id', $actor->id) ->orWhere(function ($query) use ($actor) { $this->events->fire( new ScopeModelVisibility($query, $actor, 'hide') @@ -105,8 +105,8 @@ class DiscussionPolicy extends AbstractPolicy // current user, or the user is allowed to edit the discussion's posts. if (! $actor->hasPermission('discussion.editPosts')) { $query->where(function ($query) use ($actor) { - $query->where('comment_count', '>', 0) - ->orWhere('user_id', $actor->id) + $query->where('discussions.comment_count', '>', 0) + ->orWhere('discussions.user_id', $actor->id) ->orWhere(function ($query) use ($actor) { $this->events->dispatch( new ScopeModelVisibility($query, $actor, 'editPosts') diff --git a/framework/core/src/Post/PostPolicy.php b/framework/core/src/Post/PostPolicy.php index 0370e775c..162343101 100644 --- a/framework/core/src/Post/PostPolicy.php +++ b/framework/core/src/Post/PostPolicy.php @@ -82,7 +82,7 @@ class PostPolicy extends AbstractPolicy if (! $actor->hasPermission('discussion.editPosts')) { $query->where(function ($query) use ($actor) { $query->whereNull('posts.hidden_at') - ->orWhere('user_id', $actor->id) + ->orWhere('posts.user_id', $actor->id) ->orWhereExists(function ($query) use ($actor) { $query->selectRaw('1') ->from('discussions') From 9bc934a89db799057ed736378a0eb343b5d77d40 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 17:22:03 +0930 Subject: [PATCH 42/85] Clean up attribute assignment --- framework/core/src/User/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 4ad6e1476..e49bff86f 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -277,7 +277,7 @@ class User extends AbstractModel */ public function changeAvatarPath($path) { - $this->attributes['avatar_url'] = $path; + $this->avatar_url = $path; $this->raise(new AvatarChanged($this)); From e6a7385ed4c1eb72a3e5d0682598c19d82be63b3 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 07:52:21 +0000 Subject: [PATCH 43/85] Apply fixes from StyleCI [ci skip] [skip ci] --- framework/core/src/Discussion/Discussion.php | 1 - framework/core/src/User/User.php | 1 - 2 files changed, 2 deletions(-) diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 982bcccb3..e11ff17c5 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -21,7 +21,6 @@ use Flarum\Discussion\Event\Restored; use Flarum\Discussion\Event\Started; use Flarum\Event\GetModelIsPrivate; use Flarum\Foundation\EventGeneratorTrait; -use Flarum\Post\Event\Deleted as PostDeleted; use Flarum\Post\MergeableInterface; use Flarum\Post\Post; use Flarum\User\User; diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index e49bff86f..dc009f51d 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -24,7 +24,6 @@ use Flarum\Group\Group; use Flarum\Group\Permission; use Flarum\Http\UrlGenerator; use Flarum\Notification\Notification; -use Flarum\Post\Event\Deleted as PostDeleted; use Flarum\User\Event\Activated; use Flarum\User\Event\AvatarChanged; use Flarum\User\Event\CheckingPassword; From 6df532bac7bf366514acf67cb8a65ea5ee8dbb53 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 18:35:50 +0930 Subject: [PATCH 44/85] Revert notifications_from table I didn't think this change through and it's going to be too difficult to implement right now. It can wait until we do the notifications revamp. For now reverting back to the old structure, with the `sender_id` column renamed to `from_user_id`. --- ...132900_create_notifications_from_table.php | 24 ------------- ...8_132901_seed_notifications_from_table.php | 34 ------------------- ...18_133000_change_notifications_columns.php | 5 +-- ..._change_notifications_add_foreign_keys.php | 10 +++++- .../core/src/Notification/Notification.php | 8 ++--- .../Notification/NotificationRepository.php | 2 +- .../src/Notification/NotificationSyncer.php | 6 ++-- framework/core/src/User/User.php | 2 +- 8 files changed, 21 insertions(+), 70 deletions(-) delete mode 100644 framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php delete mode 100644 framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php diff --git a/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php b/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php deleted file mode 100644 index 9ee23e2ed..000000000 --- a/framework/core/migrations/2018_01_18_132900_create_notifications_from_table.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Flarum\Database\Migration; -use Illuminate\Database\Schema\Blueprint; - -return Migration::createTable( - 'notifications_from', - function (Blueprint $table) { - $table->integer('id')->unsigned(); - $table->integer('from_user_id')->unsigned(); - - $table->foreign('id')->references('id')->on('notifications')->onDelete('cascade'); - $table->foreign('from_user_id')->references('id')->on('users')->onDelete('cascade'); - } -); diff --git a/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php b/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php deleted file mode 100644 index c58ba7df2..000000000 --- a/framework/core/migrations/2018_01_18_132901_seed_notifications_from_table.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\Database\Schema\Builder; - -return [ - 'up' => function (Builder $schema) { - $query = $schema->getConnection()->table('notifications') - ->whereExists(function ($query) { - $query->selectRaw(1)->from('users')->whereRaw('id = sender_id'); - }); - - foreach ($query->cursor() as $notification) { - $insert = [ - 'id' => $notification->id, - 'from_user_id' => $notification->sender_id - ]; - - $schema->getConnection()->table('notifications_from')->updateOrInsert($insert, $insert); - } - }, - - 'down' => function (Builder $schema) { - $schema->getConnection()->table('notifications_from')->truncate(); - } -]; diff --git a/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php b/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php index 56fef9ec8..fd4a71fe8 100644 --- a/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php +++ b/framework/core/migrations/2018_01_18_133000_change_notifications_columns.php @@ -16,9 +16,10 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { $schema->table('notifications', function (Blueprint $table) { - $table->dropColumn('sender_id', 'subject_type'); + $table->dropColumn('subject_type'); $table->renameColumn('time', 'created_at'); + $table->renameColumn('sender_id', 'from_user_id'); $table->dateTime('read_at')->nullable(); }); @@ -34,10 +35,10 @@ return [ 'down' => function (Builder $schema) { $schema->table('notifications', function (Blueprint $table) { - $table->integer('sender_id')->unsigned()->nullable(); $table->string('subject_type', 200)->nullable(); $table->renameColumn('created_at', 'time'); + $table->renameColumn('from_user_id', 'sender_id'); $table->boolean('is_read'); }); diff --git a/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php b/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php index c71327d10..442ae1dbd 100644 --- a/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php @@ -23,14 +23,22 @@ return [ }) ->delete(); + $schema->getConnection() + ->table('notifications') + ->whereNotExists(function ($query) { + $query->selectRaw(1)->from('users')->whereRaw('id = from_user_id'); + }) + ->update(['from_user_id' => null]); + $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) { - $table->dropForeign(['user_id']); + $table->dropForeign(['user_id', 'from_user_id']); }); } ]; diff --git a/framework/core/src/Notification/Notification.php b/framework/core/src/Notification/Notification.php index bbae7c4ff..c36bff190 100644 --- a/framework/core/src/Notification/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -49,7 +49,7 @@ class Notification extends AbstractModel * * @var array */ - protected $dates = ['created_at', 'read_at', 'deleted_at']; + protected $dates = ['created_at', 'read_at']; /** * A map of notification types and the model classes to use for their @@ -112,7 +112,7 @@ class Notification extends AbstractModel */ public function user() { - return $this->belongsTo(User::class, 'user_id'); + return $this->belongsTo(User::class); } /** @@ -122,7 +122,7 @@ class Notification extends AbstractModel */ public function sender() { - return $this->belongsTo(User::class, 'sender_id'); + return $this->belongsTo(User::class, 'from_user_id'); } /** @@ -132,7 +132,7 @@ class Notification extends AbstractModel */ public function subject() { - return $this->morphTo('subject', 'subjectModel', 'subject_id'); + return $this->morphTo('subject', 'subjectModel'); } /** diff --git a/framework/core/src/Notification/NotificationRepository.php b/framework/core/src/Notification/NotificationRepository.php index 726206cb3..b8e2b6681 100644 --- a/framework/core/src/Notification/NotificationRepository.php +++ b/framework/core/src/Notification/NotificationRepository.php @@ -32,7 +32,7 @@ class NotificationRepository ) ->where('user_id', $user->id) ->whereIn('type', $user->getAlertableNotificationTypes()) - ->whereNull('deleted_at') + ->where('is_deleted', false) ->groupBy('type', 'subject_id') ->orderByRaw('MAX(created_at) DESC') ->skip($offset) diff --git a/framework/core/src/Notification/NotificationSyncer.php b/framework/core/src/Notification/NotificationSyncer.php index e4b21af80..a8cdd66ab 100644 --- a/framework/core/src/Notification/NotificationSyncer.php +++ b/framework/core/src/Notification/NotificationSyncer.php @@ -225,10 +225,10 @@ class NotificationSyncer protected function getAttributes(Blueprint\BlueprintInterface $blueprint) { return [ - 'type' => $blueprint::getType(), - 'sender_id' => ($sender = $blueprint->getSender()) ? $sender->id : null, + 'type' => $blueprint::getType(), + 'from_user_id' => ($sender = $blueprint->getSender()) ? $sender->id : null, 'subject_id' => ($subject = $blueprint->getSubject()) ? $subject->id : null, - 'data' => ($data = $blueprint->getData()) ? json_encode($data) : null + 'data' => ($data = $blueprint->getData()) ? json_encode($data) : null ]; } } diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index dc009f51d..d1322fbf2 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -435,7 +435,7 @@ class User extends AbstractModel $cached = $this->notifications() ->whereIn('type', $this->getAlertableNotificationTypes()) ->whereNull('read_at') - ->whereNull('deleted_at') + ->where('is_deleted', false) ->get(); } From 5d221f87920bd79a4a614a0fe6b3722b3a2201ae Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 18:39:32 +0930 Subject: [PATCH 45/85] Fix user list sorting --- framework/core/src/Api/Controller/ListUsersController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Api/Controller/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index b04b17233..d37e191f9 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -36,10 +36,10 @@ class ListUsersController extends AbstractListController */ public $sortFields = [ 'username', - 'commentsCount', - 'discussionsCount', - 'lastSeenTime', - 'joinTime' + 'commentCount', + 'discussionCount', + 'lastSeenAt', + 'joinedAt' ]; /** From 05c8e1276141029b842a139e8ba2a9a566fa9620 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 22:02:54 +0930 Subject: [PATCH 46/85] Wrap column names; use whereColumn where possible --- ..._change_access_tokens_add_foreign_keys.php | 2 +- ...00_change_discussions_add_foreign_keys.php | 2 +- ...hange_discussion_user_add_foreign_keys.php | 4 ++-- ...0_change_email_tokens_add_foreign_keys.php | 2 +- ...ange_group_permission_add_foreign_keys.php | 2 +- ...700_change_group_user_add_foreign_keys.php | 4 ++-- ..._change_notifications_add_foreign_keys.php | 4 ++-- ...hange_password_tokens_add_foreign_keys.php | 2 +- ...8_135100_change_posts_add_foreign_keys.php | 2 +- .../src/Discussion/DiscussionRepository.php | 2 +- .../Search/Gambit/FulltextGambit.php | 19 +++++++++++++------ framework/core/src/Post/Post.php | 6 +----- framework/core/src/Post/PostPolicy.php | 2 +- 13 files changed, 28 insertions(+), 25 deletions(-) diff --git a/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php b/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php index b6125506d..3103a963e 100644 --- a/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php @@ -19,7 +19,7 @@ return [ $schema->getConnection() ->table('access_tokens') ->whereNotExists(function ($query) { - $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + $query->selectRaw(1)->from('users')->whereColumn('id', 'user_id'); }) ->delete(); diff --git a/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php b/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php index 3e33b765c..23d6b338c 100644 --- a/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php @@ -21,7 +21,7 @@ return [ $selectId = function ($table, $column) use ($connection) { return new Expression( - '('.$connection->table($table)->whereRaw("id = $column")->select('id')->toSql().')' + '('.$connection->table($table)->whereColumn('id', $column)->select('id')->toSql().')' ); }; diff --git a/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php b/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php index 4a9d69a07..c3bf1d9fd 100644 --- a/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php @@ -19,10 +19,10 @@ return [ $connection = $schema->getConnection(); $connection->table('discussion_user') ->whereNotExists(function ($query) { - $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + $query->selectRaw(1)->from('users')->whereColumn('id', 'user_id'); }) ->orWhereNotExists(function ($query) { - $query->selectRaw(1)->from('discussions')->whereRaw('id = discussion_id'); + $query->selectRaw(1)->from('discussions')->whereColumn('id', 'discussion_id'); }) ->delete(); diff --git a/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php b/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php index c840045e6..243b706f3 100644 --- a/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php @@ -19,7 +19,7 @@ return [ $schema->getConnection() ->table('email_tokens') ->whereNotExists(function ($query) { - $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + $query->selectRaw(1)->from('users')->whereColumn('id', 'user_id'); }) ->delete(); diff --git a/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php b/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php index f783547a6..267a09dc0 100644 --- a/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php @@ -19,7 +19,7 @@ return [ $schema->getConnection() ->table('group_permission') ->whereNotExists(function ($query) { - $query->selectRaw(1)->from('groups')->whereRaw('id = group_id'); + $query->selectRaw(1)->from('groups')->whereColumn('id', 'group_id'); }) ->delete(); diff --git a/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php b/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php index 028b35e94..79a5ef2a5 100644 --- a/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php @@ -19,10 +19,10 @@ return [ $schema->getConnection() ->table('group_user') ->whereNotExists(function ($query) { - $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + $query->selectRaw(1)->from('users')->whereColumn('id', 'user_id'); }) ->orWhereNotExists(function ($query) { - $query->selectRaw(1)->from('groups')->whereRaw('id = group_id'); + $query->selectRaw(1)->from('groups')->whereColumn('id', 'group_id'); }) ->delete(); diff --git a/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php b/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php index 442ae1dbd..4845222cb 100644 --- a/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php @@ -19,14 +19,14 @@ return [ $schema->getConnection() ->table('notifications') ->whereNotExists(function ($query) { - $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + $query->selectRaw(1)->from('users')->whereColumn('id', 'user_id'); }) ->delete(); $schema->getConnection() ->table('notifications') ->whereNotExists(function ($query) { - $query->selectRaw(1)->from('users')->whereRaw('id = from_user_id'); + $query->selectRaw(1)->from('users')->whereColumn('id', 'from_user_id'); }) ->update(['from_user_id' => null]); diff --git a/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php b/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php index 7e3c3c6d4..cb7303e71 100644 --- a/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php @@ -19,7 +19,7 @@ return [ $connection = $schema->getConnection(); $connection->table('password_tokens') ->whereNotExists(function ($query) { - $query->selectRaw(1)->from('users')->whereRaw('id = user_id'); + $query->selectRaw(1)->from('users')->whereColumn('id', 'user_id'); }) ->delete(); diff --git a/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php b/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php index 2a0623052..3ac447273 100644 --- a/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php @@ -21,7 +21,7 @@ return [ $selectId = function ($table, $column) use ($connection) { return new Expression( - '('.$connection->table($table)->whereRaw("id = $column")->select('id')->toSql().')' + '('.$connection->table($table)->whereColumn('id', $column)->select('id')->toSql().')' ); }; diff --git a/framework/core/src/Discussion/DiscussionRepository.php b/framework/core/src/Discussion/DiscussionRepository.php index de0b7ee36..588132d7b 100644 --- a/framework/core/src/Discussion/DiscussionRepository.php +++ b/framework/core/src/Discussion/DiscussionRepository.php @@ -51,7 +51,7 @@ class DiscussionRepository { return Discussion::leftJoin('discussions_users', 'discussions_users.discussion_id', '=', 'discussions.id') ->where('user_id', $user->id) - ->whereRaw('last_read_post_number >= last_post_number') + ->whereColumn('last_read_post_number', '>=', 'last_post_number') ->pluck('id') ->all(); } diff --git a/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php b/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php index 81f5e5976..d925e0ec8 100644 --- a/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php @@ -33,22 +33,29 @@ class FulltextGambit implements GambitInterface // See https://bugs.mysql.com/bug.php?id=74042 $bit = str_replace('@', '*', $bit); - $search->getQuery() - ->selectRaw('SUBSTRING_INDEX(GROUP_CONCAT(posts.id ORDER BY MATCH(posts.content) AGAINST (?) DESC), \',\', 1) as most_relevant_post_id', [$bit]) + $query = $search->getQuery(); + $grammar = $query->getGrammar(); + + $query + ->selectRaw('SUBSTRING_INDEX(GROUP_CONCAT('.$grammar->wrap('posts.id').' ORDER BY MATCH('.$grammar->wrap('posts.content').') AGAINST (?) DESC), \',\', 1) as most_relevant_post_id', [$bit]) ->leftJoin('posts', 'posts.discussion_id', '=', 'discussions.id') ->where('posts.type', 'comment') ->where(function ($query) use ($search) { event(new ScopeModelVisibility(Post::query()->setQuery($query), $search->getActor(), 'view')); }) ->where(function ($query) use ($bit) { - $query->whereRaw('MATCH(discussions.title) AGAINST (? IN BOOLEAN MODE)', [$bit]) - ->orWhereRaw('MATCH(posts.content) AGAINST (? IN BOOLEAN MODE)', [$bit]); + $grammar = $query->getGrammar(); + + $query->whereRaw('MATCH('.$grammar->wrap('discussions.title').') AGAINST (? IN BOOLEAN MODE)', [$bit]) + ->orWhereRaw('MATCH('.$grammar->wrap('posts.content').') AGAINST (? IN BOOLEAN MODE)', [$bit]); }) ->groupBy('posts.discussion_id'); $search->setDefaultSort(function ($query) use ($bit) { - $query->orderByRaw('MATCH(discussions.title) AGAINST (?) desc', [$bit]); - $query->orderByRaw('MATCH(posts.content) AGAINST (?) desc', [$bit]); + $grammar = $query->getGrammar(); + + $query->orderByRaw('MATCH('.$grammar->wrap('discussions.title').') AGAINST (?) desc', [$bit]); + $query->orderByRaw('MATCH('.$grammar->wrap('posts.content').') AGAINST (?) desc', [$bit]); }); } } diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php index 137e9657d..899949a6d 100644 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -121,13 +121,9 @@ class Post extends AbstractModel // Make sure the post's discussion is visible as well $query->whereExists(function ($query) use ($actor) { - $grammar = $query->getGrammar(); - $column1 = $grammar->wrap('discussions.id'); - $column2 = $grammar->wrap('posts.discussion_id'); - $query->selectRaw('1') ->from('discussions') - ->whereRaw("$column1 = $column2"); + ->whereColumn('discussions.id', 'posts.discussion_id'); static::$dispatcher->dispatch( new ScopeModelVisibility(Discussion::query()->setQuery($query), $actor, 'view') diff --git a/framework/core/src/Post/PostPolicy.php b/framework/core/src/Post/PostPolicy.php index 34df19747..0ed52e9d1 100644 --- a/framework/core/src/Post/PostPolicy.php +++ b/framework/core/src/Post/PostPolicy.php @@ -86,7 +86,7 @@ class PostPolicy extends AbstractPolicy ->orWhereExists(function ($query) use ($actor) { $query->selectRaw('1') ->from('discussions') - ->whereRaw('discussions.id = posts.discussion_id') + ->whereColumn('discussions.id', 'posts.discussion_id') ->where(function ($query) use ($actor) { $this->events->dispatch( new ScopeModelVisibility(Discussion::query()->setQuery($query), $actor, 'hidePosts') From 5aa15f5b271cfcda09ad8e89818e4a30dec9a56a Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 22:09:14 +0930 Subject: [PATCH 47/85] Remove file accidentally added in merge --- .../src/Forum/Controller/IndexController.php | 87 ------------------- 1 file changed, 87 deletions(-) delete mode 100644 framework/core/src/Forum/Controller/IndexController.php diff --git a/framework/core/src/Forum/Controller/IndexController.php b/framework/core/src/Forum/Controller/IndexController.php deleted file mode 100644 index 544b68944..000000000 --- a/framework/core/src/Forum/Controller/IndexController.php +++ /dev/null @@ -1,87 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Forum\Controller; - -use Flarum\Api\Client as ApiClient; -use Flarum\Forum\Frontend; -use Flarum\User\User; -use Illuminate\Contracts\Events\Dispatcher; -use Psr\Http\Message\ServerRequestInterface as Request; - -class IndexController extends FrontendController -{ - /** - * @var ApiClient - */ - protected $api; - - /** - * A map of sort query param values to their API sort param. - * - * @var array - */ - private $sortMap = [ - 'latest' => '-lastPostedAt', - 'top' => '-commentCount', - 'newest' => '-createdAt', - 'oldest' => 'createdAt' - ]; - - /** - * {@inheritdoc} - */ - public function __construct(Frontend $webApp, Dispatcher $events, ApiClient $api) - { - parent::__construct($webApp, $events); - - $this->api = $api; - } - - /** - * {@inheritdoc} - */ - protected function getView(Request $request) - { - $view = parent::getView($request); - - $queryParams = $request->getQueryParams(); - - $sort = array_pull($queryParams, 'sort'); - $q = array_pull($queryParams, 'q'); - $page = array_pull($queryParams, 'page', 1); - - $params = [ - 'sort' => $sort && isset($this->sortMap[$sort]) ? $this->sortMap[$sort] : '', - 'filter' => compact('q'), - 'page' => ['offset' => ($page - 1) * 20, 'limit' => 20] - ]; - - $document = $this->getDocument($request->getAttribute('actor'), $params); - - $view->document = $document; - $view->content = app('view')->make('flarum.forum::frontend.content.index', compact('document', 'page', 'forum')); - - return $view; - } - - /** - * Get the result of an API request to list discussions. - * - * @param User $actor - * @param array $params - * @return object - */ - private function getDocument(User $actor, array $params) - { - return json_decode($this->api->send('Flarum\Api\Controller\ListDiscussionsController', $actor, $params)->getBody()); - } -} From a13175600fc4a469ba72f51aa1cbc154b5337e6e Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 21 Jul 2018 23:02:44 +0930 Subject: [PATCH 48/85] Fix group/permission seeding Updating the Migration::addPermission helper table name means we need to move the seed migration to after the table rename migration. We also add a sanity check for each permission's group since the foreign key will fail if the group doesn't exist. Of course, the only way to make sure groups are seeded before permissions is to move them into another migration. --- ...003952_allow_hide_posts_for_moderators.php | 17 --------- .../2018_07_21_000000_seed_default_groups.php | 38 +++++++++++++++++++ ...000100_seed_default_group_permissions.php} | 0 framework/core/src/Database/Migration.php | 26 +++++++------ .../src/Install/Console/InstallCommand.php | 24 ------------ 5 files changed, 53 insertions(+), 52 deletions(-) delete mode 100644 framework/core/migrations/2018_07_16_003952_allow_hide_posts_for_moderators.php create mode 100644 framework/core/migrations/2018_07_21_000000_seed_default_groups.php rename framework/core/migrations/{2015_02_25_000000_setup_default_permissions.php => 2018_07_21_000100_seed_default_group_permissions.php} (100%) diff --git a/framework/core/migrations/2018_07_16_003952_allow_hide_posts_for_moderators.php b/framework/core/migrations/2018_07_16_003952_allow_hide_posts_for_moderators.php deleted file mode 100644 index 57203b7b1..000000000 --- a/framework/core/migrations/2018_07_16_003952_allow_hide_posts_for_moderators.php +++ /dev/null @@ -1,17 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Flarum\Database\Migration; -use Flarum\Group\Group; - -return Migration::addPermissions([ - 'discussion.hidePosts' => Group::MODERATOR_ID -]); diff --git a/framework/core/migrations/2018_07_21_000000_seed_default_groups.php b/framework/core/migrations/2018_07_21_000000_seed_default_groups.php new file mode 100644 index 000000000..12566ba02 --- /dev/null +++ b/framework/core/migrations/2018_07_21_000000_seed_default_groups.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Group\Group; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $db = $schema->getConnection(); + + $groups = [ + [Group::ADMINISTRATOR_ID, 'Admin', 'Admins', '#B72A2A', 'fas fa-wrench'], + [Group::GUEST_ID, 'Guest', 'Guests', null, null], + [Group::MEMBER_ID, 'Member', 'Members', null, null], + [Group::MODERATOR_ID, 'Mod', 'Mods', '#80349E', 'fas fa-bolt'] + ]; + + foreach ($groups as $group) { + if ($db->table('groups')->where('id', $group[0])->exists()) { + continue; + } + + $db->table('groups')->insert(array_combine(['id', 'name_singular', 'name_plural', 'color', 'icon'], $group)); + } + }, + + 'down' => function (Builder $schema) { + // do nothing so as to preserve user data + } +]; diff --git a/framework/core/migrations/2015_02_25_000000_setup_default_permissions.php b/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php similarity index 100% rename from framework/core/migrations/2015_02_25_000000_setup_default_permissions.php rename to framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php diff --git a/framework/core/src/Database/Migration.php b/framework/core/src/Database/Migration.php index 6469b847f..58f23acba 100644 --- a/framework/core/src/Database/Migration.php +++ b/framework/core/src/Database/Migration.php @@ -137,11 +137,11 @@ abstract class Migration */ public static function addPermissions(array $permissions) { - $keys = []; + $rows = []; foreach ($permissions as $permission => $groups) { foreach ((array) $groups as $group) { - $keys[] = [ + $rows[] = [ 'group_id' => $group, 'permission' => $permission, ]; @@ -149,23 +149,27 @@ abstract class Migration } return [ - 'up' => function (Builder $schema) use ($keys) { + 'up' => function (Builder $schema) use ($rows) { $db = $schema->getConnection(); - foreach ($keys as $key) { - $instance = $db->table('permissions')->where($key)->first(); - - if (is_null($instance)) { - $db->table('permissions')->insert($key); + foreach ($rows as $row) { + if ($db->table('group_permission')->where($row)->exists()) { + continue; } + + if ($db->table('groups')->where('id', $row['group_id'])->doesntExist()) { + continue; + } + + $db->table('group_permission')->insert($row); } }, - 'down' => function (Builder $schema) use ($keys) { + 'down' => function (Builder $schema) use ($rows) { $db = $schema->getConnection(); - foreach ($keys as $key) { - $db->table('permissions')->where($key)->delete(); + foreach ($rows as $row) { + $db->table('group_permission')->where($row)->delete(); } } ]; diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 758c1702c..b91ec48b6 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -193,8 +193,6 @@ class InstallCommand extends AbstractCommand $this->application->register(SearchServiceProvider::class); $this->application->register(PostServiceProvider::class); - $this->seedGroups(); - $this->createAdminUser(); $this->enableBundledExtensions(); @@ -280,28 +278,6 @@ class InstallCommand extends AbstractCommand } } - protected function seedGroups() - { - Group::unguard(); - - $groups = [ - [Group::ADMINISTRATOR_ID, 'Admin', 'Admins', '#B72A2A', 'fas fa-wrench'], - [Group::GUEST_ID, 'Guest', 'Guests', null, null], - [Group::MEMBER_ID, 'Member', 'Members', null, null], - [Group::MODERATOR_ID, 'Mod', 'Mods', '#80349E', 'fas fa-bolt'] - ]; - - foreach ($groups as $group) { - Group::create([ - 'id' => $group[0], - 'name_singular' => $group[1], - 'name_plural' => $group[2], - 'color' => $group[3], - 'icon' => $group[4], - ]); - } - } - protected function createAdminUser() { $admin = $this->adminUser; From fdcb78a48c1ad7ab4b30557c632c7f3fa9b89f90 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 1 Aug 2018 13:24:55 +0930 Subject: [PATCH 49/85] Change TIMESTAMP columns to DATETIME manually --- ...e_registration_tokens_created_at_to_datetime.php | 13 +++++++------ ...0_change_email_tokens_created_at_to_datetime.php | 13 +++++++------ ...hange_password_tokens_created_at_to_datetime.php | 13 +++++++------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php b/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php index 7a5dc8cf6..392950d34 100644 --- a/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php +++ b/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php @@ -14,14 +14,15 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('registration_tokens', function (Blueprint $table) { - $table->dateTime('created_at')->change(); - }); + // do this manually because dbal doesn't recognize timestamp columns + $connection = $schema->getConnection(); + $prefix = $connection->getTablePrefix(); + $connection->statement("ALTER TABLE {$prefix}registration_tokens MODIFY created_at DATETIME"); }, 'down' => function (Builder $schema) { - $schema->table('registration_tokens', function (Blueprint $table) { - $table->timestamp('created_at')->change(); - }); + $connection = $schema->getConnection(); + $prefix = $connection->getTablePrefix(); + $connection->statement("ALTER TABLE {$prefix}registration_tokens MODIFY created_at TIMESTAMP"); } ]; diff --git a/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php b/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php index 7a4c8e218..f075a44f7 100644 --- a/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php +++ b/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php @@ -14,14 +14,15 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('email_tokens', function (Blueprint $table) { - $table->dateTime('created_at')->change(); - }); + // do this manually because dbal doesn't recognize timestamp columns + $connection = $schema->getConnection(); + $prefix = $connection->getTablePrefix(); + $connection->statement("ALTER TABLE {$prefix}email_tokens MODIFY created_at DATETIME"); }, 'down' => function (Builder $schema) { - $schema->table('email_tokens', function (Blueprint $table) { - $table->timestamp('created_at')->change(); - }); + $connection = $schema->getConnection(); + $prefix = $connection->getTablePrefix(); + $connection->statement("ALTER TABLE {$prefix}email_tokens MODIFY created_at TIMESTAMP"); } ]; diff --git a/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php b/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php index f552e9cf9..c65ac98e2 100644 --- a/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php +++ b/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php @@ -14,14 +14,15 @@ use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('password_tokens', function (Blueprint $table) { - $table->dateTime('created_at')->change(); - }); + // do this manually because dbal doesn't recognize timestamp columns + $connection = $schema->getConnection(); + $prefix = $connection->getTablePrefix(); + $connection->statement("ALTER TABLE {$prefix}password_tokens MODIFY created_at DATETIME"); }, 'down' => function (Builder $schema) { - $schema->table('password_tokens', function (Blueprint $table) { - $table->timestamp('created_at')->change(); - }); + $connection = $schema->getConnection(); + $prefix = $connection->getTablePrefix(); + $connection->statement("ALTER TABLE {$prefix}password_tokens MODIFY created_at TIMESTAMP"); } ]; From ccb1321dca45d6b397ddcbecd75b04f189fc28b3 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 1 Aug 2018 03:55:21 +0000 Subject: [PATCH 50/85] Apply fixes from StyleCI [ci skip] [skip ci] --- ..._102100_change_registration_tokens_created_at_to_datetime.php | 1 - ...8_01_15_072800_change_email_tokens_created_at_to_datetime.php | 1 - ...1_18_134600_change_password_tokens_created_at_to_datetime.php | 1 - 3 files changed, 3 deletions(-) diff --git a/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php b/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php index 392950d34..f3276bf1d 100644 --- a/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php +++ b/framework/core/migrations/2018_01_11_102100_change_registration_tokens_created_at_to_datetime.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; return [ diff --git a/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php b/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php index f075a44f7..f393f72f2 100644 --- a/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php +++ b/framework/core/migrations/2018_01_15_072800_change_email_tokens_created_at_to_datetime.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; return [ diff --git a/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php b/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php index c65ac98e2..9a411f5ff 100644 --- a/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php +++ b/framework/core/migrations/2018_01_18_134600_change_password_tokens_created_at_to_datetime.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; return [ From 8b2781829f1a456774dfbed10d9ce24cb1463407 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 15:15:40 +0930 Subject: [PATCH 51/85] Remove user_user table Since there is currently no core code that facilitates use of this table, we are removing it for now. It can be re-added in a subsequent PR. --- ...18_01_30_223700_create_user_user_table.php | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 framework/core/migrations/2018_01_30_223700_create_user_user_table.php diff --git a/framework/core/migrations/2018_01_30_223700_create_user_user_table.php b/framework/core/migrations/2018_01_30_223700_create_user_user_table.php deleted file mode 100644 index 60c845ff6..000000000 --- a/framework/core/migrations/2018_01_30_223700_create_user_user_table.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Flarum\Database\Migration; -use Illuminate\Database\Schema\Blueprint; - -return Migration::createTable( - 'user_user', - function (Blueprint $table) { - $table->integer('user_id')->unsigned(); - $table->integer('other_user_id')->unsigned(); - - $table->foreign('user_id')->references('id')->on('posts')->onDelete('cascade'); - $table->foreign('other_user_id')->references('id')->on('users')->onDelete('cascade'); - } -); From 2c115cae94e4c937f6175098dc005051a0e21043 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 17:09:22 +0930 Subject: [PATCH 52/85] Revert method name --- framework/core/src/User/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 615984bc6..d43a3224c 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -127,7 +127,7 @@ class User extends AbstractModel $user->raise(new Deleted($user)); }); - static::$dispatcher->fire( + static::$dispatcher->dispatch( new ConfigureUserPreferences ); } From fbdfeeec85b597e35cceae1ce622d3b71c67f60b Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:54:46 +0930 Subject: [PATCH 53/85] Fix reset password --- framework/core/src/Forum/Controller/ResetPasswordController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index a95dd07cc..5b9811657 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -49,7 +49,7 @@ class ResetPasswordController extends AbstractHtmlController } return $this->view->make('flarum.forum::reset-password') - ->with('passwordToken', $token->id) + ->with('passwordToken', $token->token) ->with('csrfToken', $request->getAttribute('session')->token()); } } From c3906eabcdc7bdb7a3b0b2b4a6f6ba3f8d67b9a8 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 22:12:45 +0930 Subject: [PATCH 54/85] Fix installer --- framework/core/src/Install/Console/InstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 9c4c5fe95..e36ab06c5 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -288,7 +288,7 @@ class InstallCommand extends AbstractCommand 'is_email_confirmed' => 1, ]); - $this->db->table('users_groups')->insert([ + $this->db->table('group_user')->insert([ 'user_id' => $uid, 'group_id' => Group::ADMINISTRATOR_ID, ]); From 5a6b0fc474c1bb820e94228b2a3e469be50d51f2 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 20:37:04 +0930 Subject: [PATCH 55/85] Rename discussion.commentsCount --- framework/core/js/src/common/models/Discussion.js | 4 ++-- framework/core/src/Api/Serializer/DiscussionSerializer.php | 2 +- framework/core/src/Discussion/Discussion.php | 4 ++-- framework/core/src/Discussion/DiscussionMetadataUpdater.php | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/framework/core/js/src/common/models/Discussion.js b/framework/core/js/src/common/models/Discussion.js index ab6664df7..e57eafab9 100644 --- a/framework/core/js/src/common/models/Discussion.js +++ b/framework/core/js/src/common/models/Discussion.js @@ -18,8 +18,8 @@ Object.assign(Discussion.prototype, { lastPost: Model.hasOne('lastPost'), lastPostNumber: Model.attribute('lastPostNumber'), - commentsCount: Model.attribute('commentsCount'), - repliesCount: computed('commentsCount', commentsCount => Math.max(0, commentsCount - 1)), + commentCount: Model.attribute('commentCount'), + repliesCount: computed('commentCount', commentCount => Math.max(0, commentCount - 1)), posts: Model.hasMany('posts'), mostRelevantPost: Model.hasOne('mostRelevantPost'), diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index e99d5522b..e8f3df822 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -37,7 +37,7 @@ class DiscussionSerializer extends BasicDiscussionSerializer $gate = $this->gate->forUser($this->actor); $attributes = parent::getDefaultAttributes($discussion) + [ - 'commentsCount' => (int) $discussion->comment_count, + 'commentCount' => (int) $discussion->comment_count, 'participantsCount' => (int) $discussion->participant_count, 'startTime' => $this->formatDate($discussion->created_at), 'lastTime' => $this->formatDate($discussion->last_posted_at), diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index e11ff17c5..cce9f1aa1 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -230,11 +230,11 @@ class Discussion extends AbstractModel } /** - * Refresh the discussion's comments count. + * Refresh the discussion's comment count. * * @return $this */ - public function refreshCommentsCount() + public function refreshCommentCount() { $this->comment_count = $this->comments()->count(); diff --git a/framework/core/src/Discussion/DiscussionMetadataUpdater.php b/framework/core/src/Discussion/DiscussionMetadataUpdater.php index b1f894f4c..cb89a40c7 100644 --- a/framework/core/src/Discussion/DiscussionMetadataUpdater.php +++ b/framework/core/src/Discussion/DiscussionMetadataUpdater.php @@ -39,7 +39,7 @@ class DiscussionMetadataUpdater $discussion = $event->post->discussion; if ($discussion && $discussion->exists) { - $discussion->refreshCommentsCount(); + $discussion->refreshCommentCount(); $discussion->refreshLastPost(); $discussion->refreshParticipantsCount(); $discussion->save(); @@ -76,7 +76,7 @@ class DiscussionMetadataUpdater $discussion = $event->post->discussion; if ($discussion && $discussion->exists) { - $discussion->refreshCommentsCount(); + $discussion->refreshCommentCount(); $discussion->refreshParticipantsCount(); $discussion->refreshLastPost(); $discussion->save(); @@ -91,7 +91,7 @@ class DiscussionMetadataUpdater $discussion = $post->discussion; if ($discussion && $discussion->exists) { - $discussion->refreshCommentsCount(); + $discussion->refreshCommentCount(); $discussion->refreshParticipantsCount(); if ($discussion->last_post_id == $post->id) { From 98d85d51d32e95ff21f84a836cef5c7e360618fb Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 20:38:29 +0930 Subject: [PATCH 56/85] Rename discussion.participantsCount --- framework/core/src/Api/Serializer/DiscussionSerializer.php | 2 +- framework/core/src/Discussion/Discussion.php | 4 ++-- framework/core/src/Discussion/DiscussionMetadataUpdater.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index e8f3df822..38900a1ce 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -38,7 +38,7 @@ class DiscussionSerializer extends BasicDiscussionSerializer $attributes = parent::getDefaultAttributes($discussion) + [ 'commentCount' => (int) $discussion->comment_count, - 'participantsCount' => (int) $discussion->participant_count, + 'participantCount' => (int) $discussion->participant_count, 'startTime' => $this->formatDate($discussion->created_at), 'lastTime' => $this->formatDate($discussion->last_posted_at), 'lastPostNumber' => (int) $discussion->last_post_number, diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index cce9f1aa1..60d529b6d 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -242,11 +242,11 @@ class Discussion extends AbstractModel } /** - * Refresh the discussion's participants count. + * Refresh the discussion's participant count. * * @return $this */ - public function refreshParticipantsCount() + public function refreshParticipantCount() { $this->participant_count = $this->participants()->count('users.id'); diff --git a/framework/core/src/Discussion/DiscussionMetadataUpdater.php b/framework/core/src/Discussion/DiscussionMetadataUpdater.php index cb89a40c7..27a162fd0 100644 --- a/framework/core/src/Discussion/DiscussionMetadataUpdater.php +++ b/framework/core/src/Discussion/DiscussionMetadataUpdater.php @@ -41,7 +41,7 @@ class DiscussionMetadataUpdater if ($discussion && $discussion->exists) { $discussion->refreshCommentCount(); $discussion->refreshLastPost(); - $discussion->refreshParticipantsCount(); + $discussion->refreshParticipantCount(); $discussion->save(); } } @@ -77,7 +77,7 @@ class DiscussionMetadataUpdater if ($discussion && $discussion->exists) { $discussion->refreshCommentCount(); - $discussion->refreshParticipantsCount(); + $discussion->refreshParticipantCount(); $discussion->refreshLastPost(); $discussion->save(); } @@ -92,7 +92,7 @@ class DiscussionMetadataUpdater if ($discussion && $discussion->exists) { $discussion->refreshCommentCount(); - $discussion->refreshParticipantsCount(); + $discussion->refreshParticipantCount(); if ($discussion->last_post_id == $post->id) { $discussion->refreshLastPost(); From 14885fc0e1222c6995ec46e14d8c4a63b8e59562 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 20:42:07 +0930 Subject: [PATCH 57/85] Rename discussion.startPost --- framework/core/js/src/common/models/Discussion.js | 2 +- .../core/js/src/forum/components/DiscussionListItem.js | 6 +++--- .../src/Api/Controller/CreateDiscussionController.php | 2 +- .../core/src/Api/Controller/ListDiscussionsController.php | 4 ++-- .../core/src/Api/Controller/ShowDiscussionController.php | 2 +- .../core/src/Api/Serializer/BasicDiscussionSerializer.php | 2 +- .../src/Discussion/Command/StartDiscussionHandler.php | 2 +- framework/core/src/Discussion/Discussion.php | 8 ++++---- framework/core/tests/Test/Concerns/ManagesContent.php | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/framework/core/js/src/common/models/Discussion.js b/framework/core/js/src/common/models/Discussion.js index e57eafab9..7634e47d9 100644 --- a/framework/core/js/src/common/models/Discussion.js +++ b/framework/core/js/src/common/models/Discussion.js @@ -11,7 +11,7 @@ Object.assign(Discussion.prototype, { startTime: Model.attribute('startTime', Model.transformDate), startUser: Model.hasOne('startUser'), - startPost: Model.hasOne('startPost'), + firstPost: Model.hasOne('firstPost'), lastTime: Model.attribute('lastTime', Model.transformDate), lastUser: Model.hasOne('lastUser'), diff --git a/framework/core/js/src/forum/components/DiscussionListItem.js b/framework/core/js/src/forum/components/DiscussionListItem.js index c395c72f9..1f4f663bf 100644 --- a/framework/core/js/src/forum/components/DiscussionListItem.js +++ b/framework/core/js/src/forum/components/DiscussionListItem.js @@ -156,7 +156,7 @@ export default class DiscussionListItem extends Component { * * @return {Boolean} */ - showStartPost() { + showFirstPost() { return ['newest', 'oldest'].indexOf(this.props.params.sort) !== -1; } @@ -192,7 +192,7 @@ export default class DiscussionListItem extends Component { const items = new ItemList(); if (this.props.params.q) { - const post = this.props.discussion.mostRelevantPost() || this.props.discussion.startPost(); + const post = this.props.discussion.mostRelevantPost() || this.props.discussion.firstPost(); if (post && post.contentType() === 'comment') { const excerpt = highlight(post.contentPlain(), this.highlightRegExp, 175); @@ -202,7 +202,7 @@ export default class DiscussionListItem extends Component { items.add('terminalPost', TerminalPost.component({ discussion: this.props.discussion, - lastPost: !this.showStartPost() + lastPost: !this.showFirstPost() }) ); } diff --git a/framework/core/src/Api/Controller/CreateDiscussionController.php b/framework/core/src/Api/Controller/CreateDiscussionController.php index a58418a1e..2451b8cc9 100644 --- a/framework/core/src/Api/Controller/CreateDiscussionController.php +++ b/framework/core/src/Api/Controller/CreateDiscussionController.php @@ -33,7 +33,7 @@ class CreateDiscussionController extends AbstractCreateController 'posts', 'startUser', 'lastUser', - 'startPost', + 'firstPost', 'lastPost' ]; diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index f01e3ace6..a30e37223 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -40,7 +40,7 @@ class ListDiscussionsController extends AbstractListController * {@inheritdoc} */ public $optionalInclude = [ - 'startPost', + 'firstPost', 'lastPost' ]; @@ -98,7 +98,7 @@ class ListDiscussionsController extends AbstractListController $results = $results->getResults()->load($load); - if ($relations = array_intersect($load, ['startPost', 'lastPost'])) { + if ($relations = array_intersect($load, ['firstPost', 'lastPost'])) { foreach ($results as $discussion) { foreach ($relations as $relation) { if ($discussion->$relation) { diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index 33fc20477..545fdfbcc 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -54,7 +54,7 @@ class ShowDiscussionController extends AbstractShowController public $optionalInclude = [ 'startUser', 'lastUser', - 'startPost', + 'firstPost', 'lastPost' ]; diff --git a/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php index 026082a23..cb3ad2fe1 100644 --- a/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php @@ -52,7 +52,7 @@ class BasicDiscussionSerializer extends AbstractSerializer /** * @return \Tobscure\JsonApi\Relationship */ - protected function startPost($discussion) + protected function firstPost($discussion) { return $this->hasOne($discussion, BasicPostSerializer::class); } diff --git a/framework/core/src/Discussion/Command/StartDiscussionHandler.php b/framework/core/src/Discussion/Command/StartDiscussionHandler.php index bc4fbb47b..cbc7f9559 100644 --- a/framework/core/src/Discussion/Command/StartDiscussionHandler.php +++ b/framework/core/src/Discussion/Command/StartDiscussionHandler.php @@ -94,7 +94,7 @@ class StartDiscussionHandler // attributes as posting the reply will have changed some of them (e.g. // last_time.) $discussion->setRawAttributes($post->discussion->getAttributes(), true); - $discussion->setStartPost($post); + $discussion->setFirstPost($post); $discussion->setLastPost($post); $this->dispatchEventsFor($discussion, $actor); diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 60d529b6d..7eea9f561 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -46,7 +46,7 @@ use Flarum\Util\Str; * @property \Illuminate\Database\Eloquent\Collection $posts * @property \Illuminate\Database\Eloquent\Collection $comments * @property \Illuminate\Database\Eloquent\Collection $participants - * @property Post|null $startPost + * @property Post|null $firstPost * @property User|null $startUser * @property Post|null $lastPost * @property User|null $lastUser @@ -184,12 +184,12 @@ class Discussion extends AbstractModel } /** - * Set the discussion's start post details. + * Set the discussion's first post details. * * @param Post $post * @return $this */ - public function setStartPost(Post $post) + public function setFirstPost(Post $post) { $this->created_at = $post->created_at; $this->user_id = $post->user_id; @@ -329,7 +329,7 @@ class Discussion extends AbstractModel * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function startPost() + public function firstPost() { return $this->belongsTo(Post::class, 'first_post_id'); } diff --git a/framework/core/tests/Test/Concerns/ManagesContent.php b/framework/core/tests/Test/Concerns/ManagesContent.php index 9d1d687cb..80437c7fc 100644 --- a/framework/core/tests/Test/Concerns/ManagesContent.php +++ b/framework/core/tests/Test/Concerns/ManagesContent.php @@ -31,8 +31,8 @@ trait ManagesContent $post->save(); - if (! $this->discussion->startPost) { - $this->discussion->setStartPost($post); + if (! $this->discussion->firstPost) { + $this->discussion->setFirstPost($post); $this->discussion->setLastPost($post); $this->discussion->save(); From 6670605b7c3483dc17c5ae1d67e744b32272c1c5 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 20:43:52 +0930 Subject: [PATCH 58/85] Rename discussion.startUser --- framework/core/js/src/common/models/Discussion.js | 2 +- framework/core/js/src/forum/components/DiscussionList.js | 2 +- .../core/js/src/forum/components/DiscussionListItem.js | 8 ++++---- framework/core/js/src/forum/components/TerminalPost.js | 2 +- .../src/Api/Controller/CreateDiscussionController.php | 2 +- .../core/src/Api/Controller/ListDiscussionsController.php | 2 +- .../core/src/Api/Controller/ShowDiscussionController.php | 2 +- .../core/src/Api/Serializer/BasicDiscussionSerializer.php | 2 +- framework/core/src/Discussion/Discussion.php | 6 +++--- framework/core/src/Discussion/DiscussionRenamedLogger.php | 2 +- framework/core/src/User/UserMetadataUpdater.php | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/framework/core/js/src/common/models/Discussion.js b/framework/core/js/src/common/models/Discussion.js index 7634e47d9..7fa357e6b 100644 --- a/framework/core/js/src/common/models/Discussion.js +++ b/framework/core/js/src/common/models/Discussion.js @@ -10,7 +10,7 @@ Object.assign(Discussion.prototype, { slug: Model.attribute('slug'), startTime: Model.attribute('startTime', Model.transformDate), - startUser: Model.hasOne('startUser'), + user: Model.hasOne('user'), firstPost: Model.hasOne('firstPost'), lastTime: Model.attribute('lastTime', Model.transformDate), diff --git a/framework/core/js/src/forum/components/DiscussionList.js b/framework/core/js/src/forum/components/DiscussionList.js index 72fc707e0..48e1e88ea 100644 --- a/framework/core/js/src/forum/components/DiscussionList.js +++ b/framework/core/js/src/forum/components/DiscussionList.js @@ -87,7 +87,7 @@ export default class DiscussionList extends Component { * @api */ requestParams() { - const params = {include: ['startUser', 'lastUser'], filter: {}}; + const params = {include: ['user', 'lastUser'], filter: {}}; params.sort = this.sortMap()[this.props.params.sort]; diff --git a/framework/core/js/src/forum/components/DiscussionListItem.js b/framework/core/js/src/forum/components/DiscussionListItem.js index 1f4f663bf..39a9d7282 100644 --- a/framework/core/js/src/forum/components/DiscussionListItem.js +++ b/framework/core/js/src/forum/components/DiscussionListItem.js @@ -58,7 +58,7 @@ export default class DiscussionListItem extends Component { if (retain) return retain; const discussion = this.props.discussion; - const startUser = discussion.startUser(); + const user = discussion.user(); const isUnread = discussion.isUnread(); const isRead = discussion.isRead(); const showUnread = !this.showRepliesCount() && isUnread; @@ -93,14 +93,14 @@ export default class DiscussionListItem extends Component {
- - {avatar(startUser, {title: ''})} + {avatar(user, {title: ''})}
diff --git a/framework/core/js/src/forum/components/TerminalPost.js b/framework/core/js/src/forum/components/TerminalPost.js index c4c1b5bf7..7475f12b9 100644 --- a/framework/core/js/src/forum/components/TerminalPost.js +++ b/framework/core/js/src/forum/components/TerminalPost.js @@ -13,7 +13,7 @@ import icon from '../../common/helpers/icon'; export default class TerminalPost extends Component { view() { const discussion = this.props.discussion; - const lastPost = this.props.lastPost && discussion.repliesCount(); + const lastPost = this.props.lastPost && discussion.replyCount(); const user = discussion[lastPost ? 'lastPostedUser' : 'user'](); const time = discussion[lastPost ? 'lastPostedAt' : 'createdAt'](); From c2f6e2d7a37e11d048b495e8ca5cba523c4a9c89 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:25:45 +0930 Subject: [PATCH 67/85] Rename post.time --- framework/core/js/src/common/models/Post.js | 2 +- framework/core/js/src/forum/components/PostMeta.js | 2 +- framework/core/js/src/forum/components/PostStream.js | 2 +- framework/core/src/Api/Serializer/BasicPostSerializer.php | 2 +- framework/core/src/Post/Command/PostReplyHandler.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/core/js/src/common/models/Post.js b/framework/core/js/src/common/models/Post.js index 848434dab..0c72d3710 100644 --- a/framework/core/js/src/common/models/Post.js +++ b/framework/core/js/src/common/models/Post.js @@ -8,7 +8,7 @@ Object.assign(Post.prototype, { number: Model.attribute('number'), discussion: Model.hasOne('discussion'), - time: Model.attribute('time', Model.transformDate), + createdAt: Model.attribute('createdAt', Model.transformDate), user: Model.hasOne('user'), contentType: Model.attribute('contentType'), content: Model.attribute('content'), diff --git a/framework/core/js/src/forum/components/PostMeta.js b/framework/core/js/src/forum/components/PostMeta.js index 965819d93..98df112aa 100644 --- a/framework/core/js/src/forum/components/PostMeta.js +++ b/framework/core/js/src/forum/components/PostMeta.js @@ -14,7 +14,7 @@ import fullTime from '../../common/helpers/fullTime'; export default class PostMeta extends Component { view() { const post = this.props.post; - const time = post.time(); + const time = post.createdAt(); const permalink = this.getPermalink(post); const touch = 'ontouchstart' in document.documentElement; diff --git a/framework/core/js/src/forum/components/PostStream.js b/framework/core/js/src/forum/components/PostStream.js index 6175e20dd..335d0f441 100644 --- a/framework/core/js/src/forum/components/PostStream.js +++ b/framework/core/js/src/forum/components/PostStream.js @@ -205,7 +205,7 @@ class PostStream extends Component { const attrs = {'data-index': this.visibleStart + i}; if (post) { - const time = post.time(); + const time = post.createdAt(); const PostComponent = app.postComponents[post.contentType()]; content = PostComponent ? PostComponent.component({post}) : ''; diff --git a/framework/core/src/Api/Serializer/BasicPostSerializer.php b/framework/core/src/Api/Serializer/BasicPostSerializer.php index fcd689136..b12c28175 100644 --- a/framework/core/src/Api/Serializer/BasicPostSerializer.php +++ b/framework/core/src/Api/Serializer/BasicPostSerializer.php @@ -39,7 +39,7 @@ class BasicPostSerializer extends AbstractSerializer $attributes = [ 'id' => (int) $post->id, 'number' => (int) $post->number, - 'time' => $this->formatDate($post->created_at), + 'createdAt' => $this->formatDate($post->created_at), 'contentType' => $post->type ]; diff --git a/framework/core/src/Post/Command/PostReplyHandler.php b/framework/core/src/Post/Command/PostReplyHandler.php index 816448da5..5817bbfcf 100644 --- a/framework/core/src/Post/Command/PostReplyHandler.php +++ b/framework/core/src/Post/Command/PostReplyHandler.php @@ -91,7 +91,7 @@ class PostReplyHandler $command->ipAddress ); - if ($actor->isAdmin() && ($time = array_get($command->data, 'attributes.time'))) { + if ($actor->isAdmin() && ($time = array_get($command->data, 'attributes.createdAt'))) { $post->created_at = new Carbon($time); } From 8eb4a75da7240d66e4013b0f8ef83a54e30e541c Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:27:05 +0930 Subject: [PATCH 68/85] Rename post.editTime --- framework/core/js/src/common/models/Post.js | 4 ++-- framework/core/js/src/forum/components/PostEdited.js | 2 +- framework/core/src/Api/Serializer/PostSerializer.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/js/src/common/models/Post.js b/framework/core/js/src/common/models/Post.js index 0c72d3710..a720ed3a9 100644 --- a/framework/core/js/src/common/models/Post.js +++ b/framework/core/js/src/common/models/Post.js @@ -15,9 +15,9 @@ Object.assign(Post.prototype, { contentHtml: Model.attribute('contentHtml'), contentPlain: computed('contentHtml', getPlainContent), - editTime: Model.attribute('editTime', Model.transformDate), + editedAt: Model.attribute('editedAt', Model.transformDate), editUser: Model.hasOne('editUser'), - isEdited: computed('editTime', editTime => !!editTime), + isEdited: computed('editedAt', editedAt => !!editedAt), hideTime: Model.attribute('hideTime', Model.transformDate), hideUser: Model.hasOne('hideUser'), diff --git a/framework/core/js/src/forum/components/PostEdited.js b/framework/core/js/src/forum/components/PostEdited.js index e35ced036..3b8bc6f90 100644 --- a/framework/core/js/src/forum/components/PostEdited.js +++ b/framework/core/js/src/forum/components/PostEdited.js @@ -21,7 +21,7 @@ export default class PostEdited extends Component { const editUser = post.editUser(); const editedInfo = extractText(app.translator.trans( 'core.forum.post.edited_tooltip', - {user: editUser, ago: humanTime(post.editTime())} + {user: editUser, ago: humanTime(post.editedAt())} )); if (editedInfo !== this.oldEditedInfo) { this.shouldUpdateTooltip = true; diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index b3e4495e1..31305963f 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -56,7 +56,7 @@ class PostSerializer extends BasicPostSerializer } if ($post->edited_at) { - $attributes['editTime'] = $this->formatDate($post->edited_at); + $attributes['editedAt'] = $this->formatDate($post->edited_at); } if ($post->hidden_at) { From 767becec00ee5c53f5b606248701242b821188e5 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:27:50 +0930 Subject: [PATCH 69/85] Rename post.hideTime --- framework/core/js/src/common/models/Post.js | 4 ++-- framework/core/js/src/forum/utils/PostControls.js | 4 ++-- framework/core/src/Api/Serializer/PostSerializer.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/core/js/src/common/models/Post.js b/framework/core/js/src/common/models/Post.js index a720ed3a9..b9c1127c3 100644 --- a/framework/core/js/src/common/models/Post.js +++ b/framework/core/js/src/common/models/Post.js @@ -19,9 +19,9 @@ Object.assign(Post.prototype, { editUser: Model.hasOne('editUser'), isEdited: computed('editedAt', editedAt => !!editedAt), - hideTime: Model.attribute('hideTime', Model.transformDate), + hiddenAt: Model.attribute('hiddenAt', Model.transformDate), hideUser: Model.hasOne('hideUser'), - isHidden: computed('hideTime', hideTime => !!hideTime), + isHidden: computed('hiddenAt', hiddenAt => !!hiddenAt), canEdit: Model.attribute('canEdit'), canHide: Model.attribute('canHide'), diff --git a/framework/core/js/src/forum/utils/PostControls.js b/framework/core/js/src/forum/utils/PostControls.js index 6140b96b8..d90528898 100644 --- a/framework/core/js/src/forum/utils/PostControls.js +++ b/framework/core/js/src/forum/utils/PostControls.js @@ -123,7 +123,7 @@ export default { * @return {Promise} */ hideAction() { - this.pushAttributes({ hideTime: new Date(), hideUser: app.session.user }); + this.pushAttributes({ hiddenAt: new Date(), hideUser: app.session.user }); return this.save({ isHidden: true }).then(() => m.redraw()); }, @@ -134,7 +134,7 @@ export default { * @return {Promise} */ restoreAction() { - this.pushAttributes({ hideTime: null, hideUser: null }); + this.pushAttributes({ hiddenAt: null, hideUser: null }); return this.save({ isHidden: false }).then(() => m.redraw()); }, diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index 31305963f..888b32c3d 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -61,7 +61,7 @@ class PostSerializer extends BasicPostSerializer if ($post->hidden_at) { $attributes['isHidden'] = true; - $attributes['hideTime'] = $this->formatDate($post->hidden_at); + $attributes['hiddenAt'] = $this->formatDate($post->hidden_at); } $attributes += [ From 5bb93e569b6253245f402ea6851e717402dbbd6f Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:29:17 +0930 Subject: [PATCH 70/85] Rename post.editUser --- framework/core/js/src/common/models/Post.js | 2 +- framework/core/js/src/forum/components/PostEdited.js | 4 ++-- framework/core/src/Api/Controller/ListPostsController.php | 2 +- .../core/src/Api/Controller/ShowDiscussionController.php | 2 +- framework/core/src/Api/Controller/ShowPostController.php | 2 +- framework/core/src/Api/Controller/UpdatePostController.php | 2 +- framework/core/src/Api/Serializer/PostSerializer.php | 2 +- framework/core/src/Post/Post.php | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/framework/core/js/src/common/models/Post.js b/framework/core/js/src/common/models/Post.js index b9c1127c3..1b87e6722 100644 --- a/framework/core/js/src/common/models/Post.js +++ b/framework/core/js/src/common/models/Post.js @@ -16,7 +16,7 @@ Object.assign(Post.prototype, { contentPlain: computed('contentHtml', getPlainContent), editedAt: Model.attribute('editedAt', Model.transformDate), - editUser: Model.hasOne('editUser'), + editedUser: Model.hasOne('editedUser'), isEdited: computed('editedAt', editedAt => !!editedAt), hiddenAt: Model.attribute('hiddenAt', Model.transformDate), diff --git a/framework/core/js/src/forum/components/PostEdited.js b/framework/core/js/src/forum/components/PostEdited.js index 3b8bc6f90..021307040 100644 --- a/framework/core/js/src/forum/components/PostEdited.js +++ b/framework/core/js/src/forum/components/PostEdited.js @@ -18,10 +18,10 @@ export default class PostEdited extends Component { view() { const post = this.props.post; - const editUser = post.editUser(); + const editedUser = post.editedUser(); const editedInfo = extractText(app.translator.trans( 'core.forum.post.edited_tooltip', - {user: editUser, ago: humanTime(post.editedAt())} + {user: editedUser, ago: humanTime(post.editedAt())} )); if (editedInfo !== this.oldEditedInfo) { this.shouldUpdateTooltip = true; diff --git a/framework/core/src/Api/Controller/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index 609839fa4..dbec57c47 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -32,7 +32,7 @@ class ListPostsController extends AbstractListController public $include = [ 'user', 'user.groups', - 'editUser', + 'editedUser', 'hideUser', 'discussion' ]; diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index 4c439d9fb..0cf94b253 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -44,7 +44,7 @@ class ShowDiscussionController extends AbstractShowController 'posts.discussion', 'posts.user', 'posts.user.groups', - 'posts.editUser', + 'posts.editedUser', 'posts.hideUser' ]; diff --git a/framework/core/src/Api/Controller/ShowPostController.php b/framework/core/src/Api/Controller/ShowPostController.php index f269b7ebc..da88668c9 100644 --- a/framework/core/src/Api/Controller/ShowPostController.php +++ b/framework/core/src/Api/Controller/ShowPostController.php @@ -29,7 +29,7 @@ class ShowPostController extends AbstractShowController public $include = [ 'user', 'user.groups', - 'editUser', + 'editedUser', 'hideUser', 'discussion' ]; diff --git a/framework/core/src/Api/Controller/UpdatePostController.php b/framework/core/src/Api/Controller/UpdatePostController.php index fe2db5ed9..7ec36e8e5 100644 --- a/framework/core/src/Api/Controller/UpdatePostController.php +++ b/framework/core/src/Api/Controller/UpdatePostController.php @@ -28,7 +28,7 @@ class UpdatePostController extends AbstractShowController * {@inheritdoc} */ public $include = [ - 'editUser', + 'editedUser', 'discussion' ]; diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index 888b32c3d..c4996ecf4 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -92,7 +92,7 @@ class PostSerializer extends BasicPostSerializer /** * @return \Tobscure\JsonApi\Relationship */ - protected function editUser($post) + protected function editedUser($post) { return $this->hasOne($post, BasicUserSerializer::class); } diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php index 899949a6d..947495545 100644 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -34,7 +34,7 @@ use Illuminate\Database\Eloquent\Builder; * @property int|null $hidden_user_id * @property \Flarum\Discussion\Discussion|null $discussion * @property User|null $user - * @property User|null $editUser + * @property User|null $editedUser * @property User|null $hideUser * @property string $ip_address * @property bool $is_private @@ -167,7 +167,7 @@ class Post extends AbstractModel * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function editUser() + public function editedUser() { return $this->belongsTo(User::class, 'edited_user_id'); } From 1c4070a0343b5ad89253e19602c1df076368c08a Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:30:06 +0930 Subject: [PATCH 71/85] Rename post.hideUser --- framework/core/js/src/common/models/Post.js | 2 +- framework/core/js/src/forum/utils/PostControls.js | 4 ++-- framework/core/src/Api/Controller/ListPostsController.php | 2 +- .../core/src/Api/Controller/ShowDiscussionController.php | 2 +- framework/core/src/Api/Controller/ShowPostController.php | 2 +- framework/core/src/Api/Serializer/PostSerializer.php | 2 +- framework/core/src/Post/Post.php | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/framework/core/js/src/common/models/Post.js b/framework/core/js/src/common/models/Post.js index 1b87e6722..fa0c434f6 100644 --- a/framework/core/js/src/common/models/Post.js +++ b/framework/core/js/src/common/models/Post.js @@ -20,7 +20,7 @@ Object.assign(Post.prototype, { isEdited: computed('editedAt', editedAt => !!editedAt), hiddenAt: Model.attribute('hiddenAt', Model.transformDate), - hideUser: Model.hasOne('hideUser'), + hiddenUser: Model.hasOne('hiddenUser'), isHidden: computed('hiddenAt', hiddenAt => !!hiddenAt), canEdit: Model.attribute('canEdit'), diff --git a/framework/core/js/src/forum/utils/PostControls.js b/framework/core/js/src/forum/utils/PostControls.js index d90528898..574b039bf 100644 --- a/framework/core/js/src/forum/utils/PostControls.js +++ b/framework/core/js/src/forum/utils/PostControls.js @@ -123,7 +123,7 @@ export default { * @return {Promise} */ hideAction() { - this.pushAttributes({ hiddenAt: new Date(), hideUser: app.session.user }); + this.pushAttributes({ hiddenAt: new Date(), hiddenUser: app.session.user }); return this.save({ isHidden: true }).then(() => m.redraw()); }, @@ -134,7 +134,7 @@ export default { * @return {Promise} */ restoreAction() { - this.pushAttributes({ hiddenAt: null, hideUser: null }); + this.pushAttributes({ hiddenAt: null, hiddenUser: null }); return this.save({ isHidden: false }).then(() => m.redraw()); }, diff --git a/framework/core/src/Api/Controller/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index dbec57c47..f2740778d 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -33,7 +33,7 @@ class ListPostsController extends AbstractListController 'user', 'user.groups', 'editedUser', - 'hideUser', + 'hiddenUser', 'discussion' ]; diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index 0cf94b253..ae30f47fc 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -45,7 +45,7 @@ class ShowDiscussionController extends AbstractShowController 'posts.user', 'posts.user.groups', 'posts.editedUser', - 'posts.hideUser' + 'posts.hiddenUser' ]; /** diff --git a/framework/core/src/Api/Controller/ShowPostController.php b/framework/core/src/Api/Controller/ShowPostController.php index da88668c9..dcec04ba9 100644 --- a/framework/core/src/Api/Controller/ShowPostController.php +++ b/framework/core/src/Api/Controller/ShowPostController.php @@ -30,7 +30,7 @@ class ShowPostController extends AbstractShowController 'user', 'user.groups', 'editedUser', - 'hideUser', + 'hiddenUser', 'discussion' ]; diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index c4996ecf4..44ec76460 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -100,7 +100,7 @@ class PostSerializer extends BasicPostSerializer /** * @return \Tobscure\JsonApi\Relationship */ - protected function hideUser($post) + protected function hiddenUser($post) { return $this->hasOne($post, BasicUserSerializer::class); } diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php index 947495545..0a416d5bd 100644 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -35,7 +35,7 @@ use Illuminate\Database\Eloquent\Builder; * @property \Flarum\Discussion\Discussion|null $discussion * @property User|null $user * @property User|null $editedUser - * @property User|null $hideUser + * @property User|null $hiddenUser * @property string $ip_address * @property bool $is_private */ @@ -177,7 +177,7 @@ class Post extends AbstractModel * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function hideUser() + public function hiddenUser() { return $this->belongsTo(User::class, 'hidden_user_id'); } From e253b79fe6b7fefd1b74a07194f5230791f233d8 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:32:47 +0930 Subject: [PATCH 72/85] Rename user.discussionsCount --- framework/core/js/src/common/models/User.js | 2 +- framework/core/js/src/forum/components/UserPage.js | 2 +- framework/core/src/Api/Serializer/UserSerializer.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/js/src/common/models/User.js b/framework/core/js/src/common/models/User.js index 35e692467..e0c55fcf7 100644 --- a/framework/core/js/src/common/models/User.js +++ b/framework/core/js/src/common/models/User.js @@ -25,7 +25,7 @@ Object.assign(User.prototype, { unreadNotificationsCount: Model.attribute('unreadNotificationsCount'), newNotificationsCount: Model.attribute('newNotificationsCount'), - discussionsCount: Model.attribute('discussionsCount'), + discussionCount: Model.attribute('discussionCount'), commentsCount: Model.attribute('commentsCount'), canEdit: Model.attribute('canEdit'), diff --git a/framework/core/js/src/forum/components/UserPage.js b/framework/core/js/src/forum/components/UserPage.js index cd2809063..4d036dca7 100644 --- a/framework/core/js/src/forum/components/UserPage.js +++ b/framework/core/js/src/forum/components/UserPage.js @@ -140,7 +140,7 @@ export default class UserPage extends Page { items.add('discussions', LinkButton.component({ href: app.route('user.discussions', {username: user.username()}), - children: [app.translator.trans('core.forum.user.discussions_link'), {user.discussionsCount()}], + children: [app.translator.trans('core.forum.user.discussions_link'), {user.discussionCount()}], icon: 'fas fa-bars' }), 90 diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 106c39d7a..02d760ada 100644 --- a/framework/core/src/Api/Serializer/UserSerializer.php +++ b/framework/core/src/Api/Serializer/UserSerializer.php @@ -42,7 +42,7 @@ class UserSerializer extends BasicUserSerializer $attributes += [ 'joinTime' => $this->formatDate($user->joined_at), - 'discussionsCount' => (int) $user->discussion_count, + 'discussionCount' => (int) $user->discussion_count, 'commentsCount' => (int) $user->comment_count, 'canEdit' => $canEdit, 'canDelete' => $gate->allows('delete', $user), From 14508d9fcc88a34b02b4dee98de425efb3d8aa2f Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:33:18 +0930 Subject: [PATCH 73/85] Rename user.commentCount --- framework/core/js/src/common/models/User.js | 2 +- framework/core/js/src/forum/components/UserPage.js | 2 +- framework/core/src/Api/Serializer/UserSerializer.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/js/src/common/models/User.js b/framework/core/js/src/common/models/User.js index e0c55fcf7..f49512ffc 100644 --- a/framework/core/js/src/common/models/User.js +++ b/framework/core/js/src/common/models/User.js @@ -26,7 +26,7 @@ Object.assign(User.prototype, { newNotificationsCount: Model.attribute('newNotificationsCount'), discussionCount: Model.attribute('discussionCount'), - commentsCount: Model.attribute('commentsCount'), + commentCount: Model.attribute('commentCount'), canEdit: Model.attribute('canEdit'), canDelete: Model.attribute('canDelete'), diff --git a/framework/core/js/src/forum/components/UserPage.js b/framework/core/js/src/forum/components/UserPage.js index 4d036dca7..67c27fb01 100644 --- a/framework/core/js/src/forum/components/UserPage.js +++ b/framework/core/js/src/forum/components/UserPage.js @@ -131,7 +131,7 @@ export default class UserPage extends Page { items.add('posts', LinkButton.component({ href: app.route('user.posts', {username: user.username()}), - children: [app.translator.trans('core.forum.user.posts_link'), {user.commentsCount()}], + children: [app.translator.trans('core.forum.user.posts_link'), {user.commentCount()}], icon: 'far fa-comment' }), 100 diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 02d760ada..94103106e 100644 --- a/framework/core/src/Api/Serializer/UserSerializer.php +++ b/framework/core/src/Api/Serializer/UserSerializer.php @@ -43,7 +43,7 @@ class UserSerializer extends BasicUserSerializer $attributes += [ 'joinTime' => $this->formatDate($user->joined_at), 'discussionCount' => (int) $user->discussion_count, - 'commentsCount' => (int) $user->comment_count, + 'commentCount' => (int) $user->comment_count, 'canEdit' => $canEdit, 'canDelete' => $gate->allows('delete', $user), ]; From 666dfe2eb81b6863216a7849effdaf40dfcbd78e Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:33:48 +0930 Subject: [PATCH 74/85] Rename user.lastSeenTime --- framework/core/js/src/common/helpers/userOnline.js | 2 +- framework/core/js/src/common/models/User.js | 4 ++-- framework/core/js/src/forum/components/SettingsPage.js | 2 +- framework/core/js/src/forum/components/UserCard.js | 6 +++--- framework/core/src/Api/Serializer/UserSerializer.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/framework/core/js/src/common/helpers/userOnline.js b/framework/core/js/src/common/helpers/userOnline.js index 8a7052c89..fcbef1673 100644 --- a/framework/core/js/src/common/helpers/userOnline.js +++ b/framework/core/js/src/common/helpers/userOnline.js @@ -7,7 +7,7 @@ import icon from './icon'; * @return {Object} */ export default function userOnline(user) { - if (user.lastSeenTime() && user.isOnline()) { + if (user.lastSeenAt() && user.isOnline()) { return {icon('fas fa-circle')}; } } diff --git a/framework/core/js/src/common/models/User.js b/framework/core/js/src/common/models/User.js index f49512ffc..284f75413 100644 --- a/framework/core/js/src/common/models/User.js +++ b/framework/core/js/src/common/models/User.js @@ -20,7 +20,7 @@ Object.assign(User.prototype, { groups: Model.hasMany('groups'), joinTime: Model.attribute('joinTime', Model.transformDate), - lastSeenTime: Model.attribute('lastSeenTime', Model.transformDate), + lastSeenAt: Model.attribute('lastSeenAt', Model.transformDate), readTime: Model.attribute('readTime', Model.transformDate), unreadNotificationsCount: Model.attribute('unreadNotificationsCount'), newNotificationsCount: Model.attribute('newNotificationsCount'), @@ -54,7 +54,7 @@ Object.assign(User.prototype, { * @public */ isOnline() { - return this.lastSeenTime() > moment().subtract(5, 'minutes').toDate(); + return this.lastSeenAt() > moment().subtract(5, 'minutes').toDate(); }, /** diff --git a/framework/core/js/src/forum/components/SettingsPage.js b/framework/core/js/src/forum/components/SettingsPage.js index 9ea3993a7..e58e1204c 100644 --- a/framework/core/js/src/forum/components/SettingsPage.js +++ b/framework/core/js/src/forum/components/SettingsPage.js @@ -134,7 +134,7 @@ export default class SettingsPage extends UserPage { children: app.translator.trans('core.forum.settings.privacy_disclose_online_label'), state: this.user.preferences().discloseOnline, onchange: (value, component) => { - this.user.pushAttributes({lastSeenTime: null}); + this.user.pushAttributes({lastSeenAt: null}); this.preferenceSaver('discloseOnline')(value, component); } }) diff --git a/framework/core/js/src/forum/components/UserCard.js b/framework/core/js/src/forum/components/UserCard.js index 68c743a00..fa042005c 100644 --- a/framework/core/js/src/forum/components/UserCard.js +++ b/framework/core/js/src/forum/components/UserCard.js @@ -79,16 +79,16 @@ export default class UserCard extends Component { infoItems() { const items = new ItemList(); const user = this.props.user; - const lastSeenTime = user.lastSeenTime(); + const lastSeenAt = user.lastSeenAt(); - if (lastSeenTime) { + if (lastSeenAt) { const online = user.isOnline(); items.add('lastSeen', ( {online ? [icon('fas fa-circle'), ' ', app.translator.trans('core.forum.user.online_text')] - : [icon('far fa-clock'), ' ', humanTime(lastSeenTime)]} + : [icon('far fa-clock'), ' ', humanTime(lastSeenAt)]} )); } diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 94103106e..9ac6fcb70 100644 --- a/framework/core/src/Api/Serializer/UserSerializer.php +++ b/framework/core/src/Api/Serializer/UserSerializer.php @@ -50,7 +50,7 @@ class UserSerializer extends BasicUserSerializer if ($user->getPreference('discloseOnline')) { $attributes += [ - 'lastSeenTime' => $this->formatDate($user->last_seen_at) + 'lastSeenAt' => $this->formatDate($user->last_seen_at) ]; } From 0d526cfc37ea1e52e0e9a61d1da3fe1eaa2f4559 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:35:04 +0930 Subject: [PATCH 75/85] Rename user.isActivated --- framework/core/js/src/common/models/User.js | 2 +- framework/core/js/src/forum/components/EditUserModal.js | 8 ++++---- .../core/js/src/forum/utils/alertEmailConfirmation.js | 2 +- .../core/src/Api/Serializer/CurrentUserSerializer.php | 2 +- framework/core/src/Api/Serializer/UserSerializer.php | 4 ++-- framework/core/src/User/Command/EditUserHandler.php | 2 +- framework/core/src/User/Command/RegisterUserHandler.php | 2 +- .../tests/Api/Controller/CreateUserControllerTest.php | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/framework/core/js/src/common/models/User.js b/framework/core/js/src/common/models/User.js index 284f75413..d822307ea 100644 --- a/framework/core/js/src/common/models/User.js +++ b/framework/core/js/src/common/models/User.js @@ -12,7 +12,7 @@ Object.assign(User.prototype, { username: Model.attribute('username'), displayName: Model.attribute('displayName'), email: Model.attribute('email'), - isActivated: Model.attribute('isActivated'), + isEmailConfirmed: Model.attribute('isEmailConfirmed'), password: Model.attribute('password'), avatarUrl: Model.attribute('avatarUrl'), diff --git a/framework/core/js/src/forum/components/EditUserModal.js b/framework/core/js/src/forum/components/EditUserModal.js index 4cabb05c8..81b61dcc1 100644 --- a/framework/core/js/src/forum/components/EditUserModal.js +++ b/framework/core/js/src/forum/components/EditUserModal.js @@ -15,7 +15,7 @@ export default class EditUserModal extends Modal { this.username = m.prop(user.username() || ''); this.email = m.prop(user.email() || ''); - this.isActivated = m.prop(user.isActivated() || false); + this.isEmailConfirmed = m.prop(user.isEmailConfirmed() || false); this.setPassword = m.prop(false); this.password = m.prop(user.password() || ''); this.groups = {}; @@ -50,7 +50,7 @@ export default class EditUserModal extends Modal { - {!this.isActivated() ? ( + {!this.isEmailConfirmed() ? (
{Button.component({ className: 'Button Button--block', @@ -115,11 +115,11 @@ export default class EditUserModal extends Modal { this.loading = true; const data = { username: this.username(), - isActivated: true, + isEmailConfirmed: true, }; this.props.user.save(data, {errorHandler: this.onerror.bind(this)}) .then(() => { - this.isActivated(true); + this.isEmailConfirmed(true); this.loading = false; m.redraw(); }) diff --git a/framework/core/js/src/forum/utils/alertEmailConfirmation.js b/framework/core/js/src/forum/utils/alertEmailConfirmation.js index e3e4582ba..784770cdb 100644 --- a/framework/core/js/src/forum/utils/alertEmailConfirmation.js +++ b/framework/core/js/src/forum/utils/alertEmailConfirmation.js @@ -10,7 +10,7 @@ import icon from '../../common/helpers/icon'; export default function alertEmailConfirmation(app) { const user = app.session.user; - if (!user || user.isActivated()) return; + if (!user || user.isEmailConfirmed()) return; const resendButton = Button.component({ className: 'Button Button--link', diff --git a/framework/core/src/Api/Serializer/CurrentUserSerializer.php b/framework/core/src/Api/Serializer/CurrentUserSerializer.php index 667cd3592..9e88aeff9 100644 --- a/framework/core/src/Api/Serializer/CurrentUserSerializer.php +++ b/framework/core/src/Api/Serializer/CurrentUserSerializer.php @@ -22,7 +22,7 @@ class CurrentUserSerializer extends UserSerializer $attributes = parent::getDefaultAttributes($user); $attributes += [ - 'isActivated' => (bool) $user->is_email_confirmed, + 'isEmailConfirmed' => (bool) $user->is_email_confirmed, 'email' => $user->email, 'readTime' => $this->formatDate($user->marked_all_as_read_at), 'unreadNotificationsCount' => (int) $user->getUnreadNotificationsCount(), diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 9ac6fcb70..95792699d 100644 --- a/framework/core/src/Api/Serializer/UserSerializer.php +++ b/framework/core/src/Api/Serializer/UserSerializer.php @@ -56,8 +56,8 @@ class UserSerializer extends BasicUserSerializer if ($canEdit || $this->actor->id === $user->id) { $attributes += [ - 'isActivated' => (bool) $user->is_email_confirmed, - 'email' => $user->email + 'isEmailConfirmed' => (bool) $user->is_email_confirmed, + 'email' => $user->email ]; } diff --git a/framework/core/src/User/Command/EditUserHandler.php b/framework/core/src/User/Command/EditUserHandler.php index 09bbd69e1..65622990c 100644 --- a/framework/core/src/User/Command/EditUserHandler.php +++ b/framework/core/src/User/Command/EditUserHandler.php @@ -103,7 +103,7 @@ class EditUserHandler } } - if ($actor->isAdmin() && ! empty($attributes['isActivated'])) { + if ($actor->isAdmin() && ! empty($attributes['isEmailConfirmed'])) { $user->activate(); } diff --git a/framework/core/src/User/Command/RegisterUserHandler.php b/framework/core/src/User/Command/RegisterUserHandler.php index 417fd79e0..05029bb70 100644 --- a/framework/core/src/User/Command/RegisterUserHandler.php +++ b/framework/core/src/User/Command/RegisterUserHandler.php @@ -112,7 +112,7 @@ class RegisterUserHandler } } - if ($actor->isAdmin() && array_get($data, 'attributes.isActivated')) { + if ($actor->isAdmin() && array_get($data, 'attributes.isEmailConfirmed')) { $user->activate(); } diff --git a/framework/core/tests/Api/Controller/CreateUserControllerTest.php b/framework/core/tests/Api/Controller/CreateUserControllerTest.php index 772e51700..bbb127943 100644 --- a/framework/core/tests/Api/Controller/CreateUserControllerTest.php +++ b/framework/core/tests/Api/Controller/CreateUserControllerTest.php @@ -66,7 +66,7 @@ class CreateUserControllerTest extends ApiControllerTestCase $this->actor = $this->getAdminUser(); $response = $this->callWith(array_merge($this->data, [ - 'isActivated' => 1 + 'isEmailConfirmed' => 1 ])); $this->assertEquals(201, $response->getStatusCode()); From f9bab0822e11bc44767ecc138210fa59f1b2e66d Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:35:46 +0930 Subject: [PATCH 76/85] Rename user.readTime --- framework/core/js/src/common/models/Discussion.js | 2 +- framework/core/js/src/common/models/User.js | 2 +- framework/core/js/src/forum/components/DiscussionListItem.js | 2 +- framework/core/js/src/forum/components/IndexPage.js | 2 +- framework/core/src/Api/Serializer/CurrentUserSerializer.php | 2 +- framework/core/src/User/Command/EditUserHandler.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/framework/core/js/src/common/models/Discussion.js b/framework/core/js/src/common/models/Discussion.js index 26b5f7ec1..344151f30 100644 --- a/framework/core/js/src/common/models/Discussion.js +++ b/framework/core/js/src/common/models/Discussion.js @@ -67,7 +67,7 @@ Object.assign(Discussion.prototype, { unreadCount() { const user = app.session.user; - if (user && user.readTime() < this.lastPostedAt()) { + if (user && user.markedAllAsReadAt() < this.lastPostedAt()) { return Math.max(0, this.lastPostNumber() - (this.lastReadPostNumber() || 0)); } diff --git a/framework/core/js/src/common/models/User.js b/framework/core/js/src/common/models/User.js index d822307ea..b1d30b68c 100644 --- a/framework/core/js/src/common/models/User.js +++ b/framework/core/js/src/common/models/User.js @@ -21,7 +21,7 @@ Object.assign(User.prototype, { joinTime: Model.attribute('joinTime', Model.transformDate), lastSeenAt: Model.attribute('lastSeenAt', Model.transformDate), - readTime: Model.attribute('readTime', Model.transformDate), + markedAllAsReadAt: Model.attribute('markedAllAsReadAt', Model.transformDate), unreadNotificationsCount: Model.attribute('unreadNotificationsCount'), newNotificationsCount: Model.attribute('newNotificationsCount'), diff --git a/framework/core/js/src/forum/components/DiscussionListItem.js b/framework/core/js/src/forum/components/DiscussionListItem.js index ca4910d86..d11abf4f8 100644 --- a/framework/core/js/src/forum/components/DiscussionListItem.js +++ b/framework/core/js/src/forum/components/DiscussionListItem.js @@ -35,7 +35,7 @@ export default class DiscussionListItem extends Component { this.subtree = new SubtreeRetainer( () => this.props.discussion.freshness, () => { - const time = app.session.user && app.session.user.readTime(); + const time = app.session.user && app.session.user.markedAllAsReadAt(); return time && time.getTime(); }, () => this.active() diff --git a/framework/core/js/src/forum/components/IndexPage.js b/framework/core/js/src/forum/components/IndexPage.js index bfe24de0b..16648663c 100644 --- a/framework/core/js/src/forum/components/IndexPage.js +++ b/framework/core/js/src/forum/components/IndexPage.js @@ -385,7 +385,7 @@ export default class IndexPage extends Page { const confirmation = confirm(app.translator.trans('core.forum.index.mark_all_as_read_confirmation')); if (confirmation) { - app.session.user.save({readTime: new Date()}); + app.session.user.save({markedAllAsReadAt: new Date()}); } } } diff --git a/framework/core/src/Api/Serializer/CurrentUserSerializer.php b/framework/core/src/Api/Serializer/CurrentUserSerializer.php index 9e88aeff9..f947c5598 100644 --- a/framework/core/src/Api/Serializer/CurrentUserSerializer.php +++ b/framework/core/src/Api/Serializer/CurrentUserSerializer.php @@ -24,7 +24,7 @@ class CurrentUserSerializer extends UserSerializer $attributes += [ 'isEmailConfirmed' => (bool) $user->is_email_confirmed, 'email' => $user->email, - 'readTime' => $this->formatDate($user->marked_all_as_read_at), + 'markedAllAsReadAt' => $this->formatDate($user->marked_all_as_read_at), 'unreadNotificationsCount' => (int) $user->getUnreadNotificationsCount(), 'newNotificationsCount' => (int) $user->getNewNotificationsCount(), 'preferences' => (array) $user->preferences diff --git a/framework/core/src/User/Command/EditUserHandler.php b/framework/core/src/User/Command/EditUserHandler.php index 65622990c..6d9d2485d 100644 --- a/framework/core/src/User/Command/EditUserHandler.php +++ b/framework/core/src/User/Command/EditUserHandler.php @@ -114,7 +114,7 @@ class EditUserHandler $validate['password'] = $attributes['password']; } - if (! empty($attributes['readTime'])) { + if (! empty($attributes['markedAllAsReadAt'])) { $this->assertPermission($isSelf); $user->markAllAsRead(); } From eb5b3a048498d91139bd3e0672d64d994be4198e Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:36:33 +0930 Subject: [PATCH 77/85] Rename user.unreadNotificationsCount --- framework/core/js/src/common/models/User.js | 2 +- framework/core/js/src/forum/components/Notification.js | 2 +- framework/core/js/src/forum/components/NotificationList.js | 2 +- framework/core/js/src/forum/components/NotificationsDropdown.js | 2 +- framework/core/src/Api/Serializer/CurrentUserSerializer.php | 2 +- framework/core/src/User/User.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/framework/core/js/src/common/models/User.js b/framework/core/js/src/common/models/User.js index b1d30b68c..4b7ef82b8 100644 --- a/framework/core/js/src/common/models/User.js +++ b/framework/core/js/src/common/models/User.js @@ -22,7 +22,7 @@ Object.assign(User.prototype, { joinTime: Model.attribute('joinTime', Model.transformDate), lastSeenAt: Model.attribute('lastSeenAt', Model.transformDate), markedAllAsReadAt: Model.attribute('markedAllAsReadAt', Model.transformDate), - unreadNotificationsCount: Model.attribute('unreadNotificationsCount'), + unreadNotificationCount: Model.attribute('unreadNotificationCount'), newNotificationsCount: Model.attribute('newNotificationsCount'), discussionCount: Model.attribute('discussionCount'), diff --git a/framework/core/js/src/forum/components/Notification.js b/framework/core/js/src/forum/components/Notification.js index 63d9d668d..0af3f9fec 100644 --- a/framework/core/js/src/forum/components/Notification.js +++ b/framework/core/js/src/forum/components/Notification.js @@ -79,7 +79,7 @@ export default class Notification extends Component { markAsRead() { if (this.props.notification.isRead()) return; - app.session.user.pushAttributes({unreadNotificationsCount: app.session.user.unreadNotificationsCount() - 1}); + app.session.user.pushAttributes({unreadNotificationCount: app.session.user.unreadNotificationCount() - 1}); this.props.notification.save({isRead: true}); } diff --git a/framework/core/js/src/forum/components/NotificationList.js b/framework/core/js/src/forum/components/NotificationList.js index 8d9d12488..12eb83c21 100644 --- a/framework/core/js/src/forum/components/NotificationList.js +++ b/framework/core/js/src/forum/components/NotificationList.js @@ -191,7 +191,7 @@ export default class NotificationList extends Component { markAllAsRead() { if (!app.cache.notifications) return; - app.session.user.pushAttributes({unreadNotificationsCount: 0}); + app.session.user.pushAttributes({unreadNotificationCount: 0}); app.cache.notifications.forEach(notifications => { notifications.forEach(notification => notification.pushAttributes({isRead: true})) diff --git a/framework/core/js/src/forum/components/NotificationsDropdown.js b/framework/core/js/src/forum/components/NotificationsDropdown.js index a8b716dfd..521e1d637 100644 --- a/framework/core/js/src/forum/components/NotificationsDropdown.js +++ b/framework/core/js/src/forum/components/NotificationsDropdown.js @@ -62,7 +62,7 @@ export default class NotificationsDropdown extends Dropdown { } getUnreadCount() { - return app.session.user.unreadNotificationsCount(); + return app.session.user.unreadNotificationCount(); } getNewCount() { diff --git a/framework/core/src/Api/Serializer/CurrentUserSerializer.php b/framework/core/src/Api/Serializer/CurrentUserSerializer.php index f947c5598..298361ce9 100644 --- a/framework/core/src/Api/Serializer/CurrentUserSerializer.php +++ b/framework/core/src/Api/Serializer/CurrentUserSerializer.php @@ -25,7 +25,7 @@ class CurrentUserSerializer extends UserSerializer 'isEmailConfirmed' => (bool) $user->is_email_confirmed, 'email' => $user->email, 'markedAllAsReadAt' => $this->formatDate($user->marked_all_as_read_at), - 'unreadNotificationsCount' => (int) $user->getUnreadNotificationsCount(), + 'unreadNotificationCount' => (int) $user->getUnreadNotificationCount(), 'newNotificationsCount' => (int) $user->getNewNotificationsCount(), 'preferences' => (array) $user->preferences ]; diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index d43a3224c..418db5874 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -417,7 +417,7 @@ class User extends AbstractModel * * @return int */ - public function getUnreadNotificationsCount() + public function getUnreadNotificationCount() { return $this->getUnreadNotifications()->count(); } From 4b931470eda604d28874c3907a57dd93e592d857 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:37:51 +0930 Subject: [PATCH 78/85] Rename user.newNotificationsCount --- framework/core/js/src/common/components/Navigation.js | 2 +- framework/core/js/src/common/models/User.js | 2 +- framework/core/js/src/forum/components/NotificationList.js | 4 ++-- .../core/js/src/forum/components/NotificationsDropdown.js | 2 +- framework/core/src/Api/Serializer/CurrentUserSerializer.php | 2 +- framework/core/src/User/User.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/framework/core/js/src/common/components/Navigation.js b/framework/core/js/src/common/components/Navigation.js index f9c752574..77f52995c 100644 --- a/framework/core/js/src/common/components/Navigation.js +++ b/framework/core/js/src/common/components/Navigation.js @@ -95,7 +95,7 @@ export default class Navigation extends Component { return Button.component({ className: 'Button Button--icon Navigation-drawer' + - (user && user.newNotificationsCount() ? ' new' : ''), + (user && user.newNotificationCount() ? ' new' : ''), onclick: e => { e.stopPropagation(); drawer.show(); diff --git a/framework/core/js/src/common/models/User.js b/framework/core/js/src/common/models/User.js index 4b7ef82b8..d9754606f 100644 --- a/framework/core/js/src/common/models/User.js +++ b/framework/core/js/src/common/models/User.js @@ -23,7 +23,7 @@ Object.assign(User.prototype, { lastSeenAt: Model.attribute('lastSeenAt', Model.transformDate), markedAllAsReadAt: Model.attribute('markedAllAsReadAt', Model.transformDate), unreadNotificationCount: Model.attribute('unreadNotificationCount'), - newNotificationsCount: Model.attribute('newNotificationsCount'), + newNotificationCount: Model.attribute('newNotificationCount'), discussionCount: Model.attribute('discussionCount'), commentCount: Model.attribute('commentCount'), diff --git a/framework/core/js/src/forum/components/NotificationList.js b/framework/core/js/src/forum/components/NotificationList.js index 12eb83c21..eebd8032b 100644 --- a/framework/core/js/src/forum/components/NotificationList.js +++ b/framework/core/js/src/forum/components/NotificationList.js @@ -137,7 +137,7 @@ export default class NotificationList extends Component { * been loaded. */ load() { - if (app.session.user.newNotificationsCount()) { + if (app.session.user.newNotificationCount()) { delete app.cache.notifications; } @@ -145,7 +145,7 @@ export default class NotificationList extends Component { return; } - app.session.user.pushAttributes({newNotificationsCount: 0}); + app.session.user.pushAttributes({newNotificationCount: 0}); this.loadMore(); } diff --git a/framework/core/js/src/forum/components/NotificationsDropdown.js b/framework/core/js/src/forum/components/NotificationsDropdown.js index 521e1d637..d185c4a5f 100644 --- a/framework/core/js/src/forum/components/NotificationsDropdown.js +++ b/framework/core/js/src/forum/components/NotificationsDropdown.js @@ -66,7 +66,7 @@ export default class NotificationsDropdown extends Dropdown { } getNewCount() { - return app.session.user.newNotificationsCount(); + return app.session.user.newNotificationCount(); } menuClick(e) { diff --git a/framework/core/src/Api/Serializer/CurrentUserSerializer.php b/framework/core/src/Api/Serializer/CurrentUserSerializer.php index 298361ce9..cea92bca2 100644 --- a/framework/core/src/Api/Serializer/CurrentUserSerializer.php +++ b/framework/core/src/Api/Serializer/CurrentUserSerializer.php @@ -26,7 +26,7 @@ class CurrentUserSerializer extends UserSerializer 'email' => $user->email, 'markedAllAsReadAt' => $this->formatDate($user->marked_all_as_read_at), 'unreadNotificationCount' => (int) $user->getUnreadNotificationCount(), - 'newNotificationsCount' => (int) $user->getNewNotificationsCount(), + 'newNotificationCount' => (int) $user->getNewNotificationCount(), 'preferences' => (array) $user->preferences ]; diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 418db5874..fb999ad95 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -447,7 +447,7 @@ class User extends AbstractModel * * @return int */ - public function getNewNotificationsCount() + public function getNewNotificationCount() { return $this->getUnreadNotifications()->filter(function ($notification) { return $notification->created_at > $this->read_notifications_at ?: 0; From 3a21b44a71014f1596c2496d777fa2bd2b385c02 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:40:33 +0930 Subject: [PATCH 79/85] Rename notification.time --- framework/core/js/src/forum/components/Notification.js | 2 +- framework/core/src/Api/Serializer/NotificationSerializer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/js/src/forum/components/Notification.js b/framework/core/js/src/forum/components/Notification.js index 0af3f9fec..37448b262 100644 --- a/framework/core/js/src/forum/components/Notification.js +++ b/framework/core/js/src/forum/components/Notification.js @@ -29,7 +29,7 @@ export default class Notification extends Component { {avatar(notification.sender())} {icon(this.icon(), {className: 'Notification-icon'})} {this.content()} - {humanTime(notification.time())} + {humanTime(notification.createdAt())}
{this.excerpt()}
diff --git a/framework/core/src/Api/Serializer/NotificationSerializer.php b/framework/core/src/Api/Serializer/NotificationSerializer.php index 03a8d898a..bf45c87ce 100644 --- a/framework/core/src/Api/Serializer/NotificationSerializer.php +++ b/framework/core/src/Api/Serializer/NotificationSerializer.php @@ -47,7 +47,7 @@ class NotificationSerializer extends AbstractSerializer 'id' => (int) $notification->id, 'contentType' => $notification->type, 'content' => $notification->data, - 'time' => $this->formatDate($notification->created_at), + 'createdAt' => $this->formatDate($notification->created_at), 'isRead' => (bool) $notification->read_at ]; } From f0d296bfb0e77fe2127d3535ca6dce5ce56d0d8d Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:46:28 +0930 Subject: [PATCH 80/85] Rename notification.sender --- framework/core/js/src/common/models/Notification.js | 2 +- .../js/src/forum/components/DiscussionRenamedNotification.js | 2 +- framework/core/js/src/forum/components/Notification.js | 2 +- .../core/src/Api/Controller/ListNotificationsController.php | 2 +- framework/core/src/Api/Serializer/NotificationSerializer.php | 2 +- .../core/src/Notification/Blueprint/BlueprintInterface.php | 2 +- .../src/Notification/Blueprint/DiscussionRenamedBlueprint.php | 2 +- framework/core/src/Notification/Notification.php | 4 ++-- framework/core/src/Notification/NotificationSyncer.php | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/framework/core/js/src/common/models/Notification.js b/framework/core/js/src/common/models/Notification.js index 8ff48f30d..ad6cff6db 100644 --- a/framework/core/js/src/common/models/Notification.js +++ b/framework/core/js/src/common/models/Notification.js @@ -14,6 +14,6 @@ Object.assign(Notification.prototype, { additionalUnreadCount: computed('unreadCount', unreadCount => Math.max(0, unreadCount - 1)), user: Model.hasOne('user'), - sender: Model.hasOne('sender'), + fromUser: Model.hasOne('fromUser'), subject: Model.hasOne('subject') }); diff --git a/framework/core/js/src/forum/components/DiscussionRenamedNotification.js b/framework/core/js/src/forum/components/DiscussionRenamedNotification.js index d74b7966b..9979d7d4d 100644 --- a/framework/core/js/src/forum/components/DiscussionRenamedNotification.js +++ b/framework/core/js/src/forum/components/DiscussionRenamedNotification.js @@ -20,6 +20,6 @@ export default class DiscussionRenamedNotification extends Notification { } content() { - return app.translator.trans('core.forum.notifications.discussion_renamed_text', {user: this.props.notification.sender()}); + return app.translator.trans('core.forum.notifications.discussion_renamed_text', {user: this.props.notification.fromUser()}); } } diff --git a/framework/core/js/src/forum/components/Notification.js b/framework/core/js/src/forum/components/Notification.js index 37448b262..7ebc3fc28 100644 --- a/framework/core/js/src/forum/components/Notification.js +++ b/framework/core/js/src/forum/components/Notification.js @@ -26,7 +26,7 @@ export default class Notification extends Component { if (!isInitialized) $(element).click(this.markAsRead.bind(this)); }}> - {avatar(notification.sender())} + {avatar(notification.fromUser())} {icon(this.icon(), {className: 'Notification-icon'})} {this.content()} {humanTime(notification.createdAt())} diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index b1bec9718..8a5a5ef7d 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -30,7 +30,7 @@ class ListNotificationsController extends AbstractListController * {@inheritdoc} */ public $include = [ - 'sender', + 'fromUser', 'subject', 'subject.discussion' ]; diff --git a/framework/core/src/Api/Serializer/NotificationSerializer.php b/framework/core/src/Api/Serializer/NotificationSerializer.php index bf45c87ce..deaeeddbe 100644 --- a/framework/core/src/Api/Serializer/NotificationSerializer.php +++ b/framework/core/src/Api/Serializer/NotificationSerializer.php @@ -65,7 +65,7 @@ class NotificationSerializer extends AbstractSerializer * @param Notification $notification * @return \Tobscure\JsonApi\Relationship */ - protected function sender($notification) + protected function fromUser($notification) { return $this->hasOne($notification, BasicUserSerializer::class); } diff --git a/framework/core/src/Notification/Blueprint/BlueprintInterface.php b/framework/core/src/Notification/Blueprint/BlueprintInterface.php index ed8273396..600a8d941 100644 --- a/framework/core/src/Notification/Blueprint/BlueprintInterface.php +++ b/framework/core/src/Notification/Blueprint/BlueprintInterface.php @@ -23,7 +23,7 @@ interface BlueprintInterface * * @return \Flarum\User\User|null */ - public function getSender(); + public function getFromUser(); /** * Get the model that is the subject of this activity. diff --git a/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php index 50d2e6146..7e79026b9 100644 --- a/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php +++ b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php @@ -32,7 +32,7 @@ class DiscussionRenamedBlueprint implements BlueprintInterface /** * {@inheritdoc} */ - public function getSender() + public function getFromUser() { return $this->post->user; } diff --git a/framework/core/src/Notification/Notification.php b/framework/core/src/Notification/Notification.php index c36bff190..bf299b035 100644 --- a/framework/core/src/Notification/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -31,7 +31,7 @@ use Flarum\User\User; * * @property int $id * @property int $user_id - * @property int|null $sender_id + * @property int|null $from_user_id * @property string $type * @property int|null $subject_id * @property mixed|null $data @@ -39,7 +39,7 @@ use Flarum\User\User; * @property \Carbon\Carbon $read_at * @property \Carbon\Carbon $deleted_at * @property \Flarum\User\User|null $user - * @property \Flarum\User\User|null $sender + * @property \Flarum\User\User|null $fromUser * @property \Flarum\Database\AbstractModel|null $subject */ class Notification extends AbstractModel diff --git a/framework/core/src/Notification/NotificationSyncer.php b/framework/core/src/Notification/NotificationSyncer.php index a8cdd66ab..20bcca6a9 100644 --- a/framework/core/src/Notification/NotificationSyncer.php +++ b/framework/core/src/Notification/NotificationSyncer.php @@ -226,7 +226,7 @@ class NotificationSyncer { return [ 'type' => $blueprint::getType(), - 'from_user_id' => ($sender = $blueprint->getSender()) ? $sender->id : null, + 'from_user_id' => ($fromUser = $blueprint->getFromUser()) ? $fromUser->id : null, 'subject_id' => ($subject = $blueprint->getSubject()) ? $subject->id : null, 'data' => ($data = $blueprint->getData()) ? json_encode($data) : null ]; From ad33638a991158df856c970f67c59b134cc44263 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:47:57 +0930 Subject: [PATCH 81/85] Fix up Notification model --- framework/core/js/src/common/models/Notification.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/framework/core/js/src/common/models/Notification.js b/framework/core/js/src/common/models/Notification.js index ad6cff6db..b324addcd 100644 --- a/framework/core/js/src/common/models/Notification.js +++ b/framework/core/js/src/common/models/Notification.js @@ -1,17 +1,13 @@ import Model from '../Model'; -import computed from '../utils/computed'; export default class Notification extends Model {} Object.assign(Notification.prototype, { contentType: Model.attribute('contentType'), - subjectId: Model.attribute('subjectId'), content: Model.attribute('content'), - time: Model.attribute('time', Model.date), + createdAt: Model.attribute('createdAt', Model.transformDate), isRead: Model.attribute('isRead'), - unreadCount: Model.attribute('unreadCount'), - additionalUnreadCount: computed('unreadCount', unreadCount => Math.max(0, unreadCount - 1)), user: Model.hasOne('user'), fromUser: Model.hasOne('fromUser'), From d51a779241968e3bd56c08a6c6f49626fce9b55a Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:58:17 +0930 Subject: [PATCH 82/85] Missed a spot --- framework/core/src/Notification/Notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Notification/Notification.php b/framework/core/src/Notification/Notification.php index bf299b035..eab6ad5db 100644 --- a/framework/core/src/Notification/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -120,7 +120,7 @@ class Notification extends AbstractModel * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function sender() + public function fromUser() { return $this->belongsTo(User::class, 'from_user_id'); } From 5778edb5efc90057839d4aa8bfb4c2fef300eaed Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 21:59:47 +0930 Subject: [PATCH 83/85] Rename user methods --- framework/core/src/User/User.php | 4 ++-- framework/core/src/User/UserMetadataUpdater.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index fb999ad95..8439cd65a 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -743,7 +743,7 @@ class User extends AbstractModel * * @return $this */ - public function refreshCommentsCount() + public function refreshCommentCount() { $this->comment_count = $this->posts()->count(); @@ -755,7 +755,7 @@ class User extends AbstractModel * * @return $this */ - public function refreshDiscussionsCount() + public function refreshDiscussionCount() { $this->discussion_count = $this->discussions()->count(); diff --git a/framework/core/src/User/UserMetadataUpdater.php b/framework/core/src/User/UserMetadataUpdater.php index 16367ee1b..713c3fa27 100644 --- a/framework/core/src/User/UserMetadataUpdater.php +++ b/framework/core/src/User/UserMetadataUpdater.php @@ -69,7 +69,7 @@ class UserMetadataUpdater $user = $post->user; if ($user && $user->exists) { - $user->refreshCommentsCount()->save(); + $user->refreshCommentCount()->save(); } } @@ -78,7 +78,7 @@ class UserMetadataUpdater $user = $discussion->user; if ($user && $user->exists) { - $user->refreshDiscussionsCount()->save(); + $user->refreshDiscussionCount()->save(); } } } From cd4d22e42bf63383a4a9b3b533d5781a0dadfec4 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 15 Sep 2018 12:40:32 +0930 Subject: [PATCH 84/85] Inline permissions migration --- ..._000100_seed_default_group_permissions.php | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php b/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php index 1349910e9..ad40f5e03 100644 --- a/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php +++ b/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php @@ -9,22 +9,44 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Flarum\Group\Group; +use Illuminate\Database\Schema\Builder; -return Migration::addPermissions([ +$rows = [ // Guests can view the forum - 'viewDiscussions' => Group::GUEST_ID, + ['permission' => 'viewDiscussions', 'group_id' => Group::GUEST_ID], // Members can create and reply to discussions, and view the user list - 'startDiscussion' => Group::MEMBER_ID, - 'discussion.reply' => Group::MEMBER_ID, - 'viewUserList' => Group::MEMBER_ID, + ['permission' => 'startDiscussion', 'group_id' => Group::MEMBER_ID], + ['permission' => 'discussion.reply', 'group_id' => Group::MEMBER_ID], + ['permission' => 'viewUserList', 'group_id' => Group::MEMBER_ID], // Moderators can edit + delete stuff - 'discussion.hide' => Group::MODERATOR_ID, - 'discussion.editPosts' => Group::MODERATOR_ID, - 'discussion.hidePosts' => Group::MODERATOR_ID, - 'discussion.rename' => Group::MODERATOR_ID, - 'discussion.viewIpsPosts' => Group::MODERATOR_ID, -]); + ['permission' => 'discussion.hide', 'group_id' => Group::MODERATOR_ID], + ['permission' => 'discussion.editPosts', 'group_id' => Group::MODERATOR_ID], + ['permission' => 'discussion.hidePosts', 'group_id' => Group::MODERATOR_ID], + ['permission' => 'discussion.rename', 'group_id' => Group::MODERATOR_ID], + ['permission' => 'discussion.viewIpsPosts', 'group_id' => Group::MODERATOR_ID], +]; + +return [ + 'up' => function (Builder $schema) use ($rows) { + $db = $schema->getConnection(); + + foreach ($rows as $row) { + if ($db->table('groups')->where('id', $row['group_id'])->doesntExist()) { + continue; + } + + $db->table('group_permission')->updateOrInsert($row); + } + }, + + 'down' => function (Builder $schema) use ($rows) { + $db = $schema->getConnection(); + + foreach ($rows as $row) { + $db->table('group_permission')->where($row)->delete(); + } + } +]; From a7f429721476c24181bb5a4bcdae404524588e98 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 15 Sep 2018 12:44:59 +0930 Subject: [PATCH 85/85] Fix query error --- .../2018_07_21_000100_seed_default_group_permissions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php b/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php index ad40f5e03..5a82d70fe 100644 --- a/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php +++ b/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php @@ -38,7 +38,9 @@ return [ continue; } - $db->table('group_permission')->updateOrInsert($row); + if ($db->table('group_permission')->where($row)->doesntExist()) { + $db->table('group_permission')->insert($row); + } } },