Fix old log params of log type rights for new api logparam style
authorumherirrender <umherirrender_de.wp@web.de>
Fri, 17 Apr 2015 16:24:50 +0000 (18:24 +0200)
committerUmherirrender <umherirrender_de.wp@web.de>
Fri, 17 Apr 2015 18:03:52 +0000 (18:03 +0000)
The log param of right changes can also just be a string. The new api
logparam style does not recognize this and shows an error:
Argument 1 passed to ApiResult::setIndexedTagName() must be an instance of array, string given

Centralize the code in a new helper function and use it also for the gui
part.

Follow-Up: I6846ce09322eb404c506b5a51780a44ce9279fe2
Change-Id: I4762743b3f43e6ebd806d3ae516507ae66478e96

includes/logging/RightsLogFormatter.php

index 597bec5..f69530c 100644 (file)
@@ -67,20 +67,8 @@ class RightsLogFormatter extends LogFormatter {
                        return $params;
                }
 
-               $oldGroups = $params[3];
-               $newGroups = $params[4];
-
-               // Less old entries
-               if ( $oldGroups === '' ) {
-                       $oldGroups = array();
-               } elseif ( is_string( $oldGroups ) ) {
-                       $oldGroups = array_map( 'trim', explode( ',', $oldGroups ) );
-               }
-               if ( $newGroups === '' ) {
-                       $newGroups = array();
-               } elseif ( is_string( $newGroups ) ) {
-                       $newGroups = array_map( 'trim', explode( ',', $newGroups ) );
-               }
+               $oldGroups = $this->makeGroupArray( $params[3] );
+               $newGroups = $this->makeGroupArray( $params[4] );
 
                $userName = $this->entry->getTarget()->getText();
                if ( !$this->plaintext && count( $oldGroups ) ) {
@@ -128,6 +116,9 @@ class RightsLogFormatter extends LogFormatter {
                        }
                }
 
+               $params['4:array:oldgroups'] = $this->makeGroupArray( $params['4:array:oldgroups'] );
+               $params['5:array:newgroups'] = $this->makeGroupArray( $params['5:array:newgroups'] );
+
                return $params;
        }
 
@@ -141,4 +132,14 @@ class RightsLogFormatter extends LogFormatter {
                }
                return $ret;
        }
+
+       private function makeGroupArray( $group ) {
+               // Migrate old group params from string to array
+               if ( $group === '' ) {
+                       $group = array();
+               } elseif ( is_string( $group ) ) {
+                       $group = array_map( 'trim', explode( ',', $group ) );
+               }
+               return $group;
+       }
 }