From 8c04cd7647156eaa45769797fa4bd30bfac94371 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 5 Jul 2013 23:33:59 -0700 Subject: [PATCH] Added log_search tag support to ManualLogEntry Change-Id: I7e57cd3f2b8790aecd1c1831325c59a2be600780 --- includes/logging/LogEntry.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 92a0abe4b5..fee4fab6e0 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -334,6 +334,7 @@ class ManualLogEntry extends LogEntryBase { protected $type; ///!< @var string protected $subtype; ///!< @var string protected $parameters = array(); ///!< @var array + protected $relations = array(); ///!< @var array protected $performer; ///!< @var User protected $target; ///!< @var Title protected $timestamp; ///!< @var string @@ -373,6 +374,17 @@ class ManualLogEntry extends LogEntryBase { $this->parameters = $parameters; } + /** + * Declare arbitrary tag/value relations to this log entry. + * These can be used to filter log entries later on. + * + * @param array Map of (tag => (list of values)) + * @since 1.22 + */ + public function setRelations( array $relations ) { + $this->relations = $relations; + } + /** * Set the user that performed the action being logged. * @@ -464,6 +476,24 @@ class ManualLogEntry extends LogEntryBase { ); $dbw->insert( 'logging', $data, __METHOD__ ); $this->id = !is_null( $id ) ? $id : $dbw->insertId(); + + $rows = array(); + foreach ( $this->relations as $tag => $values ) { + if ( !strlen( $tag ) ) { + throw new MWException( "Got empty log search tag." ); + } + foreach ( $values as $value ) { + $rows[] = array( + 'ls_field' => $tag, + 'ls_value' => $value, + 'ls_log_id' => $this->id + ); + } + } + if ( count( $rows ) ) { + $dbw->insert( 'log_search', $rows, __METHOD__, 'IGNORE' ); + } + return $this->id; } -- 2.20.1