mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +00:00
[ticket/10899] Add event core.delete_log
PHPBB3-10899
This commit is contained in:
parent
d3f4dbedde
commit
59f39273d4
3 changed files with 29 additions and 6 deletions
|
@ -360,6 +360,29 @@ class log implements \phpbb\log\log_interface
|
||||||
$log_type = false;
|
$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) <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)
|
if ($log_type === false)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -376,13 +399,13 @@ class log implements \phpbb\log\log_interface
|
||||||
}
|
}
|
||||||
else
|
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];
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 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
|
* @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)
|
* 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)
|
* 2) <key> => array(<operator>, <value>) transformed into 'AND <key> <operator> <value>' (values can't be an array)
|
||||||
* 3) <key> => array(<values>) transformed into 'AND <key> IN <values>'
|
* 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.
|
* 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());
|
public function delete($mode, $conditions = array());
|
||||||
|
|
|
@ -49,7 +49,7 @@ class phpbb_log_delete_test extends phpbb_database_test_case
|
||||||
|
|
||||||
// Delete with IN condition
|
// Delete with IN condition
|
||||||
$this->assertCount(2, $log->get_logs('mod', false, 0, 0, array(13, 14), 0, 0, 0, 'l.log_time DESC'));
|
$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'));
|
$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)
|
// Delete with a custom condition (ie: WHERE x >= 10)
|
||||||
|
|
Loading…
Add table
Reference in a new issue