From 59f39273d42bb863ffa0d46e017919bdbe39d8d5 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 28 May 2014 23:20:50 +0200 Subject: [PATCH] [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)