From 650f695e282fbe20641e0ea0a4f7c730e19d9120 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 12 Jun 2021 23:30:57 +0800 Subject: [PATCH] update do not do exam migration --- nexus/Install/Update.php | 84 ---------------------------------------- 1 file changed, 84 deletions(-) diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index 8e0e8cd0..9b8c0dc3 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -100,90 +100,6 @@ class Update extends Install sql_query($sql); } } - - if (WITH_LARAVEL && VERSION_NUMBER == '1.6.0-beta9') { - $this->migrateExamProgress(); - } - - } - - public function migrateExamProgress() - { - if (!NexusDB::schema()->hasColumn('exam_progress', 'init_value')) { - sql_query('alter table exam_progress add column `init_value` bigint(20) NOT NULL after `index`'); - $log = 'add column init_value on table exam_progress.'; - $this->doLog($log); - } else { - $log = 'column init_value already exists on table exam_progress.'; - $this->doLog($log); - } - $examUsersQuery = ExamUser::query()->where('status', ExamUser::STATUS_NORMAL)->with('user'); - $page = 1; - $size = 100; - while (true) { - $examUsers = $examUsersQuery->forPage($page, $size)->get(); - $log = "fetch exam user by: " . last_query(); - $this->doLog($log); - if ($examUsers->isEmpty()) { - $log = "no more exam user to handle..."; - $this->doLog($log); - break; - } - $log = 'get init_vlaue...'; - $this->doLog($log); - foreach ($examUsers as $examUser) { - $oldProgress = $examUser->progress; - $user = $examUser->user; - $currentLogPrefix = "examUser: " . $examUser->toJson(); - $log = sprintf("$currentLogPrefix, progress: %s", json_encode($oldProgress)); - $this->doLog($log); - foreach ($oldProgress as $index => $progressValue) { - if ($index == Exam::INDEX_DOWNLOADED) { - $value = $user->downloaded; - $initValue = $value - $progressValue; - } elseif ($index == Exam::INDEX_UPLOADED) { - $value = $user->uploaded; - $initValue = $value - $progressValue; - } elseif ($index == Exam::INDEX_SEED_BONUS) { - $value = $user->seedbonus; - $initValue = $value - $progressValue; - } elseif ($index == Exam::INDEX_SEED_TIME_AVERAGE) { - $value = $progressValue; - $initValue = 0; - } else { - $log = sprintf("$currentLogPrefix, invalid index: %s, skip!", $index); - $this->doLog($log); - continue; - } - $insert = [ - 'exam_user_id' => $examUser->id, - 'exam_id' => $examUser->exam_id, - 'uid' => $examUser->uid, - 'index' => $index, - 'torrent_id' => -1, - 'value' => $value, - 'init_value' => $initValue, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - ]; - $exists = NexusDB::table('exam_progress') - ->where('exam_user_id', $examUser->id) - ->where('index', $insert) - ->where('torrent_id', -1) - ->orderBy('id', 'desc') - ->first(); - if ($exists) { - NexusDB::table('exam_progress')->where('id', $exists->id)->update($insert); - $log = "$currentLogPrefix, progress exists: {$exists->id}, update index: $index progress: " . json_encode($insert); - } else { - NexusDB::table('exam_progress')->insert($insert); - $log = "$currentLogPrefix, insert index: $index progress: " . json_encode($insert); - } - $this->doLog($log); - } - } - $page++; - } } }