mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 20:17:24 +08:00
improve update
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user