From 0c11ceaaa2c947e29de4dd0d3c22b5b566445166 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sun, 13 Jun 2021 22:56:13 +0800 Subject: [PATCH] update: add attendance migrate --- app/Console/Commands/Test.php | 27 +-------------------------- include/functions.php | 2 +- nexus/Install/Update.php | 12 +++++------- 3 files changed, 7 insertions(+), 34 deletions(-) diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index dee01084..415434a2 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -53,32 +53,7 @@ class Test extends Command */ public function handle() { - $page = 1; - $size = 1000; - while (true) { - $logPrefix = "[MIGRATE_ATTENDANCE], page: $page, size: $size"; - $result = Attendance::query() - ->groupBy(['uid']) - ->selectRaw('uid, max(id) as id, count(*) as counts') - ->forPage($page, $size) - ->get(); - do_log("$logPrefix, " . last_query() . ", count: " . $result->count()); - if ($result->isEmpty()) { - do_log("$logPrefix, no more data..."); - break; - } - foreach ($result as $row) { - $update = [ - 'total_days' => $row->counts, - ]; - $updateResult = $row->update($update); - do_log(sprintf( - "$logPrefix, update user: %s(ID: %s) => %s, result: %s", - $row->uid, $row->id, json_encode($update), var_export($updateResult, true) - )); - } - $page++; - } + } } diff --git a/include/functions.php b/include/functions.php index 8b2fa51e..60efbff5 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2476,7 +2476,7 @@ else { = UC_SYSOP) { ?> [] [] []: - %s', $lang_functions['text_attendance']);}?> + %s', $lang_functions['text_attendance']);}?> []:
diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index 94c892ea..af8782cc 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -107,8 +107,8 @@ class Update extends Install * * attendance change, do migrate */ - if (WITH_LARAVEL && VERSION_NUMBER == '1.6.0-beta9' && NexusDB::schema()->hasColumn('attendance', 'total_points')) { - + if (WITH_LARAVEL && VERSION_NUMBER == '1.6.0-beta9' && NexusDB::schema()->hasColumn('attendance', 'total_days')) { + $this->migrateAttendance(); } } @@ -116,13 +116,11 @@ class Update extends Install { $page = 1; $size = 1000; - $sub = Attendance::query()->orderBy('id', 'desc'); while (true) { $logPrefix = "[MIGRATE_ATTENDANCE], page: $page, size: $size"; $result = Attendance::query() - ->fromSub($sub, 'a') - ->groupBy('id, uid') - ->selectRaw('id, uid, count(*) as counts') + ->groupBy(['uid']) + ->selectRaw('uid, max(id) as id, count(*) as counts') ->forPage($page, $size) ->get(); $this->doLog("$logPrefix, " . last_query() . ", count: " . $result->count()); @@ -136,7 +134,7 @@ class Update extends Install ]; $updateResult = $row->update($update); $this->doLog(sprintf( - "$logPrefix, update user: %s(%s) => %s, result: %s", + "$logPrefix, update user: %s(ID: %s) => %s, result: %s", $row->uid, $row->id, json_encode($update), var_export($updateResult, true) )); }