From: Aaron Schulz Date: Fri, 16 May 2014 22:23:26 +0000 (-0700) Subject: For job param arrays of scalars, show the key/values as JSON in the log X-Git-Tag: 1.31.0-rc.0~15672^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%7B%7B%20url_for%28%27admin_users%27%29%20%7D%7D?a=commitdiff_plain;h=a61ff504feb3162680329fcd3fdb3ecf16ac39e2;p=lhc%2Fweb%2Fwiklou.git For job param arrays of scalars, show the key/values as JSON in the log Change-Id: Ia9056dd1d4669102178046961ddaf6e8560e5903 --- diff --git a/includes/jobqueue/Job.php b/includes/jobqueue/Job.php index 4ee370e8d2..35b4f13657 100644 --- a/includes/jobqueue/Job.php +++ b/includes/jobqueue/Job.php @@ -291,6 +291,14 @@ abstract class Job implements IJobSpecification { * @return string */ public function toString() { + $truncFunc = function( $value ) { + $value = (string)$value; + if ( mb_strlen( $value ) > 1024 ) { + $value = "string(" . mb_strlen( $value ) . ")"; + } + return $value; + }; + $paramString = ''; if ( $this->params ) { foreach ( $this->params as $key => $value ) { @@ -298,16 +306,25 @@ abstract class Job implements IJobSpecification { $paramString .= ' '; } if ( is_array( $value ) ) { - $value = "array(" . count( $value ) . ")"; + $filteredValue = array(); + foreach ( $value as $k => $v ) { + if ( is_scalar( $v ) ) { + $filteredValue[$k] = $truncFunc( $v ); + } else { + $filteredValue = null; + break; + } + } + if ( $filteredValue ) { + $value = FormatJson::encode( $filteredValue ); + } else { + $value = "array(" . count( $value ) . ")"; + } } elseif ( is_object( $value ) && !method_exists( $value, '__toString' ) ) { $value = "object(" . get_class( $value ) . ")"; } - $value = (string)$value; - if ( mb_strlen( $value ) > 1024 ) { - $value = "string(" . mb_strlen( $value ) . ")"; - } - $paramString .= "$key=$value"; + $paramString .= "$key={$truncFunc( $value )}"; } }