change datetime not null default 0000

This commit is contained in:
xiaomlove
2022-04-05 14:52:50 +08:00
parent 8bee181c09
commit bd1fe9a474
5 changed files with 81 additions and 13 deletions

View File

@@ -0,0 +1,56 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$tableFields = [
'comments' => ['editdate'],
'invites' => ['time_invited'],
'offers' => ['allowedtime'],
'peers' => ['last_action', 'prev_action'],
'posts' => ['editdate'],
'snatched' => ['last_action', 'completedat'],
'torrents' => ['last_action', 'promotion_until', 'picktime', 'last_reseed'],
'users' => [
'last_login', 'last_access', 'last_home', 'last_offer', 'forum_access', 'last_staffmsg',
'last_pm', 'last_comment', 'last_post', 'donoruntil', 'warneduntil', 'noaduntil', 'vip_until',
'leechwarnuntil', 'lastwarned',
],
];
foreach ($tableFields as $table => $fields) {
$columnInfo = \Nexus\Database\NexusDB::getMysqlColumnInfo($table);
$modifies = [];
foreach ($fields as $field) {
if (isset($columnInfo[$field]) && $columnInfo[$field]['COLUMN_DEFAULT'] == '0000-00-00 00:00:00') {
$modifies[] = sprintf('modify `%s` datetime default null', $field);
}
}
if (!empty($modifies)) {
$sql = sprintf("alter table `%s` %s", $table, implode(', ', $modifies));
\Illuminate\Support\Facades\DB::statement($sql);
}
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
};

View File

@@ -174,7 +174,7 @@ function ban_user_with_leech_warning_expired()
->where('enabled', \App\Models\User::ENABLED_YES)
->where('leechwarn', 'yes')
->where('leechwarnuntil', '<', $dt)
->get(['id', 'username', 'modcomment']);
->get(['id', 'username', 'modcomment', 'lang']);
if ($results->isEmpty()) {
return [];
}
@@ -193,7 +193,8 @@ function ban_user_with_leech_warning_expired()
}
$update = [
'enabled' => \App\Models\User::ENABLED_NO,
'leechwarnuntil' => null,
//old version site this field NOT NULL DEFAULT '0000-00-00 00:00:00'
// 'leechwarnuntil' => null,
];
\App\Models\User::query()->whereIn('id', $uidArr)->update($update);
\App\Models\UserBanLog::query()->insert($userBanLogData);
@@ -308,7 +309,7 @@ function docleanup($forceAll = 0, $printProgress = false) {
//Priority Class 2: cleanup every 30 mins
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime2'");
$row = mysql_fetch_array($res);
if (!$row) {
if (!$row && !$forceAll) {
sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime2',".sqlesc($now).")") or sqlerr(__FILE__, __LINE__);
$log = "no value for arg: 'lastcleantime2', return";
do_log($log);
@@ -334,7 +335,7 @@ function docleanup($forceAll = 0, $printProgress = false) {
//Priority Class 3: cleanup every 60 mins
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime3'");
$row = mysql_fetch_array($res);
if (!$row) {
if (!$row && !$forceAll) {
sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime3',$now)") or sqlerr(__FILE__, __LINE__);
$log = "no value for arg: 'lastcleantime3', return";
do_log($log);
@@ -494,7 +495,7 @@ function docleanup($forceAll = 0, $printProgress = false) {
//Priority Class 4: cleanup every 24 hours
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime4'");
$row = mysql_fetch_array($res);
if (!$row) {
if (!$row && !$forceAll) {
sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime4',$now)") or sqlerr(__FILE__, __LINE__);
$log = "no value for arg: 'lastcleantime4', return";
do_log($log);
@@ -821,7 +822,7 @@ function docleanup($forceAll = 0, $printProgress = false) {
//Priority Class 5: cleanup every 15 days
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime5'");
$row = mysql_fetch_array($res);
if (!$row) {
if (!$row && !$forceAll) {
sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime5',$now)") or sqlerr(__FILE__, __LINE__);
$log = "no value for arg: 'lastcleantime5', return";
do_log($log);

View File

@@ -73,7 +73,7 @@ $announce_urls = array();
$announce_urls[] = $BASIC['announce_url'] ?: ($BASEURL . '/announce.php');
$SITE_ONLINE = $MAIN['site_online'];
$max_torrent_size = $MAIN['max_torrent_size'];
$max_torrent_size = (int)$MAIN['max_torrent_size'];
$announce_interval = (int)$MAIN['announce_interval'];
$annintertwoage = (int)$MAIN['annintertwoage'];
$annintertwo = (int)$MAIN['annintertwo'];

View File

@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.6.5');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-03-30');
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.6.6');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-04-05');
defined('IN_TRACKER') || define('IN_TRACKER', true);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -267,7 +267,7 @@ class NexusDB
return DB::transaction($callback, $attempts);
}
public static function getMysqlColumnInfo($table, $column)
public static function getMysqlColumnInfo($table, $column = null)
{
static $driver;
$config = nexus_config('nexus.mysql');
@@ -276,11 +276,22 @@ class NexusDB
$driver->connect($config['host'], $config['username'], $config['password'], 'information_schema', $config['port']);
}
$sql = sprintf(
"select * from COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME = '%s' and COLUMN_NAME = '%s'",
$config['database'], $table, $column
"select * from COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME = '%s'",
$config['database'], $table
);
if ($column !== null) {
$sql .= " and COLUMN_NAME = '$column'";
}
$res = $driver->query($sql);
return $driver->fetchAssoc($res);
if ($column !== null) {
return $driver->fetchAssoc($res);
}
$results = [];
while ($row = $driver->fetchAssoc($res)) {
$results[$row['COLUMN_NAME']] = $row;
}
return $results;
}