* added timestamp column to db table
 * consolidated write operation
 * fixed storing reports when get_browser() would return empty
This commit is contained in:
Sarjuuk
2018-05-26 15:59:01 +02:00
parent c5d28a9bbc
commit 93a72013b8
5 changed files with 40 additions and 44 deletions

View File

@@ -255,19 +255,12 @@ class AjaxComment extends AjaxHandler
else else
$ok = DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~0x4 WHERE id = ?d', $this->_post['id'][0]); $ok = DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~0x4 WHERE id = ?d', $this->_post['id'][0]);
} }
else if (DB::Aowow()->selectCell('SELECT 1 FROM ?_reports WHERE `mode` = ?d AND `reason`= ?d AND `subject` = ?d AND `userId` = ?d', 1, 17, $this->_post['id'][0], User::$id))
return 'You\'ve already reported this.'; // ct_resp_error7
else if (User::$id && !$this->_post['reason'] || mb_strlen($this->_post['reason']) < self::REPLY_LENGTH_MIN) else if (User::$id && !$this->_post['reason'] || mb_strlen($this->_post['reason']) < self::REPLY_LENGTH_MIN)
return 'Your message is too short.'; return 'Your message is too short.';
else if (User::$id) // only report as outdated else if (User::$id) // only report as outdated
{ $ok = Util::createReport(1, 17, $this->_post['id'][0], '[Outdated Comment] '.$this->_post['reason']);
$ok = DB::Aowow()->query(
'INSERT INTO ?_reports (userId, mode, reason, subject, ip, description, userAgent, appName) VALUES (?d, 1, 17, ?d, ?, "<automated comment report>", ?, ?)',
User::$id,
$this->_post['id'][0],
User::$ip,
$_SERVER['HTTP_USER_AGENT'],
get_browser(null, true)['browser']
);
}
if ($ok) // this one is very special; as in: completely retarded if ($ok) // this one is very special; as in: completely retarded
return 'ok'; // the script expects the actual characters 'ok' not some string like "ok" return 'ok'; // the script expects the actual characters 'ok' not some string like "ok"
@@ -342,14 +335,7 @@ class AjaxComment extends AjaxHandler
if (!User::$id || !$this->_post['id']) if (!User::$id || !$this->_post['id'])
return; return;
DB::Aowow()->query( Util::createReport(1, 19, $this->_post['id'][0], '[General Reply Report]');
'INSERT INTO ?_reports (userId, mode, reason, subject, ip, description, userAgent, appName) VALUES (?d, 1, 19, ?d, ?, "<automated commentreply report>", ?, ?)',
User::$id,
$this->_post['id'][0],
User::$ip,
$_SERVER['HTTP_USER_AGENT'],
get_browser(null, true)['browser']
);
} }
protected function handleReplyUpvote() protected function handleReplyUpvote()

View File

@@ -41,6 +41,7 @@ class AjaxContactus extends AjaxHandler
$app = $this->_post['appname']; $app = $this->_post['appname'];
$url = $this->_post['page']; $url = $this->_post['page'];
$desc = $this->_post['desc']; $desc = $this->_post['desc'];
$subj = $this->_post['id'];
$contexts = array( $contexts = array(
[1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8],
@@ -69,30 +70,10 @@ class AjaxContactus extends AjaxHandler
// check already reported // check already reported
$field = User::$id ? 'userId' : 'ip'; $field = User::$id ? 'userId' : 'ip';
if (DB::Aowow()->selectCell('SELECT 1 FROM ?_reports WHERE `mode` = ?d AND `reason`= ?d AND `subject` = ?d AND ?# = ?', $mode, $rsn, $this->_post['id'], $field, User::$id ?: User::$ip)) if (DB::Aowow()->selectCell('SELECT 1 FROM ?_reports WHERE `mode` = ?d AND `reason`= ?d AND `subject` = ?d AND ?# = ?', $mode, $rsn, $subj, $field, User::$id ?: User::$ip))
return 7; return 7;
$update = array( if (Util::createReport($mode, $rsn, $subj, $desc, $ua, $app, $url, $this->_post['relatedurl'], $this->_post['email']))
'userId' => User::$id,
'mode' => $mode,
'reason' => $rsn,
'ip' => User::$ip,
'description' => $desc,
'userAgent' => $ua,
'appName' => $app,
'url' => $url
);
if ($_ = $this->_post['id'])
$update['subject'] = $_;
if ($_ = $this->_post['relatedurl'])
$update['relatedurl'] = $_;
if ($_ = $this->_post['email'])
$update['email'] = $_;
if (DB::Aowow()->query('INSERT INTO ?_reports (?#) VALUES (?a)', array_keys($update), array_values($update)))
return 0; return 0;
return 'save to db unsuccessful'; return 'save to db unsuccessful';

View File

@@ -1419,6 +1419,32 @@ class Util
round($offHand['gearscore'] * $oh) round($offHand['gearscore'] * $oh)
); );
} }
static function createReport($mode, $reason, $subject, $desc, $userAgent = null, $appName = null, $url = null, $relUrl = null, $email = null)
{
$update = array(
'userId' => User::$id,
'createDate' => time(),
'mode' => $mode,
'reason' => $reason,
'subject' => $subject,
'ip' => User::$ip,
'description' => $desc,
'userAgent' => $userAgent ?: $_SERVER['HTTP_USER_AGENT'],
'appName' => $appName ?: (get_browser(null, true)['browser'] ?: '')
);
if ($url)
$update['url'] = $url;
if ($relUrl)
$update['relatedurl'] = $relUrl;
if ($email)
$update['email'] = $email;
return DB::Aowow()->query('INSERT INTO ?_reports (?#) VALUES (?a)', array_keys($update), array_values($update));
}
} }
?> ?>

View File

@@ -2170,6 +2170,7 @@ CREATE TABLE `aowow_reports` (
`userId` mediumint(8) unsigned NOT NULL, `userId` mediumint(8) unsigned NOT NULL,
`assigned` mediumint(8) unsigned NOT NULL DEFAULT 0, `assigned` mediumint(8) unsigned NOT NULL DEFAULT 0,
`status` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT '0:new; 1:solved; 2:rejected', `status` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT '0:new; 1:solved; 2:rejected',
`createDate` int(10) unsigned NOT NULL,
`mode` tinyint(3) unsigned NOT NULL, `mode` tinyint(3) unsigned NOT NULL,
`reason` tinyint(3) unsigned NOT NULL, `reason` tinyint(3) unsigned NOT NULL,
`subject` mediumint(9) NOT NULL DEFAULT 0, `subject` mediumint(9) NOT NULL DEFAULT 0,
@@ -3090,7 +3091,7 @@ UNLOCK TABLES;
LOCK TABLES `aowow_dbversion` WRITE; LOCK TABLES `aowow_dbversion` WRITE;
/*!40000 ALTER TABLE `aowow_dbversion` DISABLE KEYS */; /*!40000 ALTER TABLE `aowow_dbversion` DISABLE KEYS */;
INSERT INTO `aowow_dbversion` VALUES (1527333496,0,NULL,NULL); INSERT INTO `aowow_dbversion` VALUES (1527343033,0,NULL,NULL);
/*!40000 ALTER TABLE `aowow_dbversion` ENABLE KEYS */; /*!40000 ALTER TABLE `aowow_dbversion` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;

View File

@@ -0,0 +1,2 @@
ALTER TABLE `aowow_reports`
ADD COLUMN `createDate` INT UNSIGNED NOT NULL AFTER `status`;