Dan-nl has uploaded a new change for review.

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


Change subject: corrected issue where batch upload breaks off early
......................................................................

corrected issue where batch upload breaks off early

* GWToolset.i18n.php
  - added key 'gwtoolset-no-url-to-evaluate'
  - changed key 'gwtoolset-dom-record-issue'

* includes/Config.php
  - changed comments from {boolean} to {bool} for consistency

* includes/Forms/PreviewForm.php
  - changed $user_options['record-begin'] value from 
$user_options['record-count'] to $user_options['record-current']

* includes/Handlers/Forms/MetadataMappingHandler.php
  - added line breaks to code that is > 100 characters
  - added record-current variable
  - changed set-up of record-begin variable
  - changed set-up of record-count variable
  - re-factored processMatchingElement()
  - set $_POST['record-begin'] to $user_options['record-current'] instead of 
$user_options['record-count']

* includes/Handlers/UploadHandler.php
  - added exception when $url provided to evaluateMediafileUrl() is empty
  - re-factored getTitle()
  - re-factored saveMediafileAsContent()
  - re-factored saveMediafileViaJob()
  - removed saveMediaFile()

* includes/Handlers/Xml/XmlMappingHandler.php
  - changed use of $user_options['record-count'] to 
$user_options['record-current']

* includes/Jobs/UploadMediafileJob.php
  - added use statements
  - changed use of error_log() to $this->setLastError()
  - expanded validateParams() to accommodate new params
  - passing $this->params['user_options'] instead of $this->params to 
saveMediafileAsContent();
  - re-factored processMetadata()
  - re-located validateParams() within the class
  - removed class variables

* includes/Jobs/UploadMetadataJob.php
  - created a processMetadata() method to match similar use in 
includes/Jobs/UploadMediafileJob.php

* re: #179/assembla - Batch upload breaks off early

Change-Id: I595168caba21fa23bda202724933f38de96f322a
---
M GWToolset.i18n.php
M includes/Config.php
M includes/Forms/PreviewForm.php
M includes/Handlers/Forms/MetadataMappingHandler.php
M includes/Handlers/UploadHandler.php
M includes/Handlers/Xml/XmlMappingHandler.php
M includes/Jobs/UploadMediafileJob.php
M includes/Jobs/UploadMetadataJob.php
8 files changed, 230 insertions(+), 164 deletions(-)


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

diff --git a/GWToolset.i18n.php b/GWToolset.i18n.php
index 72fdcfe..2e309f7 100644
--- a/GWToolset.i18n.php
+++ b/GWToolset.i18n.php
@@ -35,7 +35,7 @@
        '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> not provided.',
+       'gwtoolset-dom-record-issue' => '<code>record-element-name</code>, or 
<code>record-count</code> or <code>record-current</code> not provided.',
        'gwtoolset-ignorewarnings' => '<code>ignorewarnings</code> not set.',
        'gwtoolset-no-accepted-types' => 'No accepted types provided',
        'gwtoolset-no-callback' => 'No callback passed to this method.',
@@ -53,6 +53,7 @@
        'gwtoolset-no-title' => 'No title provided.',
        'gwtoolset-no-upload-handler' => 'No upload handler was created.',
        'gwtoolset-no-upload-media' => 
"<code>user_options['upload-media']</code> not set.",
+       'gwtoolset-no-url-to-evaluate' => 'No URL was provided for evaluation.',
        'gwtoolset-no-url-to-media' => '<code>url-to-the-media-file</code> not 
set.',
        'gwtoolset-no-user' => 'no user object provided.',
        'gwtoolset-no-xml-element' => 'No XMLReader or DOMElement provided.',
@@ -280,7 +281,7 @@
        'gwtoolset-desc' => 
'{{desc|name=GWToolset|url=https://www.mediawiki.org/wiki/Extension:GWToolset}}',
        'gwtoolset-developer-issue' => "A user-friendly message that lets the 
user know that something went wrong that a developer will need to fix. The 
single parameter takes a message that explains a bit more to the developer what 
the issue may be.",
        'gwtoolset-disk-write-failure' => 'User error message that appears when 
the uploaded file failed to write to disk.',
-       'gwtoolset-dom-record-issue' => 'Hint to the developer that appears 
when record-element-name, or record-count not provided.',
+       'gwtoolset-dom-record-issue' => 'Hint to the developer that appears 
when record-element-name, or record-count or record-current not provided.',
        'gwtoolset-ensure-well-formed-xml' => 'Additional instructions that 
will help the user make sure the XML File is well-formed.',
        'gwtoolset-example-record' => 'Label for the metadata example record.',
        'gwtoolset-file-interpretation-error' => 'Heading that appears when 
there was a problem interpreting the metadata file.',
@@ -347,6 +348,7 @@
        'gwtoolset-no-title' => 'Hint to the developer that appears when no 
title is provided.',
        'gwtoolset-no-upload-handler' => 'Hint to the developer that appears 
when no upload handler was created.',
        'gwtoolset-no-upload-media' => "Hint to the developer that appears when 
user_options['upload-media'] is not set.",
+       'gwtoolset-no-url-to-evaluate' => 'Message that appears when no URL was 
provided for evaluation.',
        'gwtoolset-no-url-to-media' => 'Hint to the developer that appears when 
url-to-the-media-file is not set.',
        'gwtoolset-no-user' => 'Hint to the developer that appears when no user 
object is provided.',
        'gwtoolset-no-xml-element' => 'Hint to the developer that appears when 
no XMLReader or DOMElement is provided.',
diff --git a/includes/Config.php b/includes/Config.php
index f33fa61..ad6faf9 100644
--- a/includes/Config.php
+++ b/includes/Config.php
@@ -246,6 +246,7 @@
                        'gwtoolset-cancel'
                ),
                'dependencies' => array(
+                       'jquery.json',
                        'jquery.spinner',
                        'jquery.ui.widget',
                        'jquery.ui.button',
@@ -279,7 +280,7 @@
 
        /**
         * @see SpecialPage __constructor
-        * @var {boolean}
+        * @var {bool}
         * whether the page is listed in Special:Specialpages
         */
        public static $special_page_listed = true;
@@ -307,14 +308,14 @@
        public static $title_separator = '-';
 
        /**
-        * @var {boolean}
+        * @var {bool}
         * tells the upload form to place the $accepted_mime_types in a comma
         * delimited list in the input file’s accept attribute
         */
        public static $use_file_accept_attribute = true;
 
        /**
-        * @var {boolean}
+        * @var {bool}
         */
        public static $use_UploadStash = true;
 
diff --git a/includes/Forms/PreviewForm.php b/includes/Forms/PreviewForm.php
index 0c9b225..a90974b 100644
--- a/includes/Forms/PreviewForm.php
+++ b/includes/Forms/PreviewForm.php
@@ -110,7 +110,7 @@
                                array(
                                        'type' => 'hidden',
                                        'name' => 'record-begin',
-                                       'value' => 
(int)$user_options['record-count']
+                                       'value' => 
(int)$user_options['record-current']
                                )
                        ) .
 
diff --git a/includes/Handlers/Forms/MetadataMappingHandler.php 
b/includes/Handlers/Forms/MetadataMappingHandler.php
index 5e6b234..af33cb1 100644
--- a/includes/Handlers/Forms/MetadataMappingHandler.php
+++ b/includes/Handlers/Forms/MetadataMappingHandler.php
@@ -67,9 +67,9 @@
                                'User:' . $this->User->getName() . '/' . 
Config::$name . ' Metadata Batch Job'
                        ),
                        array(
-                               'username' => $this->User->getName(),
-                               'user_options' => $user_options,
-                               'post' => $_POST
+                               'post' => $_POST,
+                               'user-name' => $this->User->getName(),
+                               'user-options' => $user_options
                        )
                );
 
@@ -164,11 +164,15 @@
                                ? true
                                : false,
 
-                       'record-count' => 0,
-
                        'record-begin' => !empty( $_POST['record-begin'] )
                                ? (int)$_POST['record-begin']
+                               : 1,
+
+                       'record-count' => !empty( $_POST['record-count'] )
+                               ? (int)$_POST['record-count']
                                : 0,
+
+                       'record-current' => 0,
 
                        'record-element-name' => !empty( 
$_POST['record-element-name'] )
                                ? $_POST['record-element-name']
@@ -212,17 +216,29 @@
         *
         * @param {array} $element_mapped_to_mediawiki_template
         * @param {string} $metadata_raw
-        * @return {null|Title}
+        * @return {null|Title|bool}
         */
        public function processMatchingElement(
                array &$user_options,
                $element_mapped_to_mediawiki_template,
                $metadata_raw
        ) {
+               $result = null;
+
                $this->_MediawikiTemplate->metadata_raw = $metadata_raw;
                $this->_MediawikiTemplate->populateFromArray( 
$element_mapped_to_mediawiki_template );
 
-               return $this->_UploadHandler->saveMediaFile( $user_options );
+               if ( $user_options['save-as-batch-job'] ) {
+                       $result = $this->_UploadHandler->saveMediafileViaJob(
+                               $user_options,
+                               $metadata_raw,
+                               $element_mapped_to_mediawiki_template
+                       );
+               } else {
+                       $result = 
$this->_UploadHandler->saveMediafileAsContent( $user_options );
+               }
+
+               return $result;
        }
 
        /**
@@ -286,7 +302,10 @@
                } elseif ( $Metadata_Title instanceof Title ) {
                        $Metadata_Page = new WikiPage( $Metadata_Title );
                        $Metadata_Content = $Metadata_Page->getContent( 
Revision::RAW );
-                       $mediafile_titles = 
$this->_XmlMappingHandler->processXml( $user_options, $Metadata_Content );
+                       $mediafile_titles = 
$this->_XmlMappingHandler->processXml(
+                               $user_options,
+                               $Metadata_Content
+                       );
                } else {
                        throw new MWException(
                                wfMessage( 
'gwtoolset-metadata-file-url-not-present' )
@@ -300,12 +319,11 @@
                 * if more metadata records exist in the metadata file, create 
another
                 * UploadMetadataJob
                 */
-               if ( empty( $this->SpecialPage ) &&
-                       (int)$user_options['record-count'] > (
-                               (int)$user_options['record-begin'] + 
(int)Config::$job_throttle
-                       )
+               if ( empty( $this->SpecialPage )
+                       && (int)$user_options['record-count']
+                       >= ( (int)$user_options['record-begin'] + 
(int)Config::$job_throttle )
                ) {
-                       $_POST['record-begin'] = 
(int)$user_options['record-count'];
+                       $_POST['record-begin'] = 
(int)$user_options['record-current'];
                        $this->createMetadataBatchJob( $user_options );
                }
 
@@ -364,10 +382,11 @@
                                                wfMessage( 
'gwtoolset-step-4-heading' )->escaped()
                                        ) .
                                        $this->createMetadataBatchJob( 
$user_options );
-                               /**
-                                * when $this->SpecialPage is empty, this 
method is being run
-                                * by a wiki job; typically, uploadMediafileJob.
-                                */
+
+                       /**
+                        * when $this->SpecialPage is empty, this method is 
being run
+                        * by a wiki job; typically, uploadMediafileJob.
+                        */
                        } else {
                                $result = $this->processMetadata( $user_options 
);
                        }
diff --git a/includes/Handlers/UploadHandler.php 
b/includes/Handlers/UploadHandler.php
index 8faddbf..c19919b 100644
--- a/includes/Handlers/UploadHandler.php
+++ b/includes/Handlers/UploadHandler.php
@@ -270,6 +270,13 @@
                $result = array( 'content-type' => null, 'extension' => null, 
'url' => null );
                $pathinfo = array();
 
+               if ( empty( $url ) ) {
+                       throw new MWException(
+                               __METHOD__ . ' ' .
+                               wfMessage( 'gwtoolset-no-url-to-evaluate' 
)->escaped()
+                       );
+               }
+
                $Http = MWHttpRequest::factory(
                        $url,
                        array(
@@ -401,6 +408,28 @@
        }
 
        /**
+        * @param {String} $title
+        * @throws {MWException}
+        * @return {Title}
+        */
+       protected function getTitle( $title ) {
+               $result = \GWToolset\getTitle(
+                       \GWToolset\stripIllegalTitleChars( $title ),
+                       Config::$mediafile_namespace,
+                       array( 'must-be-known' => false )
+               );
+
+               if ( !( $result instanceof Title ) ) {
+                       throw new MWException(
+                               wfMessage( 'gwtoolset-title-bad' )
+                                       ->params( $title )->parse()
+                       );
+               }
+
+               return $result;
+       }
+
+       /**
         * retrieves the metadata file via :
         * - a url to the local wiki
         * - or the uploaded file given in the $_POST'ed form
@@ -515,14 +544,17 @@
                $this->augmentAllowedExtensions( 
Config::$accepted_metadata_types );
                WikiChecks::increaseHTTPTimeout( 120 );
 
-               $Metadata_Title =
-                       Title::makeTitleSafe(
-                               Config::$metadata_namespace,
+               $Metadata_Title = \GWToolset\getTitle(
+                       \GWToolset\stripIllegalTitleChars(
                                Config::$metadata_sets_subpage . '/' .
-                                       $this->_User->getName() . '/' .
-                                       $this->_File->pathinfo['filename'] .
-                                       '.' . 
$this->_File->pathinfo['extension']
-                       );
+                               $this->_User->getName() . '/' .
+                               $this->_File->pathinfo['filename'] .
+                               '.' . $this->_File->pathinfo['extension'],
+                               array( 'allow-subpage' => true )
+                       ),
+                       Config::$metadata_namespace,
+                       array( 'must-be-known' => false )
+               );
 
                $text = file_get_contents( $this->_File->tmp_name );
                $Metadata_Content = ContentHandler::makeContent( $text, 
$Metadata_Title );
@@ -569,15 +601,15 @@
        }
 
        /**
-        * controls the workflow for saving media files
-        *
+        * @todo does ContentHandler filter $options['text']?
+        * @todo does WikiPage filter $options['comment']?
         * @param {array} $user_options
-        * an array of user options that was submitted in the html form
-        *
+        * @throws {MWException}
         * @return {null|Title}
         */
-       public function saveMediaFile( array &$user_options ) {
-               $result = null;
+       public function saveMediafileAsContent( array &$user_options ) {
+               $Title = null;
+               $Status = null;
                $options = array();
 
                $this->validateUserOptions( $user_options );
@@ -600,39 +632,9 @@
 
                $options['text'] = $this->getText();
 
-               if ( $this->user_options['save-as-batch-job'] ) {
-                       $Status = $this->saveMediafileViaJob( $options );
-               } else {
-                       $result = $this->saveMediafileAsContent( $options );
-               }
-
-               return $result;
-       }
-
-       /**
-        * @todo does ContentHandler filter $options['text']?
-        * @todo does WikiPage filter $options['comment']?
-        * @param {array} $options
-        * @throws {MWException}
-        * @return {Title}
-        */
-       public function saveMediafileAsContent( array &$options ) {
-               $Status = null;
                WikiChecks::increaseHTTPTimeout();
                $this->validatePageOptions( $options );
-
-               $Title = \GWToolset\getTitle(
-                       \GWToolset\stripIllegalTitleChars( $options['title'] ),
-                       Config::$mediafile_namespace,
-                       array( 'must-be-known' => false )
-               );
-
-               if ( !( $Title instanceof Title ) ) {
-                       throw new MWException(
-                               wfMessage( 'gwtoolset-title-bad' )
-                                       ->params( $options['title'] )->parse()
-                       );
-               }
+               $Title = $this->getTitle( $options['title'] );
 
                if ( !$Title->isKnown() ) {
                        $Status = $this->uploadMediaFileViaUploadFromUrl( 
$options, $Title );
@@ -657,10 +659,20 @@
        }
 
        /**
-        * @param {array} $options
+        * save a metadata record as a new/updated wiki page
+        *
+        * @param {array} $user_options
+        * an array of user options that was submitted in the html form
+        *
+        * @param {array} $element_mapped_to_mediawiki_template
+        * @param {string} $metadata_raw
         * @return {bool}
         */
-       protected function saveMediafileViaJob( array &$options ) {
+       public function saveMediafileViaJob(
+               array &$user_options,
+               $metadata_raw = null,
+               $element_mapped_to_mediawiki_template
+       ) {
                $result = false;
                $job = null;
                $sessionKey = null;
@@ -669,20 +681,18 @@
                        return;
                }
 
+               $this->validateUserOptions( $user_options );
+
                $job = new UploadMediafileJob(
-                       Title::makeTitleSafe(
-                               Config::$mediafile_namespace,
-                               $options['title']
+                       Title::newFromText(
+                       'User:' . $this->_User->getName() . '/' . Config::$name 
. ' Mediafile Batch Job'
                        ),
                        array(
-                               'comment' => $options['comment'],
-                               'ignorewarnings' => $options['ignorewarnings'],
-                               'text' => $options['text'],
-                               'title' => $options['title'],
-                               'url-to-the-media-file' => 
$options['url-to-the-media-file'],
-                               'username' => $this->_User->getName(),
-                               'user_options' => $this->user_options,
-                               'watch' => $options['watch']
+                               'element-mapped-to-mediawiki-template' => 
$element_mapped_to_mediawiki_template,
+                               'post' => $_POST,
+                               'metadata-raw' => $metadata_raw,
+                               'user-name' => $this->_User->getName(),
+                               'user-options' => $user_options
                        )
                );
 
@@ -760,19 +770,17 @@
        }
 
        /**
+        * makes sure that the following values are present
+        *   - title
+        *   - ignorewarnings
+        *   - text
+        *   - url-to-the-media-file
+        *
         * @param {array} $options
         * @throws {MWException}
         * @return {void}
         */
        protected function validatePageOptions( array &$options ) {
-               if ( empty( $options['title'] ) ) {
-                       throw new MWException(
-                               wfMessage( 'gwtoolset-developer-issue' )
-                                       ->params( wfMessage( 
'gwtoolset-no-title' )->escaped() )
-                                       ->parse()
-                       );
-               }
-
                if ( !isset( $options['ignorewarnings'] ) ) {
                        throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
@@ -788,6 +796,12 @@
                                        ->params( wfMessage( 
'gwtoolset-no-text' )->escaped() )
                                        ->parse()
                        );
+               }if ( empty( $options['title'] ) ) {
+                       throw new MWException(
+                               wfMessage( 'gwtoolset-developer-issue' )
+                                       ->params( wfMessage( 
'gwtoolset-no-title' )->escaped() )
+                                       ->parse()
+                       );
                }
 
                if ( empty( $options['url-to-the-media-file'] ) ) {
diff --git a/includes/Handlers/Xml/XmlMappingHandler.php 
b/includes/Handlers/Xml/XmlMappingHandler.php
index 0e21c4c..4c4ae4f 100644
--- a/includes/Handlers/Xml/XmlMappingHandler.php
+++ b/includes/Handlers/Xml/XmlMappingHandler.php
@@ -206,7 +206,7 @@
         *
         * @return {array}
         * - $result['Title'] {Title}
-        * - $result['stop-reading'] {boolean}
+        * - $result['stop-reading'] {bool}
         */
        protected function processDOMElements( $XMLElement, array 
&$user_options ) {
                $result = array( 'Title' => null, 'stop-reading' => false );
@@ -225,6 +225,7 @@
 
                if ( !isset( $user_options['record-element-name'] )
                        || !isset( $user_options['record-count'] )
+                       || !isset( $user_options['record-current'] )
                ) {
                        throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
@@ -248,23 +249,26 @@
                                }
 
                                if ( !empty( $record ) ) {
-                                       $user_options['record-count'] += 1;
+                                       $user_options['record-current'] += 1;
 
-                                       // don’t process the element if the 
record count is not >=
-                                       // the record nr we should start 
processing on
-                                       if ( $user_options['record-count'] < 
$user_options['record-begin'] ) {
+                                       // don’t process the element if the 
current record nr is <
+                                       // the record nr we should begin 
processing on
+                                       if ( $user_options['record-current'] < 
$user_options['record-begin'] ) {
                                                break;
                                        }
 
-                                       // stop processing if the record count 
is > the record nr we should
-                                       // start processing on plus the job 
throttle
-                                       if ( $user_options['record-count'] > 
$user_options['record-begin'] + Config::$job_throttle ) {
+                                       // stop processing if the current 
record nr is >=
+                                       // the record nr we should begin 
processing on plus the job throttle
+                                       if ( $user_options['record-current']
+                                               >= 
$user_options['record-begin'] + Config::$job_throttle
+                                       ) {
                                                $result['stop-reading'] = true;
                                                break;
                                        }
 
                                        $result['Title'] = 
$this->_MappingHandler->processMatchingElement(
-                                               $user_options, 
$this->getDOMElementMapped( $record ),
+                                               $user_options,
+                                               $this->getDOMElementMapped( 
$record ),
                                                $outer_xml
                                        );
                                }
diff --git a/includes/Jobs/UploadMediafileJob.php 
b/includes/Jobs/UploadMediafileJob.php
index 7044554..668b87d 100644
--- a/includes/Jobs/UploadMediafileJob.php
+++ b/includes/Jobs/UploadMediafileJob.php
@@ -8,27 +8,16 @@
  */
 
 namespace GWToolset\Jobs;
-use GWToolset\Handlers\UploadHandler,
+use GWToolset\Adapters\Php\MappingPhpAdapter,
+       GWToolset\Adapters\Php\MediawikiTemplatePhpAdapter,
+       GWToolset\Models\Mapping,
+       GWToolset\Models\MediawikiTemplate,
+       GWToolset\Handlers\UploadHandler,
        MWException,
        Job,
        User;
 
 class UploadMediafileJob extends Job {
-
-       /**
-        * {UploadHandler}
-        */
-       protected $_UploadHandler;
-
-       /**
-        * @var {User}
-        */
-       protected $_User;
-
-       /**
-        * @var {string}
-        */
-       public $filename_metadata;
 
        /**
         * @param {Title} $title
@@ -41,38 +30,37 @@
        }
 
        /**
+        * a control method for re-establishing application state so that the 
metadata can be processed.
+        * this is similar to MetadataMappingHandler::processMetadata(), 
however it avoids the necessity
+        * to process the metadata file
+        *
         * @return {bool|Title}
         */
        protected function processMetadata() {
                $result = false;
+               $_POST = $this->params['post'];
 
-               $this->_UploadHandler = new UploadHandler(
+               $MediawikiTemplate = new MediawikiTemplate( new 
MediawikiTemplatePhpAdapter() );
+               $MediawikiTemplate->getMediaWikiTemplate( 
$this->params['user-options'] );
+
+               $Mapping = new Mapping( new MappingPhpAdapter() );
+               $Mapping->mapping_array = 
$MediawikiTemplate->getMappingFromArray( $_POST );
+               $Mapping->setTargetElements();
+               $Mapping->reverseMap();
+
+               $User = User::newFromName( $this->params['user-name'] );
+
+               $UploadHandler = new UploadHandler(
                        array(
-                               'User' => $this->_User
+                               'Mapping' => $Mapping,
+                               'MediawikiTemplate' => $MediawikiTemplate,
+                               'User' => $User,
                        )
                );
 
-               $this->_UploadHandler->user_options = 
$this->params['user_options'];
-               $result = $this->_UploadHandler->saveMediafileAsContent( 
$this->params );
-
-               return $result;
-       }
-
-       /**
-        * @return {bool}
-        */
-       protected function validateParams() {
-               $result = true;
-
-               if ( empty( $this->params['username'] ) ) {
-                       error_log( __METHOD__ . ' : no 
$this->params[\'username\'] provided' . PHP_EOL );
-                       $result = false;
-               }
-
-               if ( empty( $this->params['user_options'] ) ) {
-                       error_log( __METHOD__ . ' : no 
$this->params[\'user_options\'] provided' . PHP_EOL );
-                       $result = false;
-               }
+               $MediawikiTemplate->metadata_raw = 
$this->params['metadata-raw'];
+               $MediawikiTemplate->populateFromArray( 
$this->params['element-mapped-to-mediawiki-template'] );
+               $result = $UploadHandler->saveMediafileAsContent( 
$this->params['user-options'] );
 
                return $result;
        }
@@ -89,16 +77,46 @@
                        return $result;
                }
 
-               $this->_User = User::newFromName( $this->params['username'] );
-
                try {
                        $result = $this->processMetadata();
                } catch ( MWException $e ) {
-                       error_log( $e->getMessage() );
+                       $this->setLastError(
+                               __METHOD__ . ': ' .
+                               $e->getMessage() .
+                               print_r( $this->params['user-options'], true )
+                       );
                }
 
-               if ( !$result ) {
-                       error_log( "Could not save [ {$this->params['title']} ] 
to the wiki." );
+               return $result;
+       }
+
+       /**
+        * @return {bool}
+        */
+       protected function validateParams() {
+               $result = true;
+
+               if ( empty( 
$this->params['element-mapped-to-mediawiki-template'] ) ) {
+                       $this->setLastError(
+                               __METHOD__ .
+                               ': no 
$this->params[\'element-mapped-to-mediawiki-template\'] provided'
+                       );
+                       $result = false;
+               }
+
+               if ( empty( $this->params['metadata-raw'] ) ) {
+                       $this->setLastError( __METHOD__ . ': no 
$this->params[\'metadata-raw\'] provided' );
+                       $result = false;
+               }
+
+               if ( empty( $this->params['user-name'] ) ) {
+                       $this->setLastError( __METHOD__ . ': no 
$this->params[\'user-name\'] provided' );
+                       $result = false;
+               }
+
+               if ( empty( $this->params['user-options'] ) ) {
+                       $this->setLastError( __METHOD__ . ': no 
$this->params[\'user-options\'] provided' );
+                       $result = false;
                }
 
                return $result;
diff --git a/includes/Jobs/UploadMetadataJob.php 
b/includes/Jobs/UploadMetadataJob.php
index aed02a6..b72b70a 100644
--- a/includes/Jobs/UploadMetadataJob.php
+++ b/includes/Jobs/UploadMetadataJob.php
@@ -29,11 +29,6 @@
 class UploadMetadataJob extends Job {
 
        /**
-        * @var {MetadataMappingHandler}
-        */
-       protected $_MetadataMappingHandler;
-
-       /**
         * @param {Title} $title
         * @param {bool|array} $params
         * @param {int} $id
@@ -44,20 +39,19 @@
        }
 
        /**
-        * @return {bool}
+        * a control method for re-establishing application state so that the 
metadata can be processed
+        *
+        * @return {bool|Title}
         */
-       protected function validateParams() {
-               $result = true;
+       protected function processMetadata() {
+               $result = false;
+               $_POST = $this->params['post'];
 
-               if ( empty( $this->params['username'] ) ) {
-                       error_log( __METHOD__ . ' : no $this->params[\'user\'] 
provided' . PHP_EOL );
-                       $result = false;
-               }
+               $MetadataMappingHandler = new MetadataMappingHandler(
+                       array( 'User' => User::newFromName( 
$this->params['user-name'] ) )
+               );
 
-               if ( empty( $this->params['post'] ) ) {
-                       error_log( __METHOD__ . ' : no $this->params[\'post\'] 
provided' . PHP_EOL );
-                       $result = false;
-               }
+               $result = $MetadataMappingHandler->processRequest();
 
                return $result;
        }
@@ -74,15 +68,29 @@
                        return $result;
                }
 
-               $_POST = $this->params['post'];
-               $this->_MetadataMappingHandler = new MetadataMappingHandler(
-                       array( 'User' => User::newFromName( 
$this->params['username'] ) )
-               );
-
                try {
-                       $result = 
$this->_MetadataMappingHandler->processRequest();
+                       $result = $this->processMetadata();
                } catch ( MWException $e ) {
-                       error_log( $e->getMessage() );
+                       $this->setLastError( __METHOD__ . ': ' . 
$e->getMessage() );
+               }
+
+               return $result;
+       }
+
+       /**
+        * @return {bool}
+        */
+       protected function validateParams() {
+               $result = true;
+
+               if ( empty( $this->params['user-name'] ) ) {
+                       $this->setLastError( __METHOD__ . ': no 
$this->params[\'user-name\'] provided' );
+                       $result = false;
+               }
+
+               if ( empty( $this->params['post'] ) ) {
+                       $this->setLastError( __METHOD__ . ': no 
$this->params[\'post\'] provided' );
+                       $result = false;
                }
 
                return $result;

-- 
To view, visit https://gerrit.wikimedia.org/r/90149
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I595168caba21fa23bda202724933f38de96f322a
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