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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.4, 2.4.1, 2.5
    • Fix Version/s: 2.3.5, 2.4.2
    • Component/s: Backup
    • Labels:
    • Testing Instructions:
      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).
    • Difficulty:
      Difficult
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-37893-grouped-empty

      Description

      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);
      }
      

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    11/Mar/13