Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-69143

Content bank content cannot generate configdata from uploaded file

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Automatic testing

      Al the new methods are covered by PHPUnit.

      vendor/bin/phpunit -c contentbank 

      Manual testing

      Prerequisites:

      1. Install the test content type provided moodle-contenttype_test.zip into "contentbank/contenttype/test" and install it
      2. download error.txt and correct.txt those files will be used for testing.

      Manual test one: correct file

      1. Go to the contentbank as admin
      2. Click on the upload button, upload the "correct.txt" file and submit the form
        1. Check that the content "This file should be accepted by the plugin!" is displayed
      3. Now click on the edit button
        1. Check that on top of the name input file a message "The original content is imported from "correct.txt". This data is stored in the configdata." appears

      Manual test two: incorrect file

      1. Go to the contentbank as admin
      2. Click on the upload button, upload the "error.txt" file and submit the form
        1. Check the upload form is displayed again with a notice over the file picker with the text "The file cannot be imported as a content. Try a different one."
      3. Now click on the cancel button to return to the contentbank
        1. Check that there is no content called "error.txt" on the content bank
      Show
      Automatic testing Al the new methods are covered by PHPUnit. vendor/bin/phpunit -c contentbank  Manual testing Prerequisites: Install the test content type provided  moodle-contenttype_test.zip  into "contentbank/contenttype/test" and install it download  error.txt  and  correct.txt  those files will be used for testing. Manual test one: correct file Go to the contentbank as admin Click on the upload button, upload the "correct.txt" file and submit the form Check that the content "This file should be accepted by the plugin!" is displayed Now click on the edit button Check that on top of the name input file a message "The original content is imported from "correct.txt". This data is stored in the configdata." appears Manual test two: incorrect file Go to the contentbank as admin Click on the upload button, upload the "error.txt" file and submit the form Check the upload form is displayed again with a notice over the file picker with the text "The file cannot be imported as a content. Try a different one." Now click on the cancel button to return to the contentbank Check that there is no content called "error.txt" on the content bank
    • Affected Branches:
      MOODLE_310_STABLE, MOODLE_39_STABLE
    • Fixed Branches:
      MOODLE_39_STABLE
    • Pull 3.9 Branch:
    • Pull Master Branch:
      MDL-69143-master
    • Sprint:
      Moppies Kanban

      Description

      When the content is uploaded into the content bank, there is no way for the content plugin to parse the uploaded file before the first render. This does not affect H5P because H5P packages are deployed on render, but most content types will need to parse the uploaded content on creation.

      How to reproduce

      1. Install the provided contentype_html plugin
      2. Go to the content bank and try to upload an HTML file

      Expected: the file content is imported in the configdata field, where the HTML is stored.

      What happens: the contenttype_html\content cannot import the content and the resulting content is empty

      Why this happens

      When a file is uploaded into the content bank the current algorithm is:

      1. Invoke contentbank\contenttype "create_content_from_file"
      2. This method invoke contenttype_html\contentype::create_content to create the content record, but it does not provide the file object and, because the file is still in the draft area, cannot be used inside the plugin.
      3. Once the content is created, upload.php invoke "file_save_draft_area_files" to store the file.

      How to solve

      We propose to implement a method called "import_file" inside the contentbank\content that can be overridden by any plugin. By default, this method will just store the file in the correct file area but any plugin can parse the file and even discard it if necessary (returning null).

      One of the features expected for 4.0 is the possibility to import a file into specific content. For now, every time a user upload content into CB this will create new content, even if the file is the same. Implementing the "import_file method" will solve this particular issue and also will provide a method to use in the future.

        Attachments

        1. correct.txt
          0.0 kB
        2. error.txt
          0.0 kB
        3. image-2020-07-03-15-46-41-512.png
          image-2020-07-03-15-46-41-512.png
          19 kB
        4. image-2020-08-13-11-42-52-199.png
          image-2020-08-13-11-42-52-199.png
          146 kB
        5. moodle-contenttype_test.zip
          23 kB

          Issue Links

            Activity

              People

              Assignee:
              tusefomal Ferran Recio
              Reporter:
              tusefomal Ferran Recio
              Peer reviewer:
              Amaia Anabitarte
              Integrator:
              Andrew Nicols
              Tester:
              Janelle Barcega
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                14/Sep/20

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 3 days, 5 hours, 12 minutes
                  3d 5h 12m