improve update

This commit is contained in:
xiaomlove
2022-02-10 22:30:26 +08:00
parent c4697a7d89
commit 186bebfe12
8 changed files with 49 additions and 32 deletions

View File

@@ -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
{

View File

@@ -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)
{

View File

@@ -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));

View File

@@ -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;
}
}

View File

@@ -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();

View File

@@ -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("<ul><li><a href=\"#id". $faq_categ[$id]['link_id'] ."\"><b>". $faq_categ[$id]['title'] ."</b></a><ul>\n");
if (array_key_exists("items", $faq_categ[$id]))
if (array_key_exists("items", $faq_categ[$id]))
{
foreach ($faq_categ[$id]['items'] as $id2 => $temp)
{

View File

@@ -344,7 +344,7 @@ if ($showstats_main == "yes")
if (!$Cache->get_page()){
$Cache->add_whole_row();
$registered = number_format(get_row_count("users"));
$unverified = number_format(get_row_count("users", "WHERE status='pending'"));
$unverified = number_format(get_row_count("users", "WHERE status='pending' and enabled='yes'"));
$totalonlinetoday = number_format(get_row_count("users","WHERE last_access >= ". sqlesc(date("Y-m-d H:i:s",(TIMENOW - 86400)))));
$totalonlineweek = number_format(get_row_count("users","WHERE last_access >= ". sqlesc(date("Y-m-d H:i:s",(TIMENOW - 604800)))));
$VIP = number_format(get_row_count("users", "WHERE class=".UC_VIP));

View File

@@ -2,7 +2,7 @@
require "../include/bittorrent.php";
dbconn();
require_once(get_langfile_path());
loggedinorreturn();
//loggedinorreturn();
stdhead($lang_rules['head_rules']);
$Cache->new_page('rules', 900, true);
if (!$Cache->get_page())