jenkins-bot has submitted this change and it was merged.
Change subject: mediafile-job-array
......................................................................
mediafile-job-array
aaron schulz requested that we, “create an array of mediafile jobs and push
them all at once
(this makes it a bit more atomic)”.
Change-Id: I52b0f57b8c2cda382635fc6480675ea8704208a7
---
M .gitignore
M GWToolset.i18n.php
M includes/Config.php
M includes/Handlers/Forms/MetadataMappingHandler.php
M includes/Handlers/UploadHandler.php
5 files changed, 41 insertions(+), 38 deletions(-)
Approvals:
Aaron Schulz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.gitignore b/.gitignore
index edd68f4..ff1dc74 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,4 @@
*.kate-swp
.*.swp
.DS_Store
-config-custom.php
\ No newline at end of file
+.change-log.txt
diff --git a/GWToolset.i18n.php b/GWToolset.i18n.php
index 1df0aeb..2baae58 100644
--- a/GWToolset.i18n.php
+++ b/GWToolset.i18n.php
@@ -33,14 +33,13 @@
'gwtoolset-batchjob-creation-failure' => 'Could not create a ($1) batch
job.',
'gwtoolset-could-not-close-xml' => 'Could not close the XMLReader.',
'gwtoolset-could-not-open-xml' => 'Could not open the XML File for
reading.',
- 'gwtoolset-developer-issue' => "Please contact a developer; they will
need to address this issue before you can continue.
-
-$1",
+ 'gwtoolset-developer-issue' => "Please contact a developer; they will
need to address this issue before you can continue. $1",
'gwtoolset-dom-record-issue' => '<code>record-element-name</code>, or
<code>record-count</code> or <code>record-current</code> not provided.',
'gwtoolset-file-backend-maxage-invalid' => 'The FileBackend max age
value provided is invalid @see
php.net/manual/en/datetime.formats.relative.php.',
'gwtoolset-fsfile-empty' => 'The mwstored file was empty; the extension
has deleted the file for you.',
'gwtoolset-fsfile-retrieval-failure' => 'Could not retrieve ($1) from
the FileBackend.',
'gwtoolset-ignorewarnings' => '<code>ignorewarnings</code> not set.',
+ 'gwtoolset-job-throttle-exceeded' => 'The batch job job throttle was
exceeded.',
'gwtoolset-no-accepted-types' => 'No accepted types provided',
'gwtoolset-no-callback' => 'No callback passed to this method.',
'gwtoolset-no-comment' => "<code>user_options['comment']</code> not
set.",
@@ -238,6 +237,7 @@
'gwtoolset-batchjob-metadata-created' => 'Metadata batch job created.
Your metadata file will be analyzed shortly and each item will be uploaded to
the wiki in a background process. You can check the ($1) page to see when they
have been uploaded.',
'gwtoolset-batchjob-metadata-creation-failure' => 'Could not create
batchjob for the metadata file.',
'gwtoolset-create-mediafile' => '$1 creating mediafile for $2.',
+ 'gwtoolset-mediafile-jobs-created' => 'Created ($1) mediafile batch
jobs.',
'gwtoolset-step-4-heading' => 'Step 4: Batch upload',
/**
@@ -306,6 +306,7 @@
'gwtoolset-ignorewarnings' => 'Hint to the developer that appears when
ignorewarnings is not set.',
'gwtoolset-improper-upload' => 'User error message that appears when a
File was not uploaded properly.',
'gwtoolset-intro' => 'Introduction paragraph for the extension used on
the initial Special:GWtoolset landing page.',
+ 'gwtoolset-job-throttle-exceeded' => 'Developer message that appears
when the batch job job throttle was exceeded.',
'gwtoolset-json-error' => 'Appears when there is a problem with a JSON
value.',
'gwtoolset-json-error-ctrl-char' => 'User error message when an
unexpected control character has been found.',
'gwtoolset-json-error-depth' => 'User error message when the maximum
stack depth is exceeded.',
@@ -321,6 +322,7 @@
'gwtoolset-mapping-no-title-identifier' => 'User error message when the
metadata mapping contains no title identifier.',
'gwtoolset-maps-to' => 'Text for the table column heading, which is at
the top of the mapping metadata table in the HTML form.',
'gwtoolset-maxuploadsize-exceeds-ini-settings' => 'User message that
appears when the PHP ini settings are less that the wiki’s $wgMaxUploadSize
setting.',
+ 'gwtoolset-mediafile-jobs-created' => 'User/Developer message that
indicates ($1) number of mediafile batch jobs was created.',
'gwtoolset-metadata-user-options-error' => 'Initial paragraph that
notifies the user that there are form fields missing. The specific form fields
that are missing are mentioned separately.',
'gwtoolset-metadata-invalid-template' => 'Message that appears when no
valid MediaWiki template is found.',
'gwtoolset-mediawiki-template' => 'Heading used on the mapping page.
The parameter is filled in with the wiki template name that will be used for
mapping the metadata to the wiki template.',
diff --git a/includes/Config.php b/includes/Config.php
index 0407db5..61efb3f 100644
--- a/includes/Config.php
+++ b/includes/Config.php
@@ -16,7 +16,7 @@
public static $url =
'https://www.mediawiki.org/wiki/Extension:GWToolset';
public static $descriptionmsg = 'gwtoolset-desc';
public static $type = 'media';
- public static $version = '0.1.6';
+ public static $version = '0.0.1-dev';
/**
* @var {array}
diff --git a/includes/Handlers/Forms/MetadataMappingHandler.php
b/includes/Handlers/Forms/MetadataMappingHandler.php
index f1e13a9..6a6c4a4 100644
--- a/includes/Handlers/Forms/MetadataMappingHandler.php
+++ b/includes/Handlers/Forms/MetadataMappingHandler.php
@@ -89,15 +89,12 @@
protected $_XmlMappingHandler;
/**
- * @param {array} $user_options
- * an array of user options that was submitted in the html form
- *
* @throws {MWException}
*
* @return {string}
* the html string has been escaped and parsed by wfMessage
*/
- protected function createMetadataBatchJob( array &$user_options ) {
+ protected function createMetadataBatchJob() {
$result = false;
$job = new UploadMetadataJob(
@@ -109,9 +106,8 @@
NS_USER
),
array(
- 'whitelisted-post' => $this->_whitelisted_post,
'user-name' => $this->User->getName(),
- 'user-options' => $user_options
+ 'whitelisted-post' => $this->_whitelisted_post
)
);
@@ -321,7 +317,7 @@
* an array of user options that was submitted in the html form
*
* @throws {GWTException}
- * @return {array}
+ * @return {array|string}
* an array of mediafile Title(s)
*/
protected function processMetadata( array &$user_options ) {
@@ -398,6 +394,18 @@
// when PHP_SAPI === 'cli' this method is being run by a wiki
job.
if ( PHP_SAPI === 'cli' ) {
+ // add jobs created earlier by
$this->_UploadHandler::saveMediafileViaJob to the JobQueue
+ if ( count( $this->_UploadHandler->mediafile_jobs ) > 0
) {
+ $added_jobs = JobQueueGroup::singleton()->push(
$this->_UploadHandler->mediafile_jobs );
+
+ if ( $added_jobs ) {
+ $result =
+ wfMessage(
'gwtoolset-mediafile-jobs-created' )
+ ->params( count(
$this->_UploadHandler->mediafile_jobs ) )
+ ->escaped();
+ }
+ }
+
// at this point
// * the UploadMetadataJob has created (
Config::$job_throttle ) number of
// UploadMediafileJobs
@@ -425,10 +433,9 @@
$this->_whitelisted_post['gwtoolset-record-begin'] =
(int)$user_options['gwtoolset-record-current'];
$this->createMetadataBatchJob( $user_options );
-
- // no more UploadMediafileJobs need to be created;
create a GWTFileBackendCleanupJob
- // that will delete the metadata file in the mwstore
} else {
+ // no more UploadMediafileJobs need to be
created
+ // create a GWTFileBackendCleanupJob that will
delete the metadata file in the mwstore
$Status =
$this->_GWTFileBackend->createCleanupJob(
$user_options['gwtoolset-metadata-file-mwstore']
);
diff --git a/includes/Handlers/UploadHandler.php
b/includes/Handlers/UploadHandler.php
index ead12e9..2048836 100644
--- a/includes/Handlers/UploadHandler.php
+++ b/includes/Handlers/UploadHandler.php
@@ -82,17 +82,12 @@
/**
* @var {array}
*/
+ public $mediafile_jobs;
+
+ /**
+ * @var {array}
+ */
public $user_options;
-
- /**
- * @var {int}
- */
- public $jobs_added;
-
- /**
- * @var {int}
- */
- public $jobs_not_added;
/**
* @param {array} $options
@@ -434,8 +429,7 @@
$this->_SpecialPage = null;
$this->_UploadBase = null;
- $this->jobs_added = 0;
- $this->jobs_not_added = 0;
+ $this->mediafile_jobs = array();
$this->user_options = array();
}
@@ -551,11 +545,16 @@
array &$user_options, array $options, array $whitelisted_post
) {
$result = false;
- $job = null;
- $sessionKey = null;
- if ( $this->jobs_added > Config::$job_throttle ) {
- return;
+ if ( count( $this->mediafile_jobs ) > Config::$job_throttle ) {
+ throw new MWException(
+ wfMessage( 'gwtoolset-developer-issue' )
+ ->params(
+ __METHOD__ . ': ' .
+ wfMessage(
'gwtoolset-job-throttle-exceeded' )->escaped()
+ )
+ ->escaped()
+ );
}
$this->validateUserOptions( $user_options );
@@ -576,13 +575,8 @@
)
);
- $result = JobQueueGroup::singleton()->push( $job );
-
- if ( $result ) {
- $this->jobs_added += 1;
- } else {
- $this->jobs_not_added += 1;
- }
+ $this->mediafile_jobs[] = $job;
+ $result = true;
return $result;
}
--
To view, visit https://gerrit.wikimedia.org/r/96014
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I52b0f57b8c2cda382635fc6480675ea8704208a7
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/GWToolset
Gerrit-Branch: master
Gerrit-Owner: Dan-nl <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Dan-nl <[email protected]>
Gerrit-Reviewer: Gergő Tisza <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits