From 23b8accecc80de7fa88353749b9c0a52186d8eec Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Mon, 18 Nov 2024 17:37:39 -0500 Subject: [PATCH 1/2] Updated duplicates documentation --- DUPLICATES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DUPLICATES.md b/DUPLICATES.md index 06c8fd9e3a..d5f71a7701 100644 --- a/DUPLICATES.md +++ b/DUPLICATES.md @@ -5,8 +5,8 @@ Because of how this database is created (by importing data from an anime databas # How to clean duplicates -Since the data changes over time, in general, when a duplicate entry is created, that generally means the old entry has been removed/changed, with the newer one being the only one in the anime database JSON file. Since the older entry does not exist in the anime database JSON file anymore, that generally means we should delete the older entry. Cleaning the database of duplicate entries is a manual process, becasue it should be a manual process in order to verify an entry truly is a duplicate. Once we are sure it is a duplicate, we have a command we can run to replace the old anime with a new anime, it is: `php artisan app:merge-anime-duplicate oldAnimeId newAnimeId` so it would look like `php artisan app:merge-anime-duplicate 29164 40755`, it will display the details for both IDs and confirm you wish to merge them into the new ID. +Since the data changes over time, in general, when a duplicate entry is created, that generally means the old entry has been removed/changed, with the newer one being the only one in the anime database JSON file. Since the older entry does not exist in the anime database JSON file anymore, that generally means we should delete the older entry. Cleaning the database of duplicate entries is a manual process, becasue it should be a manual process in order to verify an entry truly is a duplicate. Once we are sure it is a duplicate, we have a command we can run to replace the old anime with a new anime, it is: `php artisan app:merge-anime-duplicate oldAnimeId newAnimeId` so it would look like `php artisan app:merge-anime-duplicate 29164 40755`, it will display the details for both IDs and confirm you wish to merge them into the new ID. Alternatively, there is a `php artisan app:delete-anime animeId` for deleting any anime that doesn't have any reviews and doesn't belong in any list to force it to be re-imported from scratch, although this may never end up being necessary it's still nice to have that option. # How to find duplicates -We have a command to find possible duplicate anime entries, it is: `php artisan app:check-anime-duplicates` and it generates 3 CSV files you can look through to find any possible duplicate anime entries. +We have a command to find possible duplicate anime entries, it is: `php artisan app:check-anime-duplicates` and it generates 3 CSV files you can look through to find any possible duplicate anime entries. Keep in mind that the check-anime-duplicates command will not always find all duplicates, sometimes you will randomly find them through the regular anime search on the site and notice . Higher ID number in the SQL database usually means it's a newer anime, but not always. For example, I have seen an example of a higher SQL database ID anime having status ONGOING whereas a duplicate lower SQL database ID anime has status FINISHED, but the status ONGOING one with the higher ID has a higher quality picture. This means that SQL database ID is not reliable for identifying duplicates, and sometimes detailed manual checking has to be done. When in doubt, the best way seems to be manually checking the title and picture URL in the anime database JSON file and going with that one as the "latest" and the others would be considered duplicates and merged into the new one. When running the recommended import command, the anime descriptions and images should always be downloaded, both for existing and new anime, so it is generally considered fine to merge duplicate old anime entries into a new anime entry. Finally, it's worth mentioning that while duplicate anime is usually caused by the import process adding a new anime entry rather than updating an existing anime entry, it is also possible for the anime database JSON file to have duplicate entries itself, although this is usually quite rare, it's still worth double checking searching for keywords of a title and seeing if there are multiple duplicate entries in the anime database JSON file itself. \ No newline at end of file From cd53e1a5dcf6134a682afa49355a5cc179434bb7 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Mon, 18 Nov 2024 17:38:22 -0500 Subject: [PATCH 2/2] Added delete-anime command --- app/Console/Commands/DeleteAnime.php | 103 +++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 app/Console/Commands/DeleteAnime.php diff --git a/app/Console/Commands/DeleteAnime.php b/app/Console/Commands/DeleteAnime.php new file mode 100644 index 0000000000..57f73541bc --- /dev/null +++ b/app/Console/Commands/DeleteAnime.php @@ -0,0 +1,103 @@ +argument('animeId'); + + $this->info("Fetching details for anime ID $animeId..."); + + // Fetch the anime details + $anime = DB::table('anime')->find($animeId); + + if (!$anime) { + $this->error('Anime ID is invalid or does not exist.'); + return; + } + + // Display details of the anime + $this->displayAnimeDetails($anime); + + // Confirm the deletion with user input + if (!$this->confirmDelete()) { + $this->info('Delete operation cancelled.'); + return; + } + + $this->info("Deleting anime ID $animeId..."); + + try { + DB::beginTransaction(); + + // Delete references in anime_user table + DB::table('anime_user')->where('anime_id', $animeId)->delete(); + $this->info("Deleted references from anime_user table."); + + // Delete references in anime_reviews table + DB::table('anime_reviews')->where('anime_id', $animeId)->delete(); + $this->info("Deleted references from anime_reviews table."); + + // Delete the anime record itself + DB::table('anime')->where('id', $animeId)->delete(); + $this->info("Deleted anime record with ID $animeId."); + + DB::commit(); + + $this->info("Anime ID $animeId has been successfully deleted."); + } catch (\Exception $e) { + DB::rollBack(); + $this->error("An error occurred while deleting anime ID $animeId: " . $e->getMessage()); + Log::error("Error deleting anime ID $animeId: " . $e->getMessage()); + } + } + + /** + * Display anime details. + */ + private function displayAnimeDetails($anime) + { + $this->info("---- Anime Details ----"); + $this->info("ID: $anime->id"); + $this->info("Title: $anime->title"); + $this->info("Year: " . ($anime->year ?? 'UNKNOWN')); + $this->info("Season: " . ($anime->season ?? 'UNKNOWN')); + $this->info("Type: " . ($anime->anime_type_id ?? 'UNKNOWN')); + $this->info("Episodes: " . ($anime->episodes ?? 'UNKNOWN')); + $this->info("Synonyms: " . ($anime->synonyms ?? 'NONE')); + $this->info("-----------------------"); + } + + /** + * Confirm the deletion by asking for user input. + */ + private function confirmDelete() + { + $confirmation = $this->ask('Type "yes" to confirm the deletion'); + + return strtolower($confirmation) === 'yes'; + } +} \ No newline at end of file