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

h5pactivity - H5P file not found (invalid contextid)


    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Minor Minor
    • None
    • 3.11.11
    • H5P
    • None

      In our Moodle-Instance, we using H5P

      If we visit a H5P course activity, we following error message:

      H5P file not found (invalid contextid)

      We could locate the position of the thrown exception within the source and printed the stack trace:

      *** infile.php ***dml_missing_record_exception: Can't find data record in database table context. (SELECT * FROM {context} WHERE id = ? [array ( 0 => 'infile.php', )]) in /srv/moodule/src/lib/dml/moodle_database.php:1646 Stack trace: 
      #0 /srv/moodule/src/lib/dml/moodle_database.php(1622): moodle_database->get_record_select() 
      #1 /srv/moodule/src/lib/accesslib.php(5309): moodle_database->get_record() 
      #2 /srv/moodule/src/lib/accesslib.php(1257): context::instance_by_id() 
      #3 /srv/moodule/src/h5p/classes/api.php(403): get_context_info_array() 
      #4 /srv/moodule/src/h5p/classes/api.php(200): core_h5p\api::can_access_pluginfile_hash() 
      #5 /srv/moodule/src/h5p/classes/api.php(241): core_h5p\api::get_content_from_pluginfile_url() 
      #6 /srv/moodule/src/h5p/classes/player.php(130): core_h5p\api::create_content_from_pluginfile_url() 
      #7 /srv/moodule/src/h5p/embed.php(43): core_h5p\player->__construct() 
      #8 {main}

      As you can see, the provided contextid is 'infile.php', which isn't correct.


      We detected the reason.

      'infile.php' is created by


      $path = substr($path, strpos($path, '.php/') + 5);

      , because '["path":protected]=> string(15) "/pluginfile.php"'.


      We added some more debug code and got following information:

      // in can_access_pluginfile_hash(...)

      // var_dump(url);

      string(122) "https://moodle.XXXXXXXX.TLD/pluginfile.php?file=%2F63826%2Fmod_h5pactivity%2Fpackage%2F0%2Fdrag-and-drop-712.h5p"

      // var_dump(url);
      object(moodle_url)#112 (9) { ["scheme":protected]=> string(5) "https" ["host":protected]=> string(29) "moodle.XXXXXXXX.TLD" ["port":protected]=> string(0) "" ["user":protected]=> string(0) "" ["pass":protected]=> string(0) "" ["path":protected]=> string(15) "/pluginfile.php" ["slashargument":protected]=> string(0) "" ["anchor":protected]=> NULL ["params":protected]=> array(1) { ["file"]=> string(54) "/63826/mod_h5pactivity/package/0/drag-and-drop-712.h5p" } }

      // var_dump(url);

      // after $url->remove_params(array_keys($url->params()));
      object(moodle_url)#112 (9) { ["scheme":protected]=> string(5) "https" ["host":protected]=> string(29) "moodle-test.bfw-schoemberg.de" ["port":protected]=> string(0) "" ["user":protected]=> string(0) "" ["pass":protected]=> string(0) "" ["path":protected]=> string(15) "/pluginfile.php" ["slashargument":protected]=> string(0) "" ["anchor":protected]=> NULL ["params":protected]=> array(0) { } }

      // var_dump($path);
      string(15) "/pluginfile.php"

      // var_dump($contextid);
      string(10) "infile.php" 

      It seems, that '$url->remove_params' removes every param, even the contextid, which it may shouldn't.

      Is there any solution for this bug?

      We even tried to hardcode the contextid '63826', but than the same problem occurred in 'get_pluginfile_hash(...)'. It seems, that the url format is not as aspected.

       Currently Used Versions:
      $version  = 2021051711.02;
      $release  = '3.11.11+ (Build: 20221125)';
      $branch   = '311';

      mod_h5pactivity: 2021051700
      mod_hvp: 1.22.4 (2022012000)

            Unassigned Unassigned
            dkn datenkollektiv
            0 Vote for this issue
            3 Start watching this issue


                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.