jenkins-bot has submitted this change and it was merged. Change subject: Make Job::toString() handle array parameters better ......................................................................
Make Job::toString() handle array parameters better Previously it would result in array(x) in fairly simple cases. Change-Id: I6bfe67faa45835babb2c7e259b5cd158e0f0a649 --- M includes/jobqueue/Job.php M tests/phpunit/includes/jobqueue/JobTest.php 2 files changed, 34 insertions(+), 14 deletions(-) Approvals: Aaron Schulz: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/jobqueue/Job.php b/includes/jobqueue/Job.php index 48d38d9..9ccf6f8 100644 --- a/includes/jobqueue/Job.php +++ b/includes/jobqueue/Job.php @@ -315,14 +315,6 @@ * @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 ) { @@ -332,14 +324,14 @@ if ( is_array( $value ) ) { $filteredValue = []; foreach ( $value as $k => $v ) { - if ( is_scalar( $v ) ) { - $filteredValue[$k] = $truncFunc( $v ); + $json = FormatJson::encode( $v ); + if ( $json === false || mb_strlen( $json ) > 512 ) { + $filteredValue[$k] = gettype( $v ) . '(...)'; } else { - $filteredValue = null; - break; + $filteredValue[$k] = $v; } } - if ( $filteredValue && count( $filteredValue ) < 10 ) { + if ( count( $filteredValue ) <= 10 ) { $value = FormatJson::encode( $filteredValue ); } else { $value = "array(" . count( $value ) . ")"; @@ -348,7 +340,12 @@ $value = "object(" . get_class( $value ) . ")"; } - $paramString .= "$key={$truncFunc( $value )}"; + $flatValue = (string)$value; + if ( mb_strlen( $value ) > 1024 ) { + $flatValue = "string(" . mb_strlen( $value ) . ")"; + } + + $paramString .= "$key={$flatValue}"; } } diff --git a/tests/phpunit/includes/jobqueue/JobTest.php b/tests/phpunit/includes/jobqueue/JobTest.php index 65ffa49..3c648f9 100644 --- a/tests/phpunit/includes/jobqueue/JobTest.php +++ b/tests/phpunit/includes/jobqueue/JobTest.php @@ -52,6 +52,29 @@ $this->getMockJob( [ $mockToStringObj ] ), 'someCommand 0={STRING_OBJ_VAL}' ], + [ + $this->getMockJob( [ + "pages" => [ + "932737" => [ + 0, + "Robert_James_Waller" + ] + ], + "rootJobSignature" => "45868e99bba89064e4483743ebb9b682ef95c1a7", + "rootJobTimestamp" => "20160309110158", + "masterPos" => [ + "file" => "db1023-bin.001288", + "pos" => "308257743", + "asOfTime" => 1457521464.3814 + ], + "triggeredRecursive" => true + ] ), + 'someCommand pages={"932737":[0,"Robert_James_Waller"]} ' . + 'rootJobSignature=45868e99bba89064e4483743ebb9b682ef95c1a7 ' . + 'rootJobTimestamp=20160309110158 masterPos=' . + '{"file":"db1023-bin.001288","pos":"308257743","asOfTime":1457521464.3814} ' . + 'triggeredRecursive=1' + ], ]; } -- To view, visit https://gerrit.wikimedia.org/r/277830 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6bfe67faa45835babb2c7e259b5cd158e0f0a649 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: wmf/1.27.0-wmf.17 Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits