/** @var string Text for error that occurred last */
protected $error;
+ /** @var callable[] */
+ protected $teardownCallbacks = [];
+
/**
* Run the job
* @return bool Success
return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] );
}
+ /**
+ * @param callable $callback
+ * @since 1.27
+ */
+ protected function addTeardownCallback( $callback ) {
+ $this->teardownCallbacks[] = $callback;
+ }
+
+ /**
+ * Do any final cleanup after run(), deferred updates, and all DB commits happen
+ *
+ * @since 1.27
+ */
+ public function teardown() {
+ foreach ( $this->teardownCallbacks as $callback ) {
+ call_user_func( $callback );
+ }
+ }
+
/**
* Insert a single job into the queue.
* @return bool True on success
* @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 ) {
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 ) . ")";
$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}";
}
}