mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-11 22:08:54 +00:00
[ticket/10714] Refactor disable mechanism to only disable certain types
Only disable admin log when adding multiple users, so critical errors are still logged. PHPBB3-10714
This commit is contained in:
parent
2c7f498c1b
commit
3170845a50
3 changed files with 37 additions and 11 deletions
|
@ -302,7 +302,7 @@ function user_add($user_row, $cp_data = false)
|
||||||
global $phpbb_log;
|
global $phpbb_log;
|
||||||
|
|
||||||
// Because these actions only fill the log unneccessarily we skip the add_log() entry.
|
// Because these actions only fill the log unneccessarily we skip the add_log() entry.
|
||||||
$phpbb_log->disable();
|
$phpbb_log->disable('admin');
|
||||||
|
|
||||||
// Add user to "newly registered users" group and set to default group if admin specified so.
|
// Add user to "newly registered users" group and set to default group if admin specified so.
|
||||||
if ($config['new_member_group_default'])
|
if ($config['new_member_group_default'])
|
||||||
|
@ -315,7 +315,7 @@ function user_add($user_row, $cp_data = false)
|
||||||
group_user_add($add_group_id, $user_id);
|
group_user_add($add_group_id, $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$phpbb_log->enable();
|
$phpbb_log->enable('admin');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,23 +25,31 @@ interface phpbb_log_interface
|
||||||
/**
|
/**
|
||||||
* This function returns the state of the log-system.
|
* This function returns the state of the log-system.
|
||||||
*
|
*
|
||||||
* @return bool True if log is enabled
|
* @param string $type The log type we want to check. Empty to get global log status.
|
||||||
|
*
|
||||||
|
* @return bool True if log for the type is enabled
|
||||||
*/
|
*/
|
||||||
public function is_enabled();
|
public function is_enabled($type = '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function allows disable the log-system. When add_log is called, the log will not be added to the database.
|
* This function allows disable the log-system. When add_log is called, the log will not be added to the database.
|
||||||
*
|
*
|
||||||
|
* @param mixed $type The log type we want to disable. Empty to disable all logs.
|
||||||
|
* Can also be an array of types
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function disable();
|
public function disable($type = '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function allows re-enable the log-system.
|
* This function allows re-enable the log-system.
|
||||||
*
|
*
|
||||||
|
* @param mixed $type The log type we want to enable. Empty to enable all logs.
|
||||||
|
* Can also be an array of types
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function enable();
|
public function enable($type = '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a log to the database
|
* Adds a log to the database
|
||||||
|
|
|
@ -19,13 +19,21 @@ class phpbb_log_add_test extends phpbb_database_test_case
|
||||||
public function test_log_enabled()
|
public function test_log_enabled()
|
||||||
{
|
{
|
||||||
$log = new phpbb_log(LOG_TABLE);
|
$log = new phpbb_log(LOG_TABLE);
|
||||||
$this->assertTrue($log->is_enabled());
|
$this->assertTrue($log->is_enabled(), 'Initialise failed');
|
||||||
|
|
||||||
$log->disable();
|
$log->disable();
|
||||||
$this->assertFalse($log->is_enabled());
|
$this->assertFalse($log->is_enabled(), 'Disable all failed');
|
||||||
|
|
||||||
$log->enable();
|
$log->enable();
|
||||||
$this->assertTrue($log->is_enabled());
|
$this->assertTrue($log->is_enabled(), 'Enable all failed');
|
||||||
|
|
||||||
|
$log->disable('admin');
|
||||||
|
$this->assertFalse($log->is_enabled('admin'), 'Disable admin failed');
|
||||||
|
$this->assertTrue($log->is_enabled('user'), 'User should be enabled, is disabled');
|
||||||
|
$this->assertTrue($log->is_enabled(), 'Disable admin disabled all');
|
||||||
|
|
||||||
|
$log->enable('admin');
|
||||||
|
$this->assertTrue($log->is_enabled('admin'), 'Enable admin failed');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_log_add()
|
public function test_log_add()
|
||||||
|
@ -45,9 +53,19 @@ class phpbb_log_add_test extends phpbb_database_test_case
|
||||||
$log = new phpbb_log(LOG_TABLE);
|
$log = new phpbb_log(LOG_TABLE);
|
||||||
$this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time));
|
$this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time));
|
||||||
|
|
||||||
// Disable logging
|
// Disable logging for all types
|
||||||
$log->disable();
|
$log->disable();
|
||||||
$this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time));
|
$this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for all types failed');
|
||||||
|
$log->enable();
|
||||||
|
|
||||||
|
// Disable logging for same type
|
||||||
|
$log->disable('critical');
|
||||||
|
$this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for same type failed');
|
||||||
|
$log->enable();
|
||||||
|
|
||||||
|
// Disable logging for different type
|
||||||
|
$log->disable('admin');
|
||||||
|
$this->assertEquals(2, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for different types failed');
|
||||||
$log->enable();
|
$log->enable();
|
||||||
|
|
||||||
// Invalid mode specified
|
// Invalid mode specified
|
||||||
|
|
Loading…
Add table
Reference in a new issue