diff options
| author | Joas Schilling <nickvergessen@gmx.de> | 2014-05-30 23:13:00 +0200 |
|---|---|---|
| committer | Joas Schilling <nickvergessen@gmx.de> | 2014-05-30 23:13:00 +0200 |
| commit | 40218ba5e6597d0ea83fe154259f72ff8d8190c0 (patch) | |
| tree | e11c3d0ddd49f7d225a8599f2e73731af9ae2dc4 /phpBB/phpbb/log/log.php | |
| parent | be52ea882ad55af8bd8a59814b11488025fb3563 (diff) | |
| parent | 4b3bba6693d96fe5ce918a635af8ff5ec7a8c1f0 (diff) | |
| download | forums-40218ba5e6597d0ea83fe154259f72ff8d8190c0.tar forums-40218ba5e6597d0ea83fe154259f72ff8d8190c0.tar.gz forums-40218ba5e6597d0ea83fe154259f72ff8d8190c0.tar.bz2 forums-40218ba5e6597d0ea83fe154259f72ff8d8190c0.tar.xz forums-40218ba5e6597d0ea83fe154259f72ff8d8190c0.zip | |
Merge pull request #2433 from Nicofuma/ticket/10899
[ticket/10899] Using Delete All in log viewer with keyword search
* Nicofuma/ticket/10899:
[ticket/10899] Update doc block
[ticket/10899] Use isset($field_value['IN'])
[ticket/10899] Add event core.delete_log
[ticket/10899] Remove trailing ;
[ticket/10899] Fix typo in the class name
[ticket/10899] Add unit tests
[ticket/10899] Get $phpbb_log from the container
[ticket/10899] Remove extra ';'
[ticket/10899] Typo
[ticket/10899] Refactoring in \phpbb\log\log_interface
[ticket/10899] Using Delete All in log viewer with keyword search
Diffstat (limited to 'phpBB/phpbb/log/log.php')
| -rw-r--r-- | phpBB/phpbb/log/log.php | 104 |
1 files changed, 99 insertions, 5 deletions
diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index d83fa90a8e..453cb740bb 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -332,6 +332,98 @@ class log implements \phpbb\log\log_interface } /** + * {@inheritDoc} + */ + public function delete($mode, $conditions = array()) + { + switch ($mode) + { + case 'admin': + $log_type = LOG_ADMIN; + break; + + case 'mod': + $log_type = LOG_MOD; + break; + + case 'user': + $log_type = LOG_USERS; + break; + + case 'users': + $log_type = LOG_USERS; + break; + + case 'critical': + $log_type = LOG_CRITICAL; + break; + + default: + $log_type = false; + } + + /** + * Allows to modify log data before we delete it from the database + * + * NOTE: if sql_ary does not contain a log_type value, the entry will + * not be deleted in the database. So ensure to set it, if needed. + * + * @event core.delete_log + * @var string mode Mode of the entry we log + * @var string log_type Type ID of the log (should be different than false) + * @var 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>' (values can't be an array) + * 3) <key> => array('IN' => 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. + * @since 3.1.0-b4 + */ + $vars = array( + 'mode', + 'log_type', + 'conditions', + ); + extract($this->dispatcher->trigger_event('core.delete_log', compact($vars))); + + if ($log_type === false) + { + return; + } + + $sql_where = 'WHERE log_type = ' . $log_type; + foreach ($conditions as $field => $field_value) + { + $sql_where .= ' AND '; + + if ($field == 'keywords') + { + $sql_where .= $this->generate_sql_keyword($field_value, '', ''); + } + else + { + if (is_array($field_value) && sizeof($field_value) == 2 && !is_array($field_value[1])) + { + $sql_where .= $field . ' ' . $field_value[0] . ' ' . $field_value[1]; + } + else if (is_array($field_value) && isset($field_value['IN']) && is_array($field_value['IN'])) + { + $sql_where .= $this->db->sql_in_set($field, $field_value['IN']); + } + 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} @@ -638,11 +730,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 $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 */ - protected function generate_sql_keyword($keywords) + 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 @@ -687,12 +781,12 @@ class log implements \phpbb\log\log_interface } } - $sql_keywords = 'AND ('; + $sql_keywords = $statement_operator . ' ('; if (!empty($operations)) { - $sql_keywords .= $this->db->sql_in_set('l.log_operation', $operations) . ' OR '; + $sql_keywords .= $this->db->sql_in_set($table_alias . 'log_operation', $operations) . ' OR '; } - $sql_lower = $this->db->sql_lower_text('l.log_data'); + $sql_lower = $this->db->sql_lower_text($table_alias . 'log_data'); $sql_keywords .= " $sql_lower " . implode(" OR $sql_lower ", $keywords) . ')'; } |
