Extension:GWToolset/Technical Implementation/Handlers/MetadataMappingHandler

GWToolset MetadataMappingHandler.png

General overviewEdit


  1. Validates the POST’ed edit token
    1. if invalid, a user error message is displayed.
    2. if valid, calls processRequest()


The expected outcome of POST’ing the metadata mapping form is that the extension will receive several items from the form:

  1. A record-element-name that identifies the root element in the metadatafile, which contains the mediafile’s metadata.
  2. A mediawiki-template-name that will be used when mapping the metadata found in the metadatafile.
  3. A metadata-mapping-url to a wiki title previously saved as a metadata mapping ( optional ).
  4. A mediafile-throttle that indicates the number of mediafiles that will be added to the job queue each time a batch upload job is run ( optional, default is 10 ).
  5. A metadata-file-url, which is a relative URL reference to the backend metadata file uploaded in step 1: metadata detection.
  6. A record-count based on step 1: metadata detection.
  7. Metadata mapping field/values
  8. Global categories ( optional )
  9. Item specific categories ( optional )
  10. A partner template ( optional )
  11. A summary ( optional )
  12. Whether or not to re-upload the mediafile ( optional )

Step 2: Metadata MappingEdit

This handler is used between step 2: metadata mapping, and step 3: batch preview, in the upload process. The following describes what happens within the processRequest() method:

  1. In this scenario $user_options['preview'] === true
  2. GWTFileBackend-> retrieveFileFromRelativePath() retrieves the metadatafile based on the relative metadata-file-url provided in step 1; this is the metadata file provided by the user.
    • if an exception is thrown a user message is displayed.
  3. XmlMappingHandler->processXml() is sent:
    • the POST’ed form variables as $user_options
    • the FS path to the uploaded stash file
  4. XmlHandler->readXmlAsFile() is sent:
    • the POST’ed form variables as $user_options
    • the FS path to the uploaded metadatafile
    • a callback method in the XmlMappingHandler
  5. XmlHandler->readXmlAsFile() starts a read process that will:
    • use the callback method provided to process the metadata records found during the read process.
    • continue to the end of the metadata file or stop reading if $read_result['stop-reading'] is set to true.
  6. XmlMappingHandler->processDOMElement(), the callback passed to XmlHandler->processXml() will:
    • Determine if XmlHandler->readXmlAsFile() is on the record it should start processing
    • Set $result['stop-reading'] = true if the Config::$job_throttle has been reached
    • Use MetadataMappingHandler->processMatchingElement() to handle a metadata record if the Config::$job_throttle has not been reached
  7. MetadataMappingHandler->processMatchingElement() will:
    • Use UploadHandler->saveMediafileAsContent() to save the mediafile to the wiki and return the Title to XmlMappingHandler, which will return it to XmlHandler, which will add it to an array of successfully created mediafile Titles.
  8. When XmlMappingHandler->processDOMElements() sends $result['stop-reading'] = true to XmlHandler->readXmlAsFile(), it returns its array of Titles back to MetadataMappingHandler.
  9. MetadataMappingHandler->processRequest() then uses PreviewForm::getForm() to set up the HTML form and returns it to SpecialGWToolset to be displayed.

Step 3: Batch previewEdit

This handler is used between step 3: Batch preview, and step 4: Batch upload, in the upload process. The following describes what happens within the processRequest() method:

  1. In this scenario MetadataMappingHandler->SpecialPage is empty.
  2. MetadataMappingHandler->createMetadataBatchJob():
    • Creates a new UploadMetadataJob()
    • Uses JobQueueGroup::singleton()->push( $job ) to place it in the JobQueue.
      • If the job is successfully added to the job queue a user message is created and sent to SpecialGWToolset to be displayed as step 4: Batch upload.
      • If the job is not successfully created an error message is displayed.