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

PHP error when parsing XML backup and the grouped element contains no final elements

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 2.3.5, 2.4.2
    • 2.3.4, 2.4.1, 2.5
    • Backup
    • MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • MOODLE_23_STABLE, MOODLE_24_STABLE
    • MDL-37893-grouped-empty
    • Difficult
    • Hide

      Regression tests:

      1. Execute all phpunit tests before and after applying the patchset. Make sure the results are the same.
      2. Perform a restore of at least one moodle1 (ZIP) and one moodle2 (MBZ) backup file. Make sure it works again (at least as well as without the patchset applied).
      Show
      Regression tests: Execute all phpunit tests before and after applying the patchset. Make sure the results are the same. Perform a restore of at least one moodle1 (ZIP) and one moodle2 (MBZ) backup file. Make sure it works again (at least as well as without the patchset applied).

      Let us have an XML structure like this:

      <MOODLE_BACKUP>
        <COURSE>
          <FORMATDATA>
            <WEEKS>
              <WEEK>
                <SECTION>1</SECTION>
                <HIDENUMBER>1</HIDENUMBER>
              </WEEK>
            </WEEKS>
          </FORMATDATA>
        </COURSE>
      </MOODLE_BACKUP>
      

      Let us parse this XML with our progressive_parser and process it with progressive_parser_processor classes. Let us observe following paths:

      $pr->add_path('/MOODLE_BACKUP/COURSE/FORMATDATA', true);
      $pr->add_path('/MOODLE_BACKUP/COURSE/FORMATDATA/WEEKS/WEEK');
      

      As you can see, the FORMATDATA elements was requested to be grouped (the second parameter of the add_path() method). To refresh your backup/restore API knowledge, if a path is processed as a grouped one, it is returned in one chunk together with all its subpaths.

      Expected behaviour:

      We should get an array like FORMATDATA => WEEKS => WEEK[0], WEEK[1], WEEK[2] etc.

      Actual behaviour:

      PHP error "array_key_exists() expects parameter 2 to be array, null given" when calling build_currentdata() method's code:

      if (!array_key_exists($grouped, $this->currentdata)) {
          $a = new stdclass();
          $a->grouped = $grouped;
          $a->child = $data['path'];
          throw new progressive_parser_exception('xml_cannot_add_to_grouped', $a);
      }
      

            mudrd8mz David Mudrák (@mudrd8mz)
            mudrd8mz David Mudrák (@mudrd8mz)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Andrew Davis Andrew Davis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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