diff --git a/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php b/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php new file mode 100644 index 00000000..9ed075ed --- /dev/null +++ b/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php @@ -0,0 +1,56 @@ + ['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() + { + // + } +}; diff --git a/include/cleanup.php b/include/cleanup.php index d029d70b..e73c27c3 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -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); @@ -822,7 +823,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); diff --git a/include/config.php b/include/config.php index 7ba1104f..1ce7363f 100644 --- a/include/config.php +++ b/include/config.php @@ -73,7 +73,7 @@ $announce_urls = array(); $announce_urls[] = $BASIC['announce_url'] ?: ($BASEURL . '/api/announce'); $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']; diff --git a/nexus/Database/NexusDB.php b/nexus/Database/NexusDB.php index 32fa916b..2e45faf0 100644 --- a/nexus/Database/NexusDB.php +++ b/nexus/Database/NexusDB.php @@ -331,7 +331,7 @@ class NexusDB } } - public static function getMysqlColumnInfo($table, $column) + public static function getMysqlColumnInfo($table, $column = null) { static $driver; $config = nexus_config('nexus.mysql'); @@ -340,11 +340,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; + }