From 38a0fd30feaef8d649e3639ff691485658458240 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 12 Aug 2019 02:46:51 -0600 Subject: [PATCH] Add new command --- app/Console/Commands/StatusDedupe.php | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 app/Console/Commands/StatusDedupe.php diff --git a/app/Console/Commands/StatusDedupe.php b/app/Console/Commands/StatusDedupe.php new file mode 100644 index 000000000..c7c9b811c --- /dev/null +++ b/app/Console/Commands/StatusDedupe.php @@ -0,0 +1,62 @@ +selectRaw('id, uri, count(uri) as occurences') + ->whereNotNull('uri') + ->groupBy('uri') + ->orderBy('created_at') + ->having('occurences', '>', 1) + ->chunk(50, function($statuses) { + foreach($statuses as $status) { + $this->info("Found duplicate: $status->uri"); + Status::whereUri($status->uri) + ->where('id', '!=', $status->id) + ->get() + ->map(function($status) { + $this->info("Deleting Duplicate ID: $status->id"); + StatusDelete::dispatch($status); + }); + } + }); + } +}