From ea37b415e20a8975407b2928d89e04f16a3c1084 Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Sat, 17 Apr 2010 16:49:20 +0000 Subject: [PATCH] re: r65152 * Make Job::insert() return true on success * Change from Status object to array for API result on URL upload. --- includes/JobQueue.php | 6 ++++-- includes/api/ApiUpload.php | 4 ++-- includes/upload/UploadFromUrl.php | 4 +++- maintenance/tests/UploadFromUrlTest.php | 4 +--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/includes/JobQueue.php b/includes/JobQueue.php index 4ab5eac640..3ae4b8e97a 100644 --- a/includes/JobQueue.php +++ b/includes/JobQueue.php @@ -76,7 +76,8 @@ abstract class Job { $namespace = $row->job_namespace; $dbkey = $row->job_title; $title = Title::makeTitleSafe( $namespace, $dbkey ); - $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id ); + $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), + $row->job_id ); $dbw->delete( 'job', $job->insertFields(), __METHOD__ ); $dbw->commit(); @@ -260,6 +261,7 @@ abstract class Job { /** * Insert a single job into the queue. + * @return bool true on success */ function insert() { $fields = $this->insertFields(); @@ -272,7 +274,7 @@ abstract class Job { return; } } - $dbw->insert( 'job', $fields, __METHOD__ ); + return $dbw->insert( 'job', $fields, __METHOD__ ); } protected function insertFields() { diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index d98965f1f0..054b79b714 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -92,10 +92,10 @@ class ApiUpload extends ApiBase { } $this->mUpload = new UploadFromUrl; - $this->mUpload->initialize( $this->mParams['filename'], $this->mParams['url'], + $result = $this->mUpload->initialize( $this->mParams['filename'], $this->mParams['url'], $this->mParams['comment'] ); - $this->getResult()->addValue( null, $this->getModuleName(), Status::newGood() ); + $this->getResult()->addValue( null, $this->getModuleName(), array( 'queued' => $result ) ); return; } } else { diff --git a/includes/upload/UploadFromUrl.php b/includes/upload/UploadFromUrl.php index 8f851b06f2..0fb7f4bced 100644 --- a/includes/upload/UploadFromUrl.php +++ b/includes/upload/UploadFromUrl.php @@ -24,6 +24,7 @@ class UploadFromUrl extends UploadBase { /** * Checks if the upload from URL feature is enabled + * @return bool */ public static function isEnabled() { global $wgAllowCopyUploads; @@ -32,6 +33,7 @@ class UploadFromUrl extends UploadBase { /** * Entry point for API upload + * @return bool true on success */ public function initialize( $name, $url, $comment, $watchlist ) { global $wgUser; @@ -66,7 +68,7 @@ class UploadFromUrl extends UploadBase { $job = new UploadFromUrlJob( $title, $params ); - $job->insert(); + return $job->insert(); } /** diff --git a/maintenance/tests/UploadFromUrlTest.php b/maintenance/tests/UploadFromUrlTest.php index 77fd099004..76bd94fcf5 100644 --- a/maintenance/tests/UploadFromUrlTest.php +++ b/maintenance/tests/UploadFromUrlTest.php @@ -143,9 +143,7 @@ class UploadFromUrlTest extends ApiSetup { 'token' => $token, ), $data ); - $this->assertThat( $data[0]['upload'], $this->isInstanceOf( 'Status' ), - "Got Status Object" ); - $this->assertTrue( $data[0]['upload']->isOk(), 'Job added'); + $this->assertTrue( $data[0]['upload']['queued'], 'Job added'); $job = Job::pop(); $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), -- 2.20.1