mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-20 17:37:23 +08:00
attendance remove total_points
This commit is contained in:
@@ -53,10 +53,32 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$examRep = new ExamRepository();
|
||||
$examuser = ExamUser::query()->findOrFail(2);
|
||||
$r = $examRep->updateProgress($examuser);
|
||||
dd($r);
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ class Attendance extends NexusModel
|
||||
{
|
||||
protected $table = 'attendance';
|
||||
|
||||
protected $fillable = ['uid', 'added', 'points', 'days', 'total_days'];
|
||||
|
||||
protected $casts = [
|
||||
'added' => 'datetime',
|
||||
];
|
||||
|
||||
@@ -736,8 +736,8 @@ class ExamRepository extends BaseRepository
|
||||
if ($donateStatus == User::DONATE_YES) {
|
||||
$baseQuery->where("$userTable.donoruntil", ">=", Carbon::now()->toDateTimeString());
|
||||
} elseif ($donateStatus == User::DONATE_NO) {
|
||||
$baseQuery->where(function (Builder $query) {
|
||||
$query->whereNull('donoruntil')->orWhere('donoruntil', '<', Carbon::now()->toDateTimeString());
|
||||
$baseQuery->where(function (Builder $query) use ($userTable) {
|
||||
$query->whereNull("$userTable.donoruntil")->orWhere("$userTable.donoruntil", '<', Carbon::now()->toDateTimeString());
|
||||
});
|
||||
} else {
|
||||
do_log("{$exam->id} filter $filter: $donateStatus invalid.", "error");
|
||||
|
||||
@@ -46,13 +46,13 @@ class Attendance
|
||||
// sql_query(sprintf('INSERT INTO `attendance` (`uid`,`added`,`points`,`days`) VALUES (%u, %s, %u, %u)', $this->userid, sqlesc(date('Y-m-d H:i:s')), $points, $cdays)) or sqlerr(__FILE__, __LINE__);
|
||||
if ($doUpdate) {
|
||||
$sql = sprintf(
|
||||
'UPDATE `attendance` set added = %s, points = %s, days = %s, total_days= %s, total_points = %s where uid = %s order by id desc limit 1',
|
||||
sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1, $totalPoints + $points, $this->userid
|
||||
'UPDATE `attendance` set added = %s, points = %s, days = %s, total_days= %s where uid = %s order by id desc limit 1',
|
||||
sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1, $this->userid
|
||||
);
|
||||
} else {
|
||||
$sql = sprintf(
|
||||
'INSERT INTO `attendance` (`uid`, `added`, `points`, `days`, `total_days`, `total_points`) VALUES (%u, %s, %u, %u, %u, %u)',
|
||||
$this->userid, sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1, $totalPoints + $points
|
||||
'INSERT INTO `attendance` (`uid`, `added`, `points`, `days`, `total_days`) VALUES (%u, %s, %u, %u, %u, %u)',
|
||||
$this->userid, sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1
|
||||
);
|
||||
}
|
||||
do_log(sprintf('uid: %s, date: %s, doUpdate: %s, sql: %s', $this->userid, $this->curdate, $doUpdate, $sql), 'notice');
|
||||
|
||||
+2
-6
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddTotalDaysAndTotalPointsToAttendanceTable extends Migration
|
||||
class AddTotalDaysToAttendanceTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
@@ -13,12 +13,8 @@ class AddTotalDaysAndTotalPointsToAttendanceTable extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasColumns('attendance',['total_days', 'total_points'])) {
|
||||
return;
|
||||
}
|
||||
Schema::table('attendance', function (Blueprint $table) {
|
||||
$table->integer('total_days')->default(0);
|
||||
$table->integer('total_points')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -30,7 +26,7 @@ class AddTotalDaysAndTotalPointsToAttendanceTable extends Migration
|
||||
public function down()
|
||||
{
|
||||
Schema::table('attendance', function (Blueprint $table) {
|
||||
$table->dropColumn(['total_days', 'total_points']);
|
||||
$table->dropColumn('total_days');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.6.0-beta8');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2020-06-06');
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.6.0-beta9');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2020-06-13');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', true);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Nexus\Install;
|
||||
|
||||
use App\Models\Attendance;
|
||||
use App\Models\Category;
|
||||
use App\Models\Exam;
|
||||
use App\Models\ExamUser;
|
||||
@@ -100,6 +101,48 @@ class Update extends Install
|
||||
sql_query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.6.0-beta9
|
||||
*
|
||||
* attendance change, do migrate
|
||||
*/
|
||||
if (WITH_LARAVEL && VERSION_NUMBER == '1.6.0-beta9' && NexusDB::schema()->hasColumn('attendance', 'total_points')) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function migrateAttendance()
|
||||
{
|
||||
$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')
|
||||
->forPage($page, $size)
|
||||
->get();
|
||||
$this->doLog("$logPrefix, " . last_query() . ", count: " . $result->count());
|
||||
if ($result->isEmpty()) {
|
||||
$this->doLog("$logPrefix, no more data...");
|
||||
break;
|
||||
}
|
||||
foreach ($result as $row) {
|
||||
$update = [
|
||||
'total_days' => $row->counts,
|
||||
];
|
||||
$updateResult = $row->update($update);
|
||||
$this->doLog(sprintf(
|
||||
"$logPrefix, update user: %s(%s) => %s, result: %s",
|
||||
$row->uid, $row->id, json_encode($update), var_export($updateResult, true)
|
||||
));
|
||||
}
|
||||
$page++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user