Dan-nl has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/96014


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)”.

-------
version 0.1.5

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, 33 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GWToolset 
refs/changes/14/96014/1

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 10ad1fa..42aa2c6 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.3';
+       public static $version = '0.1.5';
 
        /**
         * @var {array}
diff --git a/includes/Handlers/Forms/MetadataMappingHandler.php 
b/includes/Handlers/Forms/MetadataMappingHandler.php
index f1e13a9..1e30714 100644
--- a/includes/Handlers/Forms/MetadataMappingHandler.php
+++ b/includes/Handlers/Forms/MetadataMappingHandler.php
@@ -429,6 +429,15 @@
                        // no more UploadMediafileJobs need to be created; 
create a GWTFileBackendCleanupJob
                        // that will delete the metadata file in the mwstore
                        } else {
+                               $result = JobQueueGroup::singleton()->push( 
$this->_UploadHandler->mediafile_jobs );
+
+                               if ( $result ) {
+                                       $result =
+                                               wfMessage( 
'gwtoolset-mediafile-jobs-created' )
+                                                       ->params( count( 
$this->_UploadHandler->mediafile_jobs ) )
+                                                       ->escaped();
+                               }
+
                                $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: newchange
Gerrit-Change-Id: I52b0f57b8c2cda382635fc6480675ea8704208a7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GWToolset
Gerrit-Branch: master
Gerrit-Owner: Dan-nl <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to