2006-02-24 01:56:31 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2014-01-27 21:28:47 +00:00
|
|
|
* Job queue task base code.
|
2012-05-04 06:29:11 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-09-03 18:24:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @defgroup JobQueue JobQueue
|
|
|
|
|
*/
|
2006-02-24 01:56:31 +00:00
|
|
|
|
2007-04-04 05:22:37 +00:00
|
|
|
/**
|
2007-04-21 12:33:41 +00:00
|
|
|
* Class to both describe a background job and handle jobs.
|
2018-05-20 12:10:20 +00:00
|
|
|
* To push jobs onto queues, use JobQueueGroup::singleton()->push();
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup JobQueue
|
2007-04-04 05:22:37 +00:00
|
|
|
*/
|
2014-01-27 21:28:47 +00:00
|
|
|
abstract class Job implements IJobSpecification {
|
2013-11-25 15:32:17 +00:00
|
|
|
/** @var string */
|
|
|
|
|
public $command;
|
2011-02-19 21:56:54 +00:00
|
|
|
|
2015-05-21 18:02:35 +00:00
|
|
|
/** @var array Array of job parameters */
|
2013-11-25 15:32:17 +00:00
|
|
|
public $params;
|
2006-02-24 01:56:31 +00:00
|
|
|
|
2013-11-25 15:32:17 +00:00
|
|
|
/** @var array Additional queue metadata */
|
2016-02-17 09:09:32 +00:00
|
|
|
public $metadata = [];
|
2012-12-12 00:04:03 +00:00
|
|
|
|
2013-11-25 15:32:17 +00:00
|
|
|
/** @var Title */
|
|
|
|
|
protected $title;
|
|
|
|
|
|
|
|
|
|
/** @var bool Expensive jobs may set this to true */
|
|
|
|
|
protected $removeDuplicates;
|
|
|
|
|
|
|
|
|
|
/** @var string Text for error that occurred last */
|
|
|
|
|
protected $error;
|
|
|
|
|
|
2016-02-17 03:25:24 +00:00
|
|
|
/** @var callable[] */
|
|
|
|
|
protected $teardownCallbacks = [];
|
|
|
|
|
|
2018-04-16 20:38:01 +00:00
|
|
|
/** @var int Bitfield of JOB_* class constants */
|
|
|
|
|
protected $executionFlags = 0;
|
|
|
|
|
|
|
|
|
|
/** @var int Job must not be wrapped in the usual explicit LBFactory transaction round */
|
|
|
|
|
const JOB_NO_EXPLICIT_TRX_ROUND = 1;
|
|
|
|
|
|
2007-04-21 12:33:41 +00:00
|
|
|
/**
|
|
|
|
|
* Run the job
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return bool Success
|
2007-04-21 12:33:41 +00:00
|
|
|
*/
|
2012-08-29 00:01:31 +00:00
|
|
|
abstract public function run();
|
2007-04-21 12:33:41 +00:00
|
|
|
|
|
|
|
|
/**
|
2007-06-21 19:11:24 +00:00
|
|
|
* Create the appropriate object to handle a specific job
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $command Job command
|
2013-11-25 17:12:42 +00:00
|
|
|
* @param Title $title Associated title
|
2015-05-21 18:02:35 +00:00
|
|
|
* @param array $params Job parameters
|
2012-08-02 19:36:21 +00:00
|
|
|
* @throws MWException
|
2007-06-21 19:11:24 +00:00
|
|
|
* @return Job
|
2006-06-18 12:42:16 +00:00
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public static function factory( $command, Title $title, $params = [] ) {
|
2007-06-21 19:11:24 +00:00
|
|
|
global $wgJobClasses;
|
2015-10-23 18:48:50 +00:00
|
|
|
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( isset( $wgJobClasses[$command] ) ) {
|
2017-05-04 16:00:28 +00:00
|
|
|
$handler = $wgJobClasses[$command];
|
|
|
|
|
|
|
|
|
|
if ( is_callable( $handler ) ) {
|
|
|
|
|
$job = call_user_func( $handler, $title, $params );
|
|
|
|
|
} elseif ( class_exists( $handler ) ) {
|
|
|
|
|
$job = new $handler( $title, $params );
|
|
|
|
|
} else {
|
|
|
|
|
$job = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $job instanceof Job ) {
|
|
|
|
|
$job->command = $command;
|
|
|
|
|
return $job;
|
|
|
|
|
} else {
|
|
|
|
|
throw new InvalidArgumentException( "Cannot instantiate job '$command': bad spec!" );
|
|
|
|
|
}
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
2015-10-23 18:48:50 +00:00
|
|
|
|
|
|
|
|
throw new InvalidArgumentException( "Invalid job command '{$command}'" );
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2014-09-22 18:31:57 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $command
|
|
|
|
|
* @param Title $title
|
|
|
|
|
* @param array|bool $params Can not be === true
|
|
|
|
|
*/
|
|
|
|
|
public function __construct( $command, $title, $params = false ) {
|
|
|
|
|
$this->command = $command;
|
|
|
|
|
$this->title = $title;
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->params = is_array( $params ) ? $params : []; // sanity
|
2014-09-22 18:31:57 +00:00
|
|
|
|
|
|
|
|
// expensive jobs may set this to true
|
|
|
|
|
$this->removeDuplicates = false;
|
2016-04-11 21:00:43 +00:00
|
|
|
|
|
|
|
|
if ( !isset( $this->params['requestId'] ) ) {
|
|
|
|
|
$this->params['requestId'] = WebRequest::getRequestId();
|
|
|
|
|
}
|
2014-09-22 18:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-16 20:38:01 +00:00
|
|
|
/**
|
|
|
|
|
* @param int $flag JOB_* class constant
|
|
|
|
|
* @return bool
|
|
|
|
|
* @since 1.31
|
|
|
|
|
*/
|
|
|
|
|
public function hasExecutionFlag( $flag ) {
|
|
|
|
|
return ( $this->executionFlags && $flag ) === $flag;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getType() {
|
|
|
|
|
return $this->command;
|
|
|
|
|
}
|
2007-04-21 12:33:41 +00:00
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
|
|
|
|
public function getTitle() {
|
|
|
|
|
return $this->title;
|
2006-02-24 01:56:31 +00:00
|
|
|
}
|
2007-04-21 12:33:41 +00:00
|
|
|
|
2011-10-26 04:15:09 +00:00
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2012-08-29 00:01:31 +00:00
|
|
|
public function getParams() {
|
|
|
|
|
return $this->params;
|
2006-05-31 23:56:41 +00:00
|
|
|
}
|
2006-02-24 01:56:31 +00:00
|
|
|
|
2013-03-12 03:40:01 +00:00
|
|
|
/**
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return int|null UNIX timestamp to delay running this job until, otherwise null
|
2013-03-12 03:40:01 +00:00
|
|
|
* @since 1.22
|
|
|
|
|
*/
|
|
|
|
|
public function getReleaseTimestamp() {
|
|
|
|
|
return isset( $this->params['jobReleaseTimestamp'] )
|
|
|
|
|
? wfTimestampOrNull( TS_UNIX, $this->params['jobReleaseTimestamp'] )
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-03 19:20:38 +00:00
|
|
|
/**
|
|
|
|
|
* @return int|null UNIX timestamp of when the job was queued, or null
|
|
|
|
|
* @since 1.26
|
|
|
|
|
*/
|
|
|
|
|
public function getQueuedTimestamp() {
|
|
|
|
|
return isset( $this->metadata['timestamp'] )
|
|
|
|
|
? wfTimestampOrNull( TS_UNIX, $this->metadata['timestamp'] )
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-11 21:00:43 +00:00
|
|
|
/**
|
|
|
|
|
* @return string|null Id of the request that created this job. Follows
|
|
|
|
|
* jobs recursively, allowing to track the id of the request that started a
|
|
|
|
|
* job when jobs insert jobs which insert other jobs.
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
public function getRequestId() {
|
2017-10-06 22:17:58 +00:00
|
|
|
return $this->params['requestId'] ?? null;
|
2016-04-11 21:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-01 19:30:06 +00:00
|
|
|
/**
|
|
|
|
|
* @return int|null UNIX timestamp of when the job was runnable, or null
|
|
|
|
|
* @since 1.26
|
|
|
|
|
*/
|
|
|
|
|
public function getReadyTimestamp() {
|
|
|
|
|
return $this->getReleaseTimestamp() ?: $this->getQueuedTimestamp();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-10 11:39:23 +00:00
|
|
|
/**
|
2015-01-16 23:28:38 +00:00
|
|
|
* Whether the queue should reject insertion of this job if a duplicate exists
|
|
|
|
|
*
|
|
|
|
|
* This can be used to avoid duplicated effort or combined with delayed jobs to
|
|
|
|
|
* coalesce updates into larger batches. Claimed jobs are never treated as
|
|
|
|
|
* duplicates of new jobs, and some queues may allow a few duplicates due to
|
|
|
|
|
* network partitions and fail-over. Thus, additional locking is needed to
|
|
|
|
|
* enforce mutual exclusion if this is really needed.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
2011-03-10 11:39:23 +00:00
|
|
|
*/
|
2012-08-29 00:01:31 +00:00
|
|
|
public function ignoreDuplicates() {
|
|
|
|
|
return $this->removeDuplicates;
|
|
|
|
|
}
|
2011-03-10 11:39:23 +00:00
|
|
|
|
2013-02-20 00:56:47 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool Whether this job can be retried on failure by job runners
|
2013-04-03 20:13:36 +00:00
|
|
|
* @since 1.21
|
2013-02-20 00:56:47 +00:00
|
|
|
*/
|
|
|
|
|
public function allowRetries() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-21 20:57:45 +00:00
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @return int Number of actually "work items" handled in this job
|
2013-12-21 20:57:45 +00:00
|
|
|
* @see $wgJobBackoffThrottling
|
|
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public function workItemCount() {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-08 22:01:40 +00:00
|
|
|
/**
|
2013-04-03 20:51:02 +00:00
|
|
|
* Subclasses may need to override this to make duplication detection work.
|
|
|
|
|
* The resulting map conveys everything that makes the job unique. This is
|
|
|
|
|
* only checked if ignoreDuplicates() returns true, meaning that duplicate
|
|
|
|
|
* jobs are supposed to be ignored.
|
2012-11-08 22:01:40 +00:00
|
|
|
*
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return array Map of key/values
|
2013-04-03 20:13:36 +00:00
|
|
|
* @since 1.21
|
2012-11-08 22:01:40 +00:00
|
|
|
*/
|
|
|
|
|
public function getDeduplicationInfo() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$info = [
|
2013-04-20 17:18:13 +00:00
|
|
|
'type' => $this->getType(),
|
2012-11-08 22:01:40 +00:00
|
|
|
'namespace' => $this->getTitle()->getNamespace(),
|
2013-04-20 17:18:13 +00:00
|
|
|
'title' => $this->getTitle()->getDBkey(),
|
|
|
|
|
'params' => $this->getParams()
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-11-08 22:01:40 +00:00
|
|
|
if ( is_array( $info['params'] ) ) {
|
2013-03-27 21:26:47 +00:00
|
|
|
// Identical jobs with different "root" jobs should count as duplicates
|
2012-11-08 22:01:40 +00:00
|
|
|
unset( $info['params']['rootJobSignature'] );
|
|
|
|
|
unset( $info['params']['rootJobTimestamp'] );
|
2013-03-27 21:26:47 +00:00
|
|
|
// Likewise for jobs with different delay times
|
|
|
|
|
unset( $info['params']['jobReleaseTimestamp'] );
|
2016-04-11 21:00:43 +00:00
|
|
|
// Identical jobs from different requests should count as duplicates
|
|
|
|
|
unset( $info['params']['requestId'] );
|
2015-03-19 17:45:39 +00:00
|
|
|
// Queues pack and hash this array, so normalize the order
|
|
|
|
|
ksort( $info['params'] );
|
2012-11-08 22:01:40 +00:00
|
|
|
}
|
2013-11-25 14:38:37 +00:00
|
|
|
|
2012-11-08 22:01:40 +00:00
|
|
|
return $info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-05-23 17:53:12 +00:00
|
|
|
* Get "root job" parameters for a task
|
|
|
|
|
*
|
|
|
|
|
* This is used to no-op redundant jobs, including child jobs of jobs,
|
|
|
|
|
* as long as the children inherit the root job parameters. When a job
|
|
|
|
|
* with root job parameters and "rootJobIsSelf" set is pushed, the
|
|
|
|
|
* deduplicateRootJob() method is automatically called on it. If the
|
|
|
|
|
* root job is only virtual and not actually pushed (e.g. the sub-jobs
|
|
|
|
|
* are inserted directly), then call deduplicateRootJob() directly.
|
|
|
|
|
*
|
2013-04-03 20:51:02 +00:00
|
|
|
* @see JobQueue::deduplicateRootJob()
|
2015-05-23 17:53:12 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $key A key that identifies the task
|
2013-11-28 06:43:00 +00:00
|
|
|
* @return array Map of:
|
2015-05-23 17:53:12 +00:00
|
|
|
* - rootJobIsSelf : true
|
2013-11-28 06:43:00 +00:00
|
|
|
* - rootJobSignature : hash (e.g. SHA1) that identifies the task
|
|
|
|
|
* - rootJobTimestamp : TS_MW timestamp of this instance of the task
|
2013-04-03 20:13:36 +00:00
|
|
|
* @since 1.21
|
2012-11-08 22:01:40 +00:00
|
|
|
*/
|
|
|
|
|
public static function newRootJobParams( $key ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-05-23 17:53:12 +00:00
|
|
|
'rootJobIsSelf' => true,
|
2012-11-08 22:01:40 +00:00
|
|
|
'rootJobSignature' => sha1( $key ),
|
|
|
|
|
'rootJobTimestamp' => wfTimestampNow()
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-11-08 22:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-04-03 20:51:02 +00:00
|
|
|
* @see JobQueue::deduplicateRootJob()
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return array
|
2013-04-03 20:51:02 +00:00
|
|
|
* @since 1.21
|
2012-11-08 22:01:40 +00:00
|
|
|
*/
|
|
|
|
|
public function getRootJobParams() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2017-10-06 22:17:58 +00:00
|
|
|
'rootJobSignature' => $this->params['rootJobSignature'] ?? null,
|
|
|
|
|
'rootJobTimestamp' => $this->params['rootJobTimestamp'] ?? null
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-11-08 22:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-03 20:51:02 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::deduplicateRootJob()
|
|
|
|
|
* @return bool
|
|
|
|
|
* @since 1.22
|
|
|
|
|
*/
|
|
|
|
|
public function hasRootJobParams() {
|
|
|
|
|
return isset( $this->params['rootJobSignature'] )
|
|
|
|
|
&& isset( $this->params['rootJobTimestamp'] );
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-23 17:53:12 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::deduplicateRootJob()
|
|
|
|
|
* @return bool Whether this is job is a root job
|
|
|
|
|
*/
|
|
|
|
|
public function isRootJob() {
|
|
|
|
|
return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] );
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 03:25:24 +00:00
|
|
|
/**
|
2016-10-05 01:16:56 +00:00
|
|
|
* @param callable $callback A function with one parameter, the success status, which will be
|
|
|
|
|
* false if the job failed or it succeeded but the DB changes could not be committed or
|
|
|
|
|
* any deferred updates threw an exception. (This parameter was added in 1.28.)
|
2016-02-17 03:25:24 +00:00
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
protected function addTeardownCallback( $callback ) {
|
|
|
|
|
$this->teardownCallbacks[] = $callback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Do any final cleanup after run(), deferred updates, and all DB commits happen
|
2016-10-05 01:16:56 +00:00
|
|
|
* @param bool $status Whether the job, its deferred updates, and DB commit all succeeded
|
2016-02-17 03:25:24 +00:00
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
2016-10-05 01:16:56 +00:00
|
|
|
public function teardown( $status ) {
|
2016-02-17 03:25:24 +00:00
|
|
|
foreach ( $this->teardownCallbacks as $callback ) {
|
2016-10-05 01:16:56 +00:00
|
|
|
call_user_func( $callback, $status );
|
2016-02-17 03:25:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 04:15:09 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2012-08-29 00:01:31 +00:00
|
|
|
public function toString() {
|
2006-06-18 12:42:16 +00:00
|
|
|
$paramString = '';
|
|
|
|
|
if ( $this->params ) {
|
|
|
|
|
foreach ( $this->params as $key => $value ) {
|
|
|
|
|
if ( $paramString != '' ) {
|
|
|
|
|
$paramString .= ' ';
|
2006-06-15 06:35:24 +00:00
|
|
|
}
|
2013-01-23 18:39:49 +00:00
|
|
|
if ( is_array( $value ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$filteredValue = [];
|
2014-05-16 22:23:26 +00:00
|
|
|
foreach ( $value as $k => $v ) {
|
2016-03-16 10:24:10 +00:00
|
|
|
$json = FormatJson::encode( $v );
|
|
|
|
|
if ( $json === false || mb_strlen( $json ) > 512 ) {
|
|
|
|
|
$filteredValue[$k] = gettype( $v ) . '(...)';
|
2014-05-16 22:23:26 +00:00
|
|
|
} else {
|
2016-03-16 10:24:10 +00:00
|
|
|
$filteredValue[$k] = $v;
|
2014-05-16 22:23:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-16 10:24:10 +00:00
|
|
|
if ( count( $filteredValue ) <= 10 ) {
|
2014-05-16 22:23:26 +00:00
|
|
|
$value = FormatJson::encode( $filteredValue );
|
|
|
|
|
} else {
|
|
|
|
|
$value = "array(" . count( $value ) . ")";
|
|
|
|
|
}
|
2013-02-15 04:11:26 +00:00
|
|
|
} elseif ( is_object( $value ) && !method_exists( $value, '__toString' ) ) {
|
2013-01-23 18:39:49 +00:00
|
|
|
$value = "object(" . get_class( $value ) . ")";
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 10:24:10 +00:00
|
|
|
$flatValue = (string)$value;
|
|
|
|
|
if ( mb_strlen( $value ) > 1024 ) {
|
|
|
|
|
$flatValue = "string(" . mb_strlen( $value ) . ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$paramString .= "$key={$flatValue}";
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 22:07:39 +00:00
|
|
|
$metaString = '';
|
|
|
|
|
foreach ( $this->metadata as $key => $value ) {
|
|
|
|
|
if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
|
|
|
|
|
$metaString .= ( $metaString ? ",$key=$value" : "$key=$value" );
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
2014-10-21 22:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$s = $this->command;
|
|
|
|
|
if ( is_object( $this->title ) ) {
|
|
|
|
|
$s .= " {$this->title->getPrefixedDBkey()}";
|
|
|
|
|
}
|
|
|
|
|
if ( $paramString != '' ) {
|
|
|
|
|
$s .= " $paramString";
|
|
|
|
|
}
|
|
|
|
|
if ( $metaString != '' ) {
|
|
|
|
|
$s .= " ($metaString)";
|
2006-02-24 01:56:31 +00:00
|
|
|
}
|
2014-10-09 00:15:05 +00:00
|
|
|
|
|
|
|
|
return $s;
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-22 22:44:34 +00:00
|
|
|
protected function setLastError( $error ) {
|
|
|
|
|
$this->error = $error;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
public function getLastError() {
|
2006-06-18 12:42:16 +00:00
|
|
|
return $this->error;
|
|
|
|
|
}
|
|
|
|
|
}
|