From 096333bb9f478ffc68d35423ab17bbde7f18b008 Mon Sep 17 00:00:00 2001 From: Rhilip Date: Fri, 7 Jun 2019 00:39:33 +0800 Subject: [PATCH] fix(DATABASE): Fix CURRENT_TIMESTAMP Extra error if set DEFAULT CURRENT_TIMESTAMP, The Extra DEFAULT_GENERATED will make export data lost timestamp/datetime lost...... BREAKING CHANGE: DATABASE structure changed Signed-off-by: Rhilip --- CHANGELOG.md | 3 ++- apps/controllers/TrackerController.php | 4 ++-- apps/controllers/UserController.php | 2 +- apps/libraries/Site.php | 4 ++-- apps/models/form/NewEditForm.php | 2 +- apps/models/form/TorrentUploadForm.php | 3 ++- apps/models/form/UserLoginForm.php | 4 ++-- apps/models/form/UserRecoverForm.php | 2 +- apps/models/form/UserRegisterForm.php | 2 +- apps/task/TrackerAnnounceTask.php | 6 ++--- migration/ridpt.sql | 33 +++++++++++++------------- 11 files changed, 34 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18fbd85..e01a64b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,11 @@ - **Auth:** Add UserRecover Form - **Cleanup:** Add disable cleanup job by set priority to 0 - **Cleanup:** Cleanup dead peers -- **Debug:** Remove DebugMiddleware - **Debug:** Add extend debug output +- **Debug:** Remove DebugMiddleware - **Email:** Add email template - **Invite:** Add base invite table +- **Invite:** Finish invite system - **News:** Fix news tag not appear in index - **News:** Add Site News model - **Register:** Can't copy password and paste to retyep_password diff --git a/apps/controllers/TrackerController.php b/apps/controllers/TrackerController.php index f17b581..8211d3b 100644 --- a/apps/controllers/TrackerController.php +++ b/apps/controllers/TrackerController.php @@ -139,8 +139,8 @@ public function actionIndex() } $req_info = app()->request->server('query_string') . "\n\n" . $raw_header; - app()->pdo->createCommand("INSERT INTO `agent_deny_log`(`tid`, `uid`, `user_agent`, `peer_id`, `req_info`, `msg`) - VALUES (:tid,:uid,:ua,:peer_id,:req_info,:msg) + app()->pdo->createCommand("INSERT INTO `agent_deny_log`(`tid`, `uid`, `user_agent`, `peer_id`, `req_info`,`create_at`, `msg`) + VALUES (:tid,:uid,:ua,:peer_id,:req_info,CURRENT_TIMESTAMP,:msg) ON DUPLICATE KEY UPDATE `user_agent` = VALUES(`user_agent`),`peer_id` = VALUES(`peer_id`), `req_info` = VALUES(`req_info`),`msg` = VALUES(`msg`), `last_action_at` = NOW();")->bindParams([ diff --git a/apps/controllers/UserController.php b/apps/controllers/UserController.php index ac52f2c..6eb571b 100644 --- a/apps/controllers/UserController.php +++ b/apps/controllers/UserController.php @@ -81,7 +81,7 @@ public function actionInvite() ])->execute(); $msg .= ' And return you a permanent invite'; } elseif ($invite_info['invite_type'] == 'temporarily') { - app()->pdo->createCommand('INSERT INTO `user_invitations` (`user_id`,`total`,`expire_at`) VALUES (:uid,:total,DATE_ADD(NOW(),INTERVAL :life_time SECOND ))')->bindParams([ + app()->pdo->createCommand('INSERT INTO `user_invitations` (`user_id`,`total`,`create_at`,`expire_at`) VALUES (:uid,:total,CURRENT_TIMESTAMP,DATE_ADD(NOW(),INTERVAL :life_time SECOND ))')->bindParams([ 'uid' => app()->user->getId(), 'total' => 1, 'life_time' => app()->config->get('invite.recycle_invite_lifetime') ])->execute(); diff --git a/apps/libraries/Site.php b/apps/libraries/Site.php index 6be7bd5..dda468a 100644 --- a/apps/libraries/Site.php +++ b/apps/libraries/Site.php @@ -18,13 +18,13 @@ class Site public static function writeLog($msg, $level = self::LOG_LEVEL_NORMAL) { - app()->pdo->createCommand("INSERT INTO `site_log`(`msg`, `level`) VALUES (:msg,:level)")->bindParams([ + app()->pdo->createCommand("INSERT INTO `site_log`(`create_at`,`msg`, `level`) VALUES (CURRENT_TIMESTAMP,:msg,:level)")->bindParams([ "msg" => $msg, "level" => $level ])->execute(); } public static function sendPM($sender, $receiver, $subject, $msg, $save = "no", $location = 1) { - app()->pdo->createCommand("INSERT messages (sender, receiver, subject, msg, saved, location) VALUES(:sender,:receiver,:subject,:msg,:save,:location)")->bindParams([ + app()->pdo->createCommand("INSERT `messages` (`sender`,`receiver`,`add_at`, subject, msg, saved, location) VALUES (:sender,:receiver,CURRENT_TIMESTAMP,:subject,:msg,:save,:location)")->bindParams([ "sender" => $sender, "receiver" => $receiver, "subject" => $subject , "msg" => $msg, "save" => $save , "location" => $location diff --git a/apps/models/form/NewEditForm.php b/apps/models/form/NewEditForm.php index abc6ec7..9a554ab 100644 --- a/apps/models/form/NewEditForm.php +++ b/apps/models/form/NewEditForm.php @@ -43,7 +43,7 @@ public static function inputRules() public function flush() { if ($this->id == 0) { // This is new news - app()->pdo->createCommand('INSERT INTO news (user_id,create_at,title,body,notify,force_read) VALUES (:uid,NOW(),:title,:body,:notify,:fread);')->bindParams([ + app()->pdo->createCommand('INSERT INTO news (user_id,create_at,title,body,notify,force_read) VALUES (:uid,CURRENT_TIMESTAMP,:title,:body,:notify,:fread);')->bindParams([ 'uid' => $this->user_id, 'title' => $this->title, 'body' => $this->body, 'notify' => $this->notify, 'fread' => $this->force_read ])->execute(); diff --git a/apps/models/form/TorrentUploadForm.php b/apps/models/form/TorrentUploadForm.php index c599ad5..ef672bd 100644 --- a/apps/models/form/TorrentUploadForm.php +++ b/apps/models/form/TorrentUploadForm.php @@ -169,7 +169,8 @@ public function flush() app()->pdo->beginTransaction(); try { - app()->pdo->insert('torrents', [ + app()->pdo->createCommand('INSERT INTO `torrents` (`owner_id`,`info_hash`,`status`,`added_at`,`title`,`subtitle`,`category`,`filename`,`torrent_name`,`torrent_type`,`torrent_size`,`torrent_structure`,`descr`,`uplver`) +VALUES (:owner_id,:info_hash,:status,CURRENT_TIMESTAMP,:title,:subtitle,:category,:filename,:torrent_name,:torrent_type,:torrent_size,:torrent_structure,:descr,:uplver)')->bindParams([ 'owner_id' => app()->user->getId(), 'info_hash' => $this->info_hash, 'status' => $this->status, diff --git a/apps/models/form/UserLoginForm.php b/apps/models/form/UserLoginForm.php index 45a65cd..9e45a06 100644 --- a/apps/models/form/UserLoginForm.php +++ b/apps/models/form/UserLoginForm.php @@ -154,8 +154,8 @@ public function createUserSession() } while ($count != 0); // store user login information , ( for example `login ip`,`user_agent`,`last activity at` ) - app()->pdo->createCommand('INSERT INTO `user_session_log`(`uid`, `sid`, `login_ip`, `user_agent` , `last_access_at`) ' . - 'VALUES (:uid,:sid,INET6_ATON(:login_ip),:ua, NOW())')->bindParams([ + app()->pdo->createCommand('INSERT INTO `user_session_log`(`uid`, `sid`, `login_ip`, `user_agent` ,`login_at`, `last_access_at`) ' . + 'VALUES (:uid,:sid,INET6_ATON(:login_ip),:ua,NOW(), NOW())')->bindParams([ 'uid' => $userId, 'sid' => $userSessionId, 'login_ip' => app()->request->getClientIp(), 'ua' => app()->request->header('user-agent') diff --git a/apps/models/form/UserRecoverForm.php b/apps/models/form/UserRecoverForm.php index 668b437..a51e085 100644 --- a/apps/models/form/UserRecoverForm.php +++ b/apps/models/form/UserRecoverForm.php @@ -56,7 +56,7 @@ public function flush() { // Send user email to get comfirm link $confirm_key = StringHelper::getRandomString(32); - app()->pdo->createCommand('INSERT INTO `user_confirm` (`uid`,`serect`,`action`) VALUES (:uid,:serect,:action)')->bindParams([ + app()->pdo->createCommand('INSERT INTO `user_confirm` (`uid`,`serect`,`create_at`,`action`) VALUES (:uid,:serect,CURRENT_TIMESTAMP,:action)')->bindParams([ 'uid' => $user_info['id'], 'serect' => $confirm_key, 'action' => $this->_action ])->execute(); $confirm_url = app()->request->root() . '/auth/confirm?' . http_build_query([ diff --git a/apps/models/form/UserRegisterForm.php b/apps/models/form/UserRegisterForm.php index dd44969..2fe0c82 100644 --- a/apps/models/form/UserRegisterForm.php +++ b/apps/models/form/UserRegisterForm.php @@ -281,7 +281,7 @@ public function flush() if ($this->confirm_way == 'email') { $confirm_key = StringHelper::getRandomString(32); - app()->pdo->createCommand('INSERT INTO `user_confirm` (`uid`,`serect`,`action`) VALUES (:uid,:serect,:action)')->bindParams([ + app()->pdo->createCommand('INSERT INTO `user_confirm` (`uid`,`serect`,`create_at`,`action`) VALUES (:uid,:serect,CURRENT_TIMESTAMP,:action)')->bindParams([ 'uid' => $this->id, 'serect' => $confirm_key, 'action' => $this->_action ])->execute(); $confirm_url = app()->request->root() . '/auth/confirm?' . http_build_query([ diff --git a/apps/task/TrackerAnnounceTask.php b/apps/task/TrackerAnnounceTask.php index e53dbc2..5eabd6a 100644 --- a/apps/task/TrackerAnnounceTask.php +++ b/apps/task/TrackerAnnounceTask.php @@ -64,7 +64,7 @@ private function processAnnounceRequest($queries, $seeder, $userInfo, $torrentIn $trueUploaded = max(0, $queries['uploaded']); $trueDownloaded = max(0, $queries['downloaded']); - app()->pdo->createCommand("INSERT INTO `peers` SET `user_id` =:uid, `torrent_id`= :tid, `peer_id`= :pid, + app()->pdo->createCommand("INSERT INTO `peers` SET `user_id` =:uid, `torrent_id`= :tid, `peer_id`= :pid, `started_at`= CURRENT_TIMESTAMP `agent`=:agent, `seeder` = :seeder, {$ipField} , `uploaded` = :upload , `downloaded` = :download, `to_go` = :to_go, `corrupt` = :corrupt , `key` = :key ; @@ -180,8 +180,8 @@ private function checkUpspeed($userInfo, $torrentInfo, $trueUploaded, $trueDownl $upspeed = (($trueUploaded > 0 && $duration > 0) ? $trueUploaded / $duration : 0); $logCheater = function ($commit) use ($userInfo, $torrentInfo, $trueUploaded, $trueDownloaded, $duration) { - app()->pdo->createCommand("INSERT INTO `cheaters`(`userid`, `torrentid`, `uploaded`, `downloaded`, `anctime`, `seeders`, `leechers`, `hit`, `commit`, `reviewed`, `reviewed_by`) - VALUES (:uid, :tid, :uploaded, :downloaded, :anctime, :seeders, :leechers, :hit, :msg, :reviewed, :reviewed_by) + app()->pdo->createCommand("INSERT INTO `cheaters`(`added_at`,`userid`, `torrentid`, `uploaded`, `downloaded`, `anctime`, `seeders`, `leechers`, `hit`, `commit`, `reviewed`, `reviewed_by`) + VALUES (CURRENT_TIMESTAMP, :uid, :tid, :uploaded, :downloaded, :anctime, :seeders, :leechers, :hit, :msg, :reviewed, :reviewed_by) ON DUPLICATE KEY UPDATE `hit` = `hit` + 1, `reviewed` = 0,`reviewed_by` = '',`commit` = VALUES(`commit`)")->bindParams([ "uid" => $userInfo["id"], "tid" => $torrentInfo["id"], "uploaded" => $trueUploaded, "downloaded" => $trueDownloaded, "anctime" => $duration, diff --git a/migration/ridpt.sql b/migration/ridpt.sql index a4782a4..e3b7a36 100644 --- a/migration/ridpt.sql +++ b/migration/ridpt.sql @@ -3,7 +3,7 @@ -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1 --- Generation Time: Jun 07, 2019 at 12:03 AM +-- Generation Time: Jun 07, 2019 at 12:27 AM -- Server version: 8.0.16 -- PHP Version: 7.3.6 @@ -118,7 +118,7 @@ CREATE TABLE IF NOT EXISTS `agent_deny_log` ( `peer_id` varbinary(20) NOT NULL, `req_info` text NOT NULL, `msg` varchar(255) NOT NULL, - `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `create_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `last_action_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `one_peer` (`tid`,`uid`) @@ -161,7 +161,7 @@ CREATE TABLE IF NOT EXISTS `bookmarks` ( DROP TABLE IF EXISTS `cheaters`; CREATE TABLE IF NOT EXISTS `cheaters` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `added_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `added_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `userid` mediumint(8) UNSIGNED NOT NULL DEFAULT '0', `torrentid` mediumint(8) UNSIGNED NOT NULL DEFAULT '0', `uploaded` int(10) UNSIGNED NOT NULL DEFAULT '0', @@ -242,7 +242,7 @@ CREATE TABLE IF NOT EXISTS `ip_bans` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ip` varchar(255) NOT NULL, `add_by` int(10) UNSIGNED NOT NULL, - `add_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `add_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `commit` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `ip` (`ip`), @@ -266,7 +266,7 @@ CREATE TABLE IF NOT EXISTS `messages` ( `id` int(11) NOT NULL AUTO_INCREMENT, `sender` mediumint(8) UNSIGNED NOT NULL DEFAULT '0', `receiver` mediumint(8) UNSIGNED NOT NULL DEFAULT '0', - `add_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `add_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `subject` varchar(128) NOT NULL DEFAULT '', `msg` text NOT NULL, `unread` enum('yes','no') NOT NULL DEFAULT 'yes', @@ -292,7 +292,7 @@ DROP TABLE IF EXISTS `news`; CREATE TABLE IF NOT EXISTS `news` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) UNSIGNED NOT NULL, - `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `create_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `edit_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `title` varchar(255) NOT NULL DEFAULT '', `body` text NOT NULL, @@ -330,8 +330,8 @@ CREATE TABLE IF NOT EXISTS `peers` ( `downloaded` bigint(20) UNSIGNED NOT NULL DEFAULT '0', `to_go` bigint(20) UNSIGNED NOT NULL DEFAULT '0', `finished` tinyint(1) NOT NULL DEFAULT '0', - `started_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `last_action_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `started_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `last_action_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `finish_at` timestamp NULL DEFAULT NULL, `agent` varchar(64) NOT NULL, `corrupt` tinyint(1) NOT NULL DEFAULT '0', @@ -504,7 +504,7 @@ INSERT INTO `site_crontab` (`id`, `job`, `priority`, `job_interval`) VALUES DROP TABLE IF EXISTS `site_log`; CREATE TABLE IF NOT EXISTS `site_log` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `create_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `msg` text CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL, `level` enum('normal','mod','sysop','leader') CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'normal', PRIMARY KEY (`id`) @@ -536,7 +536,7 @@ CREATE TABLE IF NOT EXISTS `snatched` ( `leech_time` int(10) UNSIGNED NOT NULL DEFAULT '0', `finished` enum('yes','no') NOT NULL DEFAULT 'no', `finish_ip` varchar(40) DEFAULT NULL, - `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `create_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `last_action_at` timestamp NULL DEFAULT NULL, `finish_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), @@ -564,7 +564,8 @@ CREATE TABLE IF NOT EXISTS `torrents` ( `owner_id` int(11) UNSIGNED NOT NULL, `info_hash` varbinary(20) NOT NULL, `status` enum('deleted','banned','pending','confirmed') NOT NULL DEFAULT 'confirmed', - `added_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `added_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `update_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `complete` int(11) NOT NULL DEFAULT '0' COMMENT 'The number of active peers that have completed downloading.', `incomplete` int(11) NOT NULL DEFAULT '0' COMMENT 'The number of active peers that have not completed downloading.', `downloaded` int(11) NOT NULL DEFAULT '0' COMMENT 'The number of peers that have ever completed downloading.', @@ -608,7 +609,7 @@ CREATE TABLE IF NOT EXISTS `torrents_buff` ( `ratio_type` enum('Normal','Free','2X','2X Free','50%','2X 50%','30%','Other') NOT NULL DEFAULT 'Normal', `upload_ratio` decimal(4,2) NOT NULL DEFAULT '1.00', `download_ratio` decimal(4,2) NOT NULL DEFAULT '1.00', - `add_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `add_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `start_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `expired_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`), @@ -653,7 +654,7 @@ CREATE TABLE IF NOT EXISTS `users` ( `class` smallint(6) UNSIGNED NOT NULL DEFAULT '1', `passkey` varchar(32) NOT NULL, `invite_by` int(11) UNSIGNED NOT NULL DEFAULT '0', - `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `create_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `register_ip` varbinary(16) NOT NULL, `uploadpos` tinyint(1) NOT NULL DEFAULT '1', `downloadpos` tinyint(1) NOT NULL DEFAULT '1', @@ -697,7 +698,7 @@ CREATE TABLE IF NOT EXISTS `user_confirm` ( `action` enum('register','recover') NOT NULL, `uid` int(11) UNSIGNED NOT NULL, `serect` varchar(64) NOT NULL, - `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `create_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `used` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `serect` (`serect`), @@ -722,7 +723,7 @@ CREATE TABLE IF NOT EXISTS `user_invitations` ( `user_id` int(10) UNSIGNED NOT NULL, `total` smallint(5) NOT NULL DEFAULT '0', `used` smallint(5) NOT NULL DEFAULT '0', - `create_at` timestamp NOT NULL, + `create_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `expire_at` timestamp NOT NULL, PRIMARY KEY (`id`), KEY `FK_invition_users_id` (`user_id`) @@ -745,7 +746,7 @@ CREATE TABLE IF NOT EXISTS `user_session_log` ( `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, `uid` int(10) UNSIGNED NOT NULL, `sid` varchar(64) NOT NULL, - `login_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `login_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `login_ip` varbinary(16) NOT NULL, `user_agent` varchar(512) NOT NULL DEFAULT '', `last_access_at` timestamp NOT NULL,