aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/acp/acp_logs.php24
-rw-r--r--phpBB/includes/mcp/mcp_logs.php34
-rw-r--r--phpBB/phpbb/log/log.php57
-rw-r--r--phpBB/phpbb/log/log_interface.php12
-rw-r--r--phpBB/phpbb/log/null.php7
5 files changed, 100 insertions, 34 deletions
diff --git a/phpBB/includes/acp/acp_logs.php b/phpBB/includes/acp/acp_logs.php
index 4e5db058fb..11d911151b 100644
--- a/phpBB/includes/acp/acp_logs.php
+++ b/phpBB/includes/acp/acp_logs.php
@@ -53,7 +53,7 @@ class acp_logs
{
if (confirm_box(true))
{
- $where_sql = '';
+ $conditions = array();
if ($deletemark && sizeof($marked))
{
@@ -62,27 +62,23 @@ class acp_logs
{
$sql_in[] = $mark;
}
- $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
+ $conditions['log_id'] = $sql_in;
unset($sql_in);
}
if ($deleteall)
{
- $where_sql = ($sort_days) ? 'AND log_time >= ' . (time() - ($sort_days * 86400)) : '';
+ if ($sort_days)
+ {
+ $conditions['log_time'] = array('>=', time() - ($sort_days * 86400));
+ }
+
$keywords = utf8_normalize_nfc(request_var('keywords', '', true));
- $keywords_where = $phpbb_log->generate_sql_keyword($keywords, '');
- $where_sql .= ' ' . $keywords_where;
+ $conditions['keywords'] = $keywords;
}
- if ($where_sql)
- {
- $sql = 'DELETE FROM ' . LOG_TABLE . "
- WHERE log_type = {$this->log_type}
- $where_sql";
- $db->sql_query($sql);
-
- add_log('admin', 'LOG_CLEAR_' . strtoupper($mode));
- }
+ $conditions['log_type'] = $this->log_type;
+ $phpbb_log->delete($mode, $conditions);
}
else
{
diff --git a/phpBB/includes/mcp/mcp_logs.php b/phpBB/includes/mcp/mcp_logs.php
index c51877002b..be4f7c5650 100644
--- a/phpBB/includes/mcp/mcp_logs.php
+++ b/phpBB/includes/mcp/mcp_logs.php
@@ -111,33 +111,35 @@ class mcp_logs
{
if ($deletemark && sizeof($marked))
{
- $sql = 'DELETE FROM ' . LOG_TABLE . '
- WHERE log_type = ' . LOG_MOD . '
- AND ' . $db->sql_in_set('forum_id', $forum_list) . '
- AND ' . $db->sql_in_set('log_id', $marked);
- $db->sql_query($sql);
+ $conditions = array(
+ 'log_type' => LOG_MOD,
+ 'forum_id' => $forum_list,
+ 'log_id' => $marked,
+ );
- add_log('admin', 'LOG_CLEAR_MOD');
+ $phpbb_log->delete('mod', $conditions);
}
else if ($deleteall)
{
- $where_sql = ($sort_days) ? 'AND log_time >= ' . (time() - ($sort_days * 86400)) : '';
$keywords = utf8_normalize_nfc(request_var('keywords', '', true));
- $keywords_where = $phpbb_log->generate_sql_keyword($keywords, '');
- $where_sql .= ' ' . $keywords_where;
- $sql = 'DELETE FROM ' . LOG_TABLE . '
- WHERE log_type = ' . LOG_MOD . '
- AND ' . $db->sql_in_set('forum_id', $forum_list) .
- $where_sql;
+ $conditions = array(
+ 'log_type' => LOG_MOD,
+ 'forum_id' => $forum_list,
+ 'keywords' => $keywords,
+ );
+
+ if ($sort_days)
+ {
+ $conditions['log_time'] = array('>=', time() - ($sort_days * 86400));
+ }
if ($mode == 'topic_logs')
{
- $sql .= ' AND topic_id = ' . $topic_id;
+ $conditions['topic_logs'] = $topic_id;
}
- $db->sql_query($sql);
- add_log('admin', 'LOG_CLEAR_MOD');
+ $phpbb_log->delete('mod', $conditions);
}
}
else
diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php
index e3a0fa0261..a0d399ccee 100644
--- a/phpBB/phpbb/log/log.php
+++ b/phpBB/phpbb/log/log.php
@@ -330,6 +330,54 @@ class log implements \phpbb\log\log_interface
}
/**
+ * {@inheritDoc}
+ */
+ public function delete($mode, $conditions = array())
+ {
+ $sql_where = '';
+ $started = false;
+ foreach ($conditions as $field => $field_value)
+ {
+ if ($started)
+ {
+ $sql_where .= ' AND ';
+ }
+ else
+ {
+ $sql_where = 'WHERE ';
+ $started = true;
+ }
+
+ if ($field == 'keywords')
+ {
+ $sql_where .= $this->generate_sql_keyword($field_value, '', '');
+ }
+ else
+ {
+ if (is_array($field_value) && sizeof($field_value) == 2)
+ {
+ $sql_where .= $field . ' ' . $field_value[0] . ' ' . $field_value[1];
+ }
+ else if (is_array($field_value) && sizeof($field_value) > 2)
+ {
+ $sql_where .= $this->db->sql_in_set($field, $field_value);;
+ }
+ else
+ {
+ $sql_where .= $field . ' = ' . $field_value;
+ }
+
+ }
+ }
+
+ $sql = 'DELETE FROM ' . LOG_TABLE . "
+ $sql_where";
+ $this->db->sql_query($sql);
+
+ $this->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_CLEAR_' . strtoupper($mode));
+ }
+
+ /**
* Grab the logs from the database
*
* {@inheritDoc}
@@ -636,12 +684,13 @@ class log implements \phpbb\log\log_interface
/**
* Generates a sql condition for the specified keywords
*
- * @param string $keywords The keywords the user specified to search for
- * @param string $table_alias The alias of the logs' table ('l.' by default)
+ * @param string $keywords The keywords the user specified to search for
+ * @param string $table_alias The alias of the logs' table ('l.' by default)
+ * @param string $statement_operator The operator used to prefix the statement ('AND' by default)
*
* @return string Returns the SQL condition searching for the keywords
*/
- public function generate_sql_keyword($keywords, $table_alias = 'l.')
+ protected function generate_sql_keyword($keywords, $table_alias = 'l.', $statement_operator = 'AND')
{
// Use no preg_quote for $keywords because this would lead to sole
// backslashes being added. We also use an OR connection here for
@@ -686,7 +735,7 @@ class log implements \phpbb\log\log_interface
}
}
- $sql_keywords = 'AND (';
+ $sql_keywords = $statement_operator . ' (';
if (!empty($operations))
{
$sql_keywords .= $this->db->sql_in_set($table_alias . 'log_operation', $operations) . ' OR ';
diff --git a/phpBB/phpbb/log/log_interface.php b/phpBB/phpbb/log/log_interface.php
index 420ba79691..dff43b946a 100644
--- a/phpBB/phpbb/log/log_interface.php
+++ b/phpBB/phpbb/log/log_interface.php
@@ -67,6 +67,18 @@ interface log_interface
public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array());
/**
+ * Delete entries in the logs
+ *
+ * @param string $mode The mode defines which log_type is used and from which log the entries are deleted
+ * @param array $conditions An array of conditions, 3 different forms are accepted
+ * 1) <key> => 'value> transformed into 'AND <key> = <value>' (value should be an integer)
+ * 2) <key> => array(<operator>, <value>) transformed into 'AND <key> <operator> <value>' (value should be an integer)
+ * 3) <key> => array(<values>) transformed into 'AND <key> IN <values>'
+ * A special field, keywords, can also be defined. In this case only the log entries that have the keywords in log_operation or log_data will be deleted.
+ */
+ public function delete($mode, $conditions = array());
+
+ /**
* Grab the logs from the database
*
* @param string $mode The mode defines which log_type is used and ifrom which log the entry is retrieved
diff --git a/phpBB/phpbb/log/null.php b/phpBB/phpbb/log/null.php
index 77d0fbe2d7..2a79e74bbd 100644
--- a/phpBB/phpbb/log/null.php
+++ b/phpBB/phpbb/log/null.php
@@ -49,6 +49,13 @@ class null implements log_interface
/**
* {@inheritdoc}
*/
+ public function delete($mode, $conditions = array())
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '')
{
return array();