public $params;
/** @var array Additional queue metadata */
- public $metadata = array();
+ public $metadata = [];
/** @var Title */
protected $title;
* @throws MWException
* @return Job
*/
- public static function factory( $command, Title $title, $params = array() ) {
+ public static function factory( $command, Title $title, $params = [] ) {
global $wgJobClasses;
if ( isset( $wgJobClasses[$command] ) ) {
public function __construct( $command, $title, $params = false ) {
$this->command = $command;
$this->title = $title;
- $this->params = is_array( $params ) ? $params : array(); // sanity
+ $this->params = is_array( $params ) ? $params : []; // sanity
// expensive jobs may set this to true
$this->removeDuplicates = false;
* @since 1.21
*/
public function getDeduplicationInfo() {
- $info = array(
+ $info = [
'type' => $this->getType(),
'namespace' => $this->getTitle()->getNamespace(),
'title' => $this->getTitle()->getDBkey(),
'params' => $this->getParams()
- );
+ ];
if ( is_array( $info['params'] ) ) {
// Identical jobs with different "root" jobs should count as duplicates
unset( $info['params']['rootJobSignature'] );
* @since 1.21
*/
public static function newRootJobParams( $key ) {
- return array(
+ return [
'rootJobIsSelf' => true,
'rootJobSignature' => sha1( $key ),
'rootJobTimestamp' => wfTimestampNow()
- );
+ ];
}
/**
* @since 1.21
*/
public function getRootJobParams() {
- return array(
+ return [
'rootJobSignature' => isset( $this->params['rootJobSignature'] )
? $this->params['rootJobSignature']
: null,
'rootJobTimestamp' => isset( $this->params['rootJobTimestamp'] )
? $this->params['rootJobTimestamp']
: null
- );
+ ];
}
/**
* @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 ) {
$paramString .= ' ';
}
if ( is_array( $value ) ) {
- $filteredValue = array();
+ $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 ) . ")";
$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}";
}
}