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

create_gradecategories::create_gradecategories_from_data incorrectly calls $DB->rollback

    XMLWordPrintable

Details

    • MOODLE_401_STABLE
    • MOODLE_400_STABLE, MOODLE_401_STABLE
    • MDL-76869-400
    • MDL-76869-401
    • MDL-76869-master
    • Hide
      1. Place the attached test.php script in the root of your moodle installation
      2. Hack grade/edit/tree/lib.php such that the update_gradecategory method immediately throws an exception:

        public static function update_gradecategory(grade_category $gradecategory, stdClass $data) {
            throw new \Exception('exception in update_gradecategory');
        

      3. Run the test.php script:

        php test.php
        

      4. Verify that no ArgumentCountError is thrown and the text: "!!! Exception - exception in update_gradecategory !!!" is displayed
      Show
      Place the attached test.php script in the root of your moodle installation Hack grade/edit/tree/lib.php such that the update_gradecategory method immediately throws an exception: public static function update_gradecategory(grade_category $gradecategory , stdClass $data ) { throw new \Exception( 'exception in update_gradecategory' ); Run the test.php script: php test.php Verify that no ArgumentCountError is thrown and the text: "!!! Exception - exception in update_gradecategory !!!" is displayed

    Description

      lib/dml/moodle_transaction.php

      101
      public function rollback($e) {
      102
          if ($this->is_disposed()) {
      103
              throw new dml_transaction_exception('Transactions already disposed', $this);
      104
          }
      105
          $this->database->rollback_delegated_transaction($this, $e);
      106
      }
      

      grade/classes/external/create_gradecategories.php

      226
      try {
      227
          $transaction = $DB->start_delegated_transaction();
      228
          \grade_edit_tree::update_gradecategory($gradecategory, (object) $data);
      229
          $transaction->allow_commit();
      230
          $createdcats[] = $gradecategory->id;
      231
      } catch (\Exception $e) {
      232
          // If the submitted data was broken for any reason.
      233
          $warnings['database'] = $e->getMessage();
      234
          $transaction->rollback();
      235
          return ['warnings' => $warnings];
      236
      }
      

      rollback needs to be passed an exception. If this code is ever called an ArgumentCountError will be thrown.

      To replicate:

      1. Hack grade/edit/tree/lib.php such that the update_gradecategory method immediately throws an exception:

        public static function update_gradecategory(grade_category $gradecategory, stdClass $data) {
            throw new \Exception('exception in update_gradecategory');
        

      2. Run the test.php script attached to this issue from the root of your moodle installation:

        php test.php
        

      Attachments

        1. 400.png
          400.png
          85 kB
        2. 401.png
          401.png
          106 kB
        3. master.png
          master.png
          99 kB
        4. test.php
          0.2 kB

        Issue Links

          Activity

            People

              cameron1729 cameron1729
              cameron1729 cameron1729
              Peter Burnett Peter Burnett
              Paul Holden Paul Holden
              Ron Carl Alfon Yu Ron Carl Alfon Yu
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                13/Mar/23

                Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 35 minutes
                  35m