Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
fix(DATABASE): Fix CURRENT_TIMESTAMP Extra error
Browse files Browse the repository at this point in the history
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 <rhilipruan@gmail.com>
  • Loading branch information
Rhilip committed Jun 6, 2019
1 parent 36056ac commit 096333b
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/controllers/TrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion apps/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions apps/libraries/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/models/form/NewEditForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion apps/models/form/TorrentUploadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions apps/models/form/UserLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion apps/models/form/UserRecoverForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion apps/models/form/UserRegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
6 changes: 3 additions & 3 deletions apps/task/TrackerAnnounceTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down Expand Up @@ -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,
Expand Down
33 changes: 17 additions & 16 deletions migration/ridpt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`)
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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`),
Expand All @@ -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',
Expand All @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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`)
Expand Down Expand Up @@ -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`),
Expand Down Expand Up @@ -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.',
Expand Down Expand Up @@ -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`),
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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`),
Expand All @@ -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`)
Expand All @@ -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,
Expand Down

0 comments on commit 096333b

Please sign in to comment.