From c5a4ad3d31047f9580b19b3401ef523b0fd53733 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 10 May 2014 16:58:11 +0200 Subject: [PATCH 01/11] [ticket/10899] Using Delete All in log viewer with keyword search https://tracker.phpbb.com/browse/PHPBB3-10899 PHPBB3-10899 --- phpBB/includes/acp/acp_logs.php | 12 ++++++++++-- phpBB/includes/mcp/mcp_logs.php | 10 ++++++++-- phpBB/phpbb/log/log.php | 9 +++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/acp/acp_logs.php b/phpBB/includes/acp/acp_logs.php index 2c795bb77b..4e5db058fb 100644 --- a/phpBB/includes/acp/acp_logs.php +++ b/phpBB/includes/acp/acp_logs.php @@ -26,7 +26,7 @@ class acp_logs { global $db, $user, $auth, $template, $cache, $phpbb_container; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - global $request; + global $request, $phpbb_log; $user->add_lang('mcp'); @@ -66,7 +66,15 @@ class acp_logs unset($sql_in); } - if ($where_sql || $deleteall) + 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; + } + + if ($where_sql) { $sql = 'DELETE FROM ' . LOG_TABLE . " WHERE log_type = {$this->log_type} diff --git a/phpBB/includes/mcp/mcp_logs.php b/phpBB/includes/mcp/mcp_logs.php index 7bcb0fc477..c51877002b 100644 --- a/phpBB/includes/mcp/mcp_logs.php +++ b/phpBB/includes/mcp/mcp_logs.php @@ -33,7 +33,7 @@ class mcp_logs function main($id, $mode) { global $auth, $db, $user, $template; - global $config, $phpbb_root_path, $phpEx, $phpbb_container; + global $config, $phpbb_root_path, $phpEx, $phpbb_container, $phpbb_log; $user->add_lang('acp/common'); @@ -121,9 +121,15 @@ class mcp_logs } 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); + AND ' . $db->sql_in_set('forum_id', $forum_list) . + $where_sql; if ($mode == 'topic_logs') { diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index e4c5ce47d9..e3a0fa0261 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -636,11 +636,12 @@ 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) * * @return string Returns the SQL condition searching for the keywords */ - protected function generate_sql_keyword($keywords) + public function generate_sql_keyword($keywords, $table_alias = 'l.') { // Use no preg_quote for $keywords because this would lead to sole // backslashes being added. We also use an OR connection here for @@ -688,9 +689,9 @@ class log implements \phpbb\log\log_interface $sql_keywords = 'AND ('; 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) . ')'; } From c6d7875b9b76a931e27e8dbf742ad7af25fe19cf Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 10 May 2014 18:24:07 +0200 Subject: [PATCH 02/11] [ticket/10899] Refactoring in \phpbb\log\log_interface PHPBB3-10899 --- phpBB/includes/acp/acp_logs.php | 24 ++++++------- phpBB/includes/mcp/mcp_logs.php | 34 +++++++++--------- phpBB/phpbb/log/log.php | 57 ++++++++++++++++++++++++++++--- phpBB/phpbb/log/log_interface.php | 12 +++++++ phpBB/phpbb/log/null.php | 7 ++++ 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 @@ -329,6 +329,54 @@ class log implements \phpbb\log\log_interface return $this->db->sql_nextid(); } + /** + * {@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 * @@ -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 @@ -66,6 +66,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) => 'value> transformed into 'AND = ' (value should be an integer) + * 2) => array(, ) transformed into 'AND ' (value should be an integer) + * 3) => array() transformed into 'AND IN ' + * 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 * 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 @@ -46,6 +46,13 @@ class null implements log_interface return false; } + /** + * {@inheritdoc} + */ + public function delete($mode, $conditions = array()) + { + } + /** * {@inheritdoc} */ From 56aaba696f01a920713a08f0b418604609505d83 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 10 May 2014 18:25:24 +0200 Subject: [PATCH 03/11] [ticket/10899] Typo PHPBB3-10899 --- phpBB/phpbb/log/log_interface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/log/log_interface.php b/phpBB/phpbb/log/log_interface.php index dff43b946a..165eeaeed2 100644 --- a/phpBB/phpbb/log/log_interface.php +++ b/phpBB/phpbb/log/log_interface.php @@ -71,7 +71,7 @@ interface log_interface * * @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) => 'value> transformed into 'AND = ' (value should be an integer) + * 1) => transformed into 'AND = ' (value should be an integer) * 2) => array(, ) transformed into 'AND ' (value should be an integer) * 3) => array() transformed into 'AND IN ' * 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. From 164f52c3f30d6afd85e1f25cea7ebc75f327d12d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 10 May 2014 19:04:37 +0200 Subject: [PATCH 04/11] [ticket/10899] Remove extra ';' PHPBB3-10899 --- phpBB/phpbb/log/log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index a0d399ccee..4b1a8e40ad 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -360,7 +360,7 @@ class log implements \phpbb\log\log_interface } else if (is_array($field_value) && sizeof($field_value) > 2) { - $sql_where .= $this->db->sql_in_set($field, $field_value);; + $sql_where .= $this->db->sql_in_set($field, $field_value); } else { From ac1eb2d789d81381fd2298c03a1960707e1c90c3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 27 May 2014 19:57:25 +0200 Subject: [PATCH 05/11] [ticket/10899] Get $phpbb_log from the container PHPBB3-10899 --- phpBB/includes/acp/acp_logs.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_logs.php b/phpBB/includes/acp/acp_logs.php index 11d911151b..c5443ef5ee 100644 --- a/phpBB/includes/acp/acp_logs.php +++ b/phpBB/includes/acp/acp_logs.php @@ -26,7 +26,7 @@ class acp_logs { global $db, $user, $auth, $template, $cache, $phpbb_container; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - global $request, $phpbb_log; + global $request; $user->add_lang('mcp'); @@ -78,6 +78,8 @@ class acp_logs } $conditions['log_type'] = $this->log_type; + + $phpbb_log = $phpbb_container->get('log'); $phpbb_log->delete($mode, $conditions); } else From 05e76e55e149936d112ccb3441f88bbd3ce235fb Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 28 May 2014 00:54:22 +0200 Subject: [PATCH 06/11] [ticket/10899] Add unit tests PHPBB3-10899 --- phpBB/phpbb/log/log.php | 49 +++++-- tests/log/delete_test.php | 60 ++++++++ tests/log/fixtures/delete_log.xml | 232 ++++++++++++++++++++++++++++++ 3 files changed, 327 insertions(+), 14 deletions(-) create mode 100644 tests/log/delete_test.php create mode 100644 tests/log/fixtures/delete_log.xml diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 4b1a8e40ad..8b51ed7758 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -334,19 +334,41 @@ class log implements \phpbb\log\log_interface */ public function delete($mode, $conditions = array()) { - $sql_where = ''; - $started = false; + 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; + } + + if ($log_type === false) + { + return; + } + + $sql_where = 'WHERE log_type = ' . $log_type; foreach ($conditions as $field => $field_value) { - if ($started) - { - $sql_where .= ' AND '; - } - else - { - $sql_where = 'WHERE '; - $started = true; - } + $sql_where .= ' AND '; if ($field == 'keywords') { @@ -354,11 +376,11 @@ class log implements \phpbb\log\log_interface } else { - if (is_array($field_value) && sizeof($field_value) == 2) + if (is_array($field_value) && sizeof($field_value) == 2 && is_string($field_value[0])) { $sql_where .= $field . ' ' . $field_value[0] . ' ' . $field_value[1]; } - else if (is_array($field_value) && sizeof($field_value) > 2) + else if (is_array($field_value)) { $sql_where .= $this->db->sql_in_set($field, $field_value); } @@ -366,7 +388,6 @@ class log implements \phpbb\log\log_interface { $sql_where .= $field . ' = ' . $field_value; } - } } diff --git a/tests/log/delete_test.php b/tests/log/delete_test.php new file mode 100644 index 0000000000..54ea4145ef --- /dev/null +++ b/tests/log/delete_test.php @@ -0,0 +1,60 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_log.xml'); + } + + public function test_log_delete() + { + global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher, $auth; + + $db = $this->new_dbal(); + $cache = new phpbb_mock_cache; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = $this->getMock('\phpbb\user'); + $user->data['user_id'] = 1; + $auth = $this->getMock('\phpbb\auth\auth'); + + $log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + + // Delete all admin logs + $this->assertCount(2, $log->get_logs('admin')); + $log->delete('admin'); + // One entry is added to the admin log when the logs are purged + $this->assertCount(1, $log->get_logs('admin')); + + // Delete with keyword + $this->assertCount(1, $log->get_logs('mod', false, 0, 0, 0, 0, 0, 0, 'l.log_time DESC', 'guest')); + $log->delete('mod', array('keywords' => 'guest')); + $this->assertEmpty($log->get_logs('mod', false, 0, 0, 0, 0, 0, 0, 'l.log_time DESC', 'guest')); + + // Delete with simples conditions + $this->assertCount(3, $log->get_logs('mod', false, 0, 0, 12, 0, 1, 0, 'l.log_time DESC')); + $log->delete('mod', array('forum_id' => 12, 'user_id' => 1)); + $this->assertEmpty($log->get_logs('mod', false, 0, 0, 12, 0, 1, 0, 'l.log_time DESC')); + + // Delete with IN condition + $this->assertCount(2, $log->get_logs('mod', false, 0, 0, array(13, 14), 0, 0, 0, 'l.log_time DESC')); + $log->delete('mod', array('forum_id' => array(14, 13))); + $this->assertEmpty($log->get_logs('mod', false, 0, 0, array(13, 14), 0, 0, 0, 'l.log_time DESC')); + + // Delete with a custom condition (ie: WHERE x >= 10) + $this->assertCount(3, $log->get_logs('critical', false, 0, 0, 0, 0, 0, 0, 'l.log_time DESC')); + $log->delete('critical', array('user_id' => array('>', 1))); + $this->assertCount(1, $log->get_logs('critical', false, 0, 0, 0, 0, 0, 0, 'l.log_time DESC')); + } +} diff --git a/tests/log/fixtures/delete_log.xml b/tests/log/fixtures/delete_log.xml new file mode 100644 index 0000000000..4b2402102e --- /dev/null +++ b/tests/log/fixtures/delete_log.xml @@ -0,0 +1,232 @@ + + + + log_id + log_type + user_id + forum_id + topic_id + reportee_id + log_ip + log_time + log_operation + log_data + + 1 + 0 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_INSTALL_INSTALLED + a:1:{i:0;s:9:"3.1.0-dev";} + + + 2 + 0 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_KEY_NOT_EXISTS + a:1:{i:0;s:15:"additional_data";} + + + 3 + 2 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_CRITICAL + a:1:{i:0;s:13:"critical data";} + + + 4 + 1 + 1 + 12 + 34 + 0 + 127.0.0.1 + 1 + LOG_MOD + + + + 5 + 1 + 1 + 12 + 45 + 0 + 127.0.0.1 + 1 + LOG_MOD + + + + 6 + 1 + 1 + 23 + 56 + 0 + 127.0.0.1 + 1 + LOG_MOD + + + + 7 + 1 + 1 + 12 + 45 + 0 + 127.0.0.1 + 1 + LOG_MOD2 + + + + 8 + 3 + 1 + 0 + 0 + 2 + 127.0.0.1 + 1 + LOG_USER + a:1:{i:0;s:5:"admin";} + + + 9 + 3 + 1 + 0 + 0 + 1 + 127.0.0.1 + 1 + LOG_USER + a:1:{i:0;s:5:"guest";} + + + 10 + 3 + 1 + 0 + 0 + 0 + 127.0.0.1 + 1 + LOG_SINGULAR_PLURAL + a:1:{i:0;i:2;} + + + 11 + 1 + 1 + 15 + 3 + 0 + 127.0.0.1 + 1 + LOG_MOD3 + a:1:{i:0;s:5:"guest";} + + + 12 + 1 + 1 + 13 + 0 + 0 + 127.0.0.1 + 1 + + + + + 13 + 1 + 1 + 14 + 0 + 0 + 127.0.0.1 + 1 + + + + + 14 + 2 + 2 + 0 + 0 + 0 + 127.0.0.1 + 1 + + + + + 15 + 2 + 2 + 0 + 0 + 0 + 127.0.0.1 + 1 + + + +
+ + user_id + username + username_clean + user_permissions + user_sig + + 1 + Anonymous + Anonymous + + + + + 2 + admin + admin + + + +
+ + topic_id + forum_id + + 34 + 12 + + + 45 + 12 + + + 56 + 23 + +
+
From dfec62c68d7cee49811b09366f61cf3755ed6ede Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 28 May 2014 01:14:36 +0200 Subject: [PATCH 07/11] [ticket/10899] Fix typo in the class name PHPBB3-10899 --- tests/log/delete_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/log/delete_test.php b/tests/log/delete_test.php index 54ea4145ef..d36a8c8623 100644 --- a/tests/log/delete_test.php +++ b/tests/log/delete_test.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; -class phpbb_log_add_test extends phpbb_database_test_case +class phpbb_log_delete_test extends phpbb_database_test_case { public function getDataSet() { From d3f4dbedde157c316fe5a675de923e9b1e73d6f2 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 28 May 2014 11:50:13 +0200 Subject: [PATCH 08/11] [ticket/10899] Remove trailing ; PHPBB3-10899 --- phpBB/phpbb/log/log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 8b51ed7758..206a665283 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -353,7 +353,7 @@ class log implements \phpbb\log\log_interface break; case 'critical': - $log_type = LOG_CRITICAL;; + $log_type = LOG_CRITICAL; break; default: From 59f39273d42bb863ffa0d46e017919bdbe39d8d5 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 28 May 2014 23:20:50 +0200 Subject: [PATCH 09/11] [ticket/10899] Add event core.delete_log PHPBB3-10899 --- phpBB/phpbb/log/log.php | 29 ++++++++++++++++++++++++++--- phpBB/phpbb/log/log_interface.php | 4 ++-- tests/log/delete_test.php | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 206a665283..6c0c160b58 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -360,6 +360,29 @@ class log implements \phpbb\log\log_interface $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.add_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) => transformed into 'AND = ' (value should be an integer) + * 2) => array(, ) transformed into 'AND ' (values can't be an array) + * 3) => array('IN' => array()) transformed into 'AND IN ' + * 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; @@ -376,13 +399,13 @@ class log implements \phpbb\log\log_interface } else { - if (is_array($field_value) && sizeof($field_value) == 2 && is_string($field_value[0])) + 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)) + else if (is_array($field_value) && sizeof($field_value) == 1 && is_array($field_value['IN'])) { - $sql_where .= $this->db->sql_in_set($field, $field_value); + $sql_where .= $this->db->sql_in_set($field, $field_value['IN']); } else { diff --git a/phpBB/phpbb/log/log_interface.php b/phpBB/phpbb/log/log_interface.php index 165eeaeed2..eb3f700953 100644 --- a/phpBB/phpbb/log/log_interface.php +++ b/phpBB/phpbb/log/log_interface.php @@ -72,8 +72,8 @@ interface log_interface * @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) => transformed into 'AND = ' (value should be an integer) - * 2) => array(, ) transformed into 'AND ' (value should be an integer) - * 3) => array() transformed into 'AND IN ' + * 2) => array(, ) transformed into 'AND ' (values can't be an array) + * 3) => array('IN' => array()) transformed into 'AND IN ' * 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()); diff --git a/tests/log/delete_test.php b/tests/log/delete_test.php index d36a8c8623..f10e3e582b 100644 --- a/tests/log/delete_test.php +++ b/tests/log/delete_test.php @@ -49,7 +49,7 @@ class phpbb_log_delete_test extends phpbb_database_test_case // Delete with IN condition $this->assertCount(2, $log->get_logs('mod', false, 0, 0, array(13, 14), 0, 0, 0, 'l.log_time DESC')); - $log->delete('mod', array('forum_id' => array(14, 13))); + $log->delete('mod', array('forum_id' => array('IN' => array(14, 13)))); $this->assertEmpty($log->get_logs('mod', false, 0, 0, array(13, 14), 0, 0, 0, 'l.log_time DESC')); // Delete with a custom condition (ie: WHERE x >= 10) From ff5fd3442d9e985e0b3c48f5a13254448d27d929 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 28 May 2014 23:30:47 +0200 Subject: [PATCH 10/11] [ticket/10899] Use isset($field_value['IN']) PHPBB3-10899 --- phpBB/phpbb/log/log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 6c0c160b58..879a1b49e8 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -403,7 +403,7 @@ class log implements \phpbb\log\log_interface { $sql_where .= $field . ' ' . $field_value[0] . ' ' . $field_value[1]; } - else if (is_array($field_value) && sizeof($field_value) == 1 && is_array($field_value['IN'])) + 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']); } From 4b3bba6693d96fe5ce918a635af8ff5ec7a8c1f0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 29 May 2014 02:30:15 +0200 Subject: [PATCH 11/11] [ticket/10899] Update doc block PHPBB3-10899 --- phpBB/phpbb/log/log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 879a1b49e8..e7875e1a12 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -366,7 +366,7 @@ class log implements \phpbb\log\log_interface * 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.add_log + * @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