From 863ec3c91bbd136e8e1343ece9ef5b841996d86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sat, 21 Sep 2024 00:15:50 +0000 Subject: [PATCH] Revert migrations --- ...44_replace_emoji_shorcuts_with_unicode.php | 101 ++++++++++++++++++ .../2018_09_15_041340_add_users_indicies.php | 31 ++++++ ..._09_15_041828_add_discussions_indicies.php | 37 +++++++ framework/core/migrations/mysql-install.dump | 4 +- framework/core/migrations/pgsql-install.dump | 4 +- framework/core/migrations/sqlite-install.dump | 4 +- 6 files changed, 175 insertions(+), 6 deletions(-) create mode 100644 extensions/emoji/migrations/2018_09_29_060444_replace_emoji_shorcuts_with_unicode.php create mode 100644 framework/core/migrations/2018_09_15_041340_add_users_indicies.php create mode 100644 framework/core/migrations/2018_09_15_041828_add_discussions_indicies.php diff --git a/extensions/emoji/migrations/2018_09_29_060444_replace_emoji_shorcuts_with_unicode.php b/extensions/emoji/migrations/2018_09_29_060444_replace_emoji_shorcuts_with_unicode.php new file mode 100644 index 0000000000..b5c025e511 --- /dev/null +++ b/extensions/emoji/migrations/2018_09_29_060444_replace_emoji_shorcuts_with_unicode.php @@ -0,0 +1,101 @@ + function (Builder $schema) { + $emojioneToTwemojiMap = [ + '1f468-2764-1f468' => '1f468-200d-2764-fe0f-200d-1f468', + '1f469-2764-1f469' => '1f469-200d-2764-fe0f-200d-1f469', + '1f468-2764-1f48b-1f468' => '1f468-200d-2764-fe0f-200d-1f48b-200d-1f468', + '1f469-2764-1f48b-1f469' => '1f469-200d-2764-fe0f-200d-1f48b-200d-1f469', + '1f468-1f468-1f466' => '1f468-200d-1f468-200d-1f466', + '1f468-1f468-1f466-1f466' => '1f468-200d-1f468-200d-1f466-200d-1f466', + '1f468-1f468-1f467' => '1f468-200d-1f468-200d-1f467', + '1f468-1f468-1f467-1f466' => '1f468-200d-1f468-200d-1f467-200d-1f466', + '1f468-1f468-1f467-1f467' => '1f468-200d-1f468-200d-1f467-200d-1f467', + '1f468-1f469-1f466-1f466' => '1f468-200d-1f469-200d-1f466-200d-1f466', + '1f468-1f469-1f467' => '1f468-200d-1f469-200d-1f467', + '1f468-1f469-1f467-1f466' => '1f468-200d-1f469-200d-1f467-200d-1f466', + '1f468-1f469-1f467-1f467' => '1f468-200d-1f469-200d-1f467-200d-1f467', + '1f469-1f469-1f466' => '1f469-200d-1f469-200d-1f466', + '1f469-1f469-1f466-1f466' => '1f469-200d-1f469-200d-1f466-200d-1f466', + '1f469-1f469-1f467' => '1f469-200d-1f469-200d-1f467', + '1f469-1f469-1f467-1f466' => '1f469-200d-1f469-200d-1f467-200d-1f466', + '1f469-1f469-1f467-1f467' => '1f469-200d-1f469-200d-1f467-200d-1f467', + '1f441-1f5e8' => '1f441-200d-1f5e8', // as always PITA + '1f3f3-1f308' => '1f3f3-fe0f-200d-1f308', + + // https://github.com/twitter/twemoji/issues/192 + '1f91d-1f3fb' => '1f91d', + '1f91d-1f3fc' => '1f91d', + '1f91d-1f3fd' => '1f91d', + '1f91d-1f3fe' => '1f91d', + '1f91d-1f3ff' => '1f91d', + '1f93c-1f3fb' => '1f93c', + '1f93c-1f3fc' => '1f93c', + '1f93c-1f3fd' => '1f93c', + '1f93c-1f3fe' => '1f93c', + '1f93c-1f3ff' => '1f93c', + ]; + + $fromCodePoint = function ($code) { + $num = intval($code, 16); + + if ($num <= 0x7F) { + return chr($num); + } + + if ($num <= 0x7FF) { + return chr(($num >> 6) + 192).chr(($num & 63) + 128); + } + + if ($num <= 0xFFFF) { + return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); + } + + return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); + }; + + $convertEmojioneToTwemoji = function ($code) use ($emojioneToTwemojiMap) { + if (isset($emojioneToTwemojiMap[$code])) { + return $emojioneToTwemojiMap[$code]; + } + + return ltrim($code, '0'); + }; + + $posts = $schema->getConnection()->table('posts') + ->select('id', 'content') + ->where('content', 'like', '%cursor(); + + foreach ($posts as $post) { + $content = preg_replace_callback( + '/.+?<\/EMOJI>/', + function ($m) use ($convertEmojioneToTwemoji, $fromCodePoint) { + $code = $convertEmojioneToTwemoji($m[1]); + $codepoints = explode('-', $code); + + return implode('', array_map($fromCodePoint, $codepoints)); + }, + $post->content + ); + + $schema->getConnection()->table('posts') + ->where('id', $post->id) + ->update(['content' => $content]); + } + }, + + 'down' => function (Builder $schema) { + // not implemented + } +]; diff --git a/framework/core/migrations/2018_09_15_041340_add_users_indicies.php b/framework/core/migrations/2018_09_15_041340_add_users_indicies.php new file mode 100644 index 0000000000..15a9d6931b --- /dev/null +++ b/framework/core/migrations/2018_09_15_041340_add_users_indicies.php @@ -0,0 +1,31 @@ + function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->index('joined_at'); + $table->index('last_seen_at'); + $table->index('discussion_count'); + $table->index('comment_count'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->dropIndex(['joined_at']); + $table->dropIndex(['last_seen_at']); + $table->dropIndex(['discussion_count']); + $table->dropIndex(['comment_count']); + }); + } +]; diff --git a/framework/core/migrations/2018_09_15_041828_add_discussions_indicies.php b/framework/core/migrations/2018_09_15_041828_add_discussions_indicies.php new file mode 100644 index 0000000000..8a74b08d94 --- /dev/null +++ b/framework/core/migrations/2018_09_15_041828_add_discussions_indicies.php @@ -0,0 +1,37 @@ + function (Builder $schema) { + $schema->table('discussions', function (Blueprint $table) { + $table->index('last_posted_at'); + $table->index('last_posted_user_id'); + $table->index('created_at'); + $table->index('user_id'); + $table->index('comment_count'); + $table->index('participant_count'); + $table->index('hidden_at'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('discussions', function (Blueprint $table) { + $table->dropIndex(['last_posted_at']); + $table->dropIndex(['last_posted_user_id']); + $table->dropIndex(['created_at']); + $table->dropIndex(['user_id']); + $table->dropIndex(['comment_count']); + $table->dropIndex(['participant_count']); + $table->dropIndex(['hidden_at']); + }); + } +]; diff --git a/framework/core/migrations/mysql-install.dump b/framework/core/migrations/mysql-install.dump index ec5d82ccc6..a3146d149a 100644 --- a/framework/core/migrations/mysql-install.dump +++ b/framework/core/migrations/mysql-install.dump @@ -350,8 +350,8 @@ INSERT INTO `db_prefix_migrations` VALUES (49,'2018_01_18_135100_change_posts_ad INSERT INTO `db_prefix_migrations` VALUES (50,'2018_01_30_112238_add_fulltext_index_to_discussions_title',NULL); INSERT INTO `db_prefix_migrations` VALUES (51,'2018_01_30_220100_create_post_user_table',NULL); INSERT INTO `db_prefix_migrations` VALUES (52,'2018_01_30_222900_change_users_rename_columns',NULL); -INSERT INTO `db_prefix_migrations` VALUES (55,'2018_09_15_041340_add_users_indices',NULL); -INSERT INTO `db_prefix_migrations` VALUES (56,'2018_09_15_041828_add_discussions_indices',NULL); +INSERT INTO `db_prefix_migrations` VALUES (55,'2018_09_15_041340_add_users_indicies',NULL); +INSERT INTO `db_prefix_migrations` VALUES (56,'2018_09_15_041828_add_discussions_indicies',NULL); INSERT INTO `db_prefix_migrations` VALUES (57,'2018_09_15_043337_add_notifications_indices',NULL); INSERT INTO `db_prefix_migrations` VALUES (58,'2018_09_15_043621_add_posts_indices',NULL); INSERT INTO `db_prefix_migrations` VALUES (59,'2018_09_22_004100_change_registration_tokens_columns',NULL); diff --git a/framework/core/migrations/pgsql-install.dump b/framework/core/migrations/pgsql-install.dump index 7b3ceed193..760c0b82dd 100644 --- a/framework/core/migrations/pgsql-install.dump +++ b/framework/core/migrations/pgsql-install.dump @@ -1207,8 +1207,8 @@ INSERT INTO public.db_prefix_migrations VALUES (49,'2018_01_18_135100_change_pos INSERT INTO public.db_prefix_migrations VALUES (50,'2018_01_30_112238_add_fulltext_index_to_discussions_title',NULL); INSERT INTO public.db_prefix_migrations VALUES (51,'2018_01_30_220100_create_post_user_table',NULL); INSERT INTO public.db_prefix_migrations VALUES (52,'2018_01_30_222900_change_users_rename_columns',NULL); -INSERT INTO public.db_prefix_migrations VALUES (55,'2018_09_15_041340_add_users_indices',NULL); -INSERT INTO public.db_prefix_migrations VALUES (56,'2018_09_15_041828_add_discussions_indices',NULL); +INSERT INTO public.db_prefix_migrations VALUES (55,'2018_09_15_041340_add_users_indicies',NULL); +INSERT INTO public.db_prefix_migrations VALUES (56,'2018_09_15_041828_add_discussions_indicies',NULL); INSERT INTO public.db_prefix_migrations VALUES (57,'2018_09_15_043337_add_notifications_indices',NULL); INSERT INTO public.db_prefix_migrations VALUES (58,'2018_09_15_043621_add_posts_indices',NULL); INSERT INTO public.db_prefix_migrations VALUES (59,'2018_09_22_004100_change_registration_tokens_columns',NULL); diff --git a/framework/core/migrations/sqlite-install.dump b/framework/core/migrations/sqlite-install.dump index e1354a4e1c..6a4cda4bc9 100644 --- a/framework/core/migrations/sqlite-install.dump +++ b/framework/core/migrations/sqlite-install.dump @@ -105,8 +105,8 @@ INSERT INTO db_prefix_migrations VALUES(49,'2018_01_18_135100_change_posts_add_f INSERT INTO db_prefix_migrations VALUES(50,'2018_01_30_112238_add_fulltext_index_to_discussions_title',NULL); INSERT INTO db_prefix_migrations VALUES(51,'2018_01_30_220100_create_post_user_table',NULL); INSERT INTO db_prefix_migrations VALUES(52,'2018_01_30_222900_change_users_rename_columns',NULL); -INSERT INTO db_prefix_migrations VALUES(55,'2018_09_15_041340_add_users_indices',NULL); -INSERT INTO db_prefix_migrations VALUES(56,'2018_09_15_041828_add_discussions_indices',NULL); +INSERT INTO db_prefix_migrations VALUES(55,'2018_09_15_041340_add_users_indicies',NULL); +INSERT INTO db_prefix_migrations VALUES(56,'2018_09_15_041828_add_discussions_indicies',NULL); INSERT INTO db_prefix_migrations VALUES(57,'2018_09_15_043337_add_notifications_indices',NULL); INSERT INTO db_prefix_migrations VALUES(58,'2018_09_15_043621_add_posts_indices',NULL); INSERT INTO db_prefix_migrations VALUES(59,'2018_09_22_004100_change_registration_tokens_columns',NULL);