From 186bebfe124d54914a21b17324086533877f677c Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Thu, 10 Feb 2022 22:30:26 +0800 Subject: [PATCH] improve update --- app/Repositories/BonusRepository.php | 19 ------------- include/functions.php | 2 +- nexus/Install/Install.php | 9 ++++-- nexus/Install/Update.php | 41 ++++++++++++++++++++++++---- nexus/Install/update/update.php | 2 +- public/faq.php | 4 +-- public/index.php | 2 +- public/rules.php | 2 +- 8 files changed, 49 insertions(+), 32 deletions(-) diff --git a/app/Repositories/BonusRepository.php b/app/Repositories/BonusRepository.php index ade471d3..1f438b80 100644 --- a/app/Repositories/BonusRepository.php +++ b/app/Repositories/BonusRepository.php @@ -43,25 +43,6 @@ class BonusRepository extends BaseRepository } - public function initSeedPoints(): int - { - $size = 10000; - $tableName = (new User())->getTable(); - $result = 0; - do { - $affectedRows = NexusDB::table($tableName) - ->whereNull('seed_points') - ->limit($size) - ->update([ - 'seed_points' => NexusDB::raw('seed_points = seedbonus') - ]); - $result += $affectedRows; - do_log("affectedRows: $affectedRows, query: " . last_query()); - } while ($affectedRows > 0); - - return $result; - } - public function consumeToBuyMedal($uid, $medalId): bool { diff --git a/include/functions.php b/include/functions.php index 0f47d593..b3aa73d1 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1207,7 +1207,7 @@ if ($restrictemaildomain == 'yes'){ $newEmail = trim(strtolower($newEmail)); $sql = sql_query("SELECT * FROM allowedemails") or sqlerr(__FILE__, __LINE__); $list = mysql_fetch_array($sql); - $addresses = explode(' ', preg_replace("/[[:space:]]+/", " ", trim($list[value])) ); + $addresses = explode(' ', preg_replace("/[[:space:]]+/", " ", trim($list['value'])) ); if(count($addresses) > 0) { diff --git a/nexus/Install/Install.php b/nexus/Install/Install.php index b5f0b4c8..b4d62e1e 100644 --- a/nexus/Install/Install.php +++ b/nexus/Install/Install.php @@ -539,12 +539,17 @@ class Install return true; } - public function runMigrate() + public function runMigrate($path = null) { if (!WITH_LARAVEL) { throw new \RuntimeException('Laravel is not available.'); } - $command = "php " . ROOT_PATH . "artisan migrate --force"; + $command = "php " . ROOT_PATH . "artisan migrate"; + if (!is_null($path)) { + $command .= " --path=$path"; + } else { + $command .= " --force"; + } $result = exec($command, $output, $result_code); $this->doLog(sprintf('command: %s, result_code: %s, result: %s', $command, $result_code, $result)); $this->doLog("output: " . json_encode($output)); diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index ce36e171..ecc3cada 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -11,9 +11,11 @@ use App\Models\HitAndRun; use App\Models\Icon; use App\Models\Setting; use App\Models\User; +use App\Repositories\BonusRepository; use App\Repositories\ExamRepository; use Carbon\Carbon; use GuzzleHttp\Client; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; use Nexus\Database\NexusDB; @@ -126,15 +128,25 @@ class Update extends Install * * attendance change, do migrate */ - if (WITH_LARAVEL && VERSION_NUMBER == '1.6.0-beta9' && NexusDB::schema()->hasColumn('attendance', 'total_days')) { + if (WITH_LARAVEL && !NexusDB::schema()->hasColumn('attendance', 'total_days')) { + $this->runMigrate(database_path('migrations/2021_06_13_215440_add_total_days_to_attendance_table.php')); $this->migrateAttendance(); } - if (WITH_LARAVEL && version_compare(VERSION_NUMBER, '1.6.0-beta12', '>=')) { - $this->addSetting('authority.torrent_hr', User::CLASS_ADMINISTRATOR); - $this->addSetting('bonus.cancel_hr', BonusLogs::DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN); - $this->addSetting('hr.mode', HitAndRun::MODE_DISABLED); + /** + * @since 1.6.0-beta13 + * + * add seed points to user + */ + if (WITH_LARAVEL && !NexusDB::schema()->hasColumn('users', 'seed_points')) { + $this->runMigrate(database_path('migrations/2021_06_24_013107_add_seed_points_to_users_table.php')); + $result = $this->initSeedPoints(); + $this->doLog("[INIT SEED POINTS], $result"); } + + + + } private function migrateAttendance() @@ -248,4 +260,23 @@ class Update extends Install return true; } + public function initSeedPoints(): int + { + $size = 10000; + $tableName = (new User())->getTable(); + $result = 0; + do { + $affectedRows = NexusDB::table($tableName) + ->whereNull('seed_points') + ->limit($size) + ->update([ + 'seed_points' => NexusDB::raw('seed_points = seedbonus') + ]); + $result += $affectedRows; + $this->doLog("affectedRows: $affectedRows, query: " . last_query()); + } while ($affectedRows > 0); + + return $result; + } + } diff --git a/nexus/Install/update/update.php b/nexus/Install/update/update.php index 678fda76..b6812ea3 100644 --- a/nexus/Install/update/update.php +++ b/nexus/Install/update/update.php @@ -139,9 +139,9 @@ if ($currentStep == 4) { while ($isPost) { try { $update->createSymbolicLinks($symbolicLinks); - $update->runMigrate(); $update->saveSettings($settings); $update->runExtraQueries(); + $update->runMigrate(); $update->nextStep(); } catch (\Exception $e) { $error = $e->getMessage(); diff --git a/public/faq.php b/public/faq.php index 7620eec5..1cbb8df4 100644 --- a/public/faq.php +++ b/public/faq.php @@ -2,7 +2,7 @@ require "../include/bittorrent.php"; dbconn(); require_once(get_langfile_path()); -loggedinorreturn(); +//loggedinorreturn(); stdhead($lang_faq['head_faq']); $Cache->new_page('faq', 900, true); @@ -61,7 +61,7 @@ if (isset($faq_categ)) { if ($faq_categ[$id]['flag'] == "1") { print("