1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-21 00:02:18 +02:00

Merge pull request #3457 from brunoais/ticket/13661

[ticket/13661] Add event to allow editing the queries used to get the logs

* brunoais/ticket/13661:
  [ticket/13661] BUMP version to 3.1.5-dev
  [ticket/13661] Brackets in their own line
  [ticket/13661] Re-Fixed  $log_type -> $log_time
  [ticket/13661] Wrong event @since version
  [ticket/13661] Removed superfluous whitespace
  [ticket/13661] bugfix: The conditional is the log_time, not log_type
  [ticket/13661] Fixed the "FROM" in the built query.
  [ticket/13661] Add event to allow editing the queries used to get the logs
  [ticket/13661] Transform queries to get logs and log count into built queries
This commit is contained in:
Joas Schilling 2015-05-28 12:52:19 +02:00
commit b1d829c232

View File

@ -521,15 +521,77 @@ class log implements \phpbb\log\log_interface
$sql_keywords = $this->generate_sql_keyword($keywords);
}
$get_logs_sql_ary = array(
'SELECT' => 'l.*, u.username, u.username_clean, u.user_colour',
'FROM' => array(
$this->log_table => 'l',
USERS_TABLE => 'u',
),
'WHERE' => 'l.log_type = ' . (int) $log_type . "
AND l.user_id = u.user_id
$sql_keywords
$sql_additional",
'ORDER_BY' => $sort_by,
);
if($log_time)
{
$get_logs_sql_ary['WHERE'] = 'l.log_time >= ' . (int) $log_time . '
AND ' . $get_logs_sql_ary['WHERE'];
}
/**
* Modify the query to obtain the logs data
*
* @event core.get_logs_main_query_before
* @var array get_logs_sql_ary The array in the format of the query builder with the query
* to get the log count and the log list
* @var string mode Mode of the entries we display
* @var bool count_logs Do we count all matching entries?
* @var int limit Limit the number of entries
* @var int offset Offset when fetching the entries
* @var mixed forum_id Limit entries to the forum_id,
* can also be an array of forum_ids
* @var int topic_id Limit entries to the topic_id
* @var int user_id Limit entries to the user_id
* @var int log_time Limit maximum age of log entries
* @var string sort_by SQL order option
* @var string keywords Will only return entries that have the
* keywords in log_operation or log_data
* @var string profile_url URL to the users profile
* @var int log_type Limit logs to a certain type. If log_type
* is false, no entries will be returned.
* @var string sql_additional Additional conditions for the entries,
* e.g.: 'AND l.forum_id = 1'
* @since 3.1.5-RC1
*/
$vars = array(
'get_logs_sql_ary',
'mode',
'count_logs',
'limit',
'offset',
'forum_id',
'topic_id',
'user_id',
'log_time',
'sort_by',
'keywords',
'profile_url',
'log_type',
'sql_additional',
);
extract($this->dispatcher->trigger_event('core.get_logs_main_query_before', compact($vars)));
if ($count_logs)
{
$sql = 'SELECT COUNT(l.log_id) AS total_entries
FROM ' . $this->log_table . ' l, ' . USERS_TABLE . ' u
WHERE l.log_type = ' . (int) $log_type . '
AND l.user_id = u.user_id
AND l.log_time >= ' . (int) $log_time . "
$sql_keywords
$sql_additional";
$count_logs_sql_ary = $get_logs_sql_ary;
$count_logs_sql_ary['SELECT'] = 'COUNT(l.log_id) AS total_entries';
unset($count_logs_sql_ary['ORDER_BY']);
$sql = $this->db->sql_build_query('SELECT', $count_logs_sql_ary);
$result = $this->db->sql_query($sql);
$this->entry_count = (int) $this->db->sql_fetchfield('total_entries');
$this->db->sql_freeresult($result);
@ -548,14 +610,7 @@ class log implements \phpbb\log\log_interface
}
}
$sql = 'SELECT l.*, u.username, u.username_clean, u.user_colour
FROM ' . $this->log_table . ' l, ' . USERS_TABLE . ' u
WHERE l.log_type = ' . (int) $log_type . '
AND u.user_id = l.user_id
' . (($log_time) ? 'AND l.log_time >= ' . (int) $log_time : '') . "
$sql_keywords
$sql_additional
ORDER BY $sort_by";
$sql = $this->db->sql_build_query('SELECT', $get_logs_sql_ary);
$result = $this->db->sql_query_limit($sql, $limit, $this->last_page_offset);
$i = 0;