Added log_search tag support to ManualLogEntry
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 6 Jul 2013 06:33:59 +0000 (23:33 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Sat, 6 Jul 2013 17:42:54 +0000 (10:42 -0700)
Change-Id: I7e57cd3f2b8790aecd1c1831325c59a2be600780

includes/logging/LogEntry.php

index 92a0abe..fee4fab 100644 (file)
@@ -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;
        }