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

backuptempdir bug in course copy feature

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.1.9, 4.2.6, 4.3.3
    • Backup
    • None
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE

      Hello,

      We've identified and fixed an issue with the course copy functionality.

      A teacher with the necessary permissions can create a copy of a course using the dedicated button on the course administration page. Afterward, they are redirected to the page that lists pending tasks. However, when the cron job runs and attempts to create the new course, it encounters a failure.

      The problem originates from our `config.php` file, where we conditionally modify the `$CFG->backuptempdir` variable as follows:

          if (defined('CLI_SCRIPT')) {
              $CFG->backuptempdir = '...';
          }
      

          

      This modification is made to ensure that all temporary backup files are stored on a local disk to the server running the cron job, rather than on an NFS folder shared by the entire cluster. Unfortunately, Moodle backup controllers are serialized (as "web", reflecting teacher actions) and deserialized (as "cli", as they are adhoc tasks) during this process. This results in the `backuptempdir` not being correctly reused in `backup/util/plan/backup_plan.class.php`.

      To address this, we've added the `__unserialize()` function to the mentioned class, allowing for overrides.

      The diff:

       

        
          diff --git a/backup/util/plan/backup_plan.class.php b/backup/util/plan/backup_plan.class.php
          index ce23748bc99..6c5a667d17c 100644
          --- a/backup/util/plan/backup_plan.class.php
          +++ b/backup/util/plan/backup_plan.class.php
          @@ -161,6 +161,24 @@ class backup_plan extends base_plan implements loggable {
                       $event->trigger();
                   }
               }
          +
          +    // CBlue START - #618007 - Core modification to override $this->basepath, which was initialized with the "web" parameters and not "cli".
          +    /**
          +     * Core modification to override $this->basepath, which was initialized with the "web" parameters and not "cli".
          +     */
          +    public function __unserialize(array $data): void
          +    {
          +        foreach ($data as $k => $v) {
          +            $k = ltrim($k, " \n\r\t\v\0*");
          +            $this->\{$k} = $v;
          +        }
          +
          +        if (CLI_SCRIPT) {
          +            $backuptempdir = make_backup_temp_directory('');
          +            $this->basepath = $backuptempdir . '/' . $this->controller->get_backupid();
          +        }
          +    }
          +    // CBlue END - #618007 - Core modification to override $this->basepath, which was initialized with the "web" parameters and not "cli".
      

      What do you think of this change?

      Thank you in advance,

      Kind regards,

      Olivier

            Unassigned Unassigned
            Trolli Olivier Piton
            Votes:
            4 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

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