Moodle
  1. Moodle
  2. MDL-35361

updating (overwriting) a file in private area which is linked multiple times to courses - error

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.3.2
    • Fix Version/s: None
    • Component/s: Filepicker, Files API
    • Labels:
      None
    • Affected Branches:
      MOODLE_23_STABLE
    • Rank:
      44036

      Description

      step to reproduce:
      1) upload a file to your private file area (eg example.jpg)
      2) link it to a course
      2.1) go to a course and add new file
      2.2) in the content box click add, in file picker select private files, select the file, and choose "create an alias..." in the popup.
      2.3) save and return to course
      3) link it to another course (see step 2)
      4) go to my private files
      5) click add, upload a different file, save as the previous file name (eg. example.jpg), click overwrite.
      (minor bug here is that the thumbnail doesn't refresh in file list)
      6) click save changes

      ERROR:
      Coding error detected, it must be fixed by a programmer: PHP catchable fatal error

      More information about this error

      Debug info: Argument 1 passed to file_storage::update_references_to_storedfile() must be an instance of stored_file, null given, called in /var/www/clients/client1/web6/web/lib/filelib.php on line 835 and defined
      Error code: codingerror
      Stack trace:
      line 397 of /lib/setuplib.php: coding_exception thrown
      line 1823 of /lib/filestorage/file_storage.php: call to default_error_handler()
      line 835 of /lib/filelib.php: call to file_storage->update_references_to_storedfile()
      line 291 of /lib/filelib.php: call to file_save_draft_area_files()
      line 64 of /user/files.php: call to file_postupdate_standard_filemanager()

        Issue Links

          Activity

          Hide
          kiswap added a comment -

          maybe a resolution:

          lib/filelib.php, line 831
                      // Replaced file content
                      if ($oldfile->get_contenthash() != $newfile->get_contenthash() || $oldfile->get_filesize() != $newfile->get_filesize()) {
                          $oldfile->replace_content_with($newfile);
                          // push changes to all local files that are referencing this file
                          $fs->update_references_to_storedfile($newfile);
                      }
          

          change $this to $newfile

          lib/filestorage/file_storage.php, line 1823
              public function update_references_to_storedfile(stored_file $storedfile) {
                  global $CFG,$DB;
          

          add $DB to global

          Show
          kiswap added a comment - maybe a resolution: lib/filelib.php, line 831 // Replaced file content if ($oldfile->get_contenthash() != $newfile->get_contenthash() || $oldfile->get_filesize() != $newfile->get_filesize()) { $oldfile->replace_content_with($newfile); // push changes to all local files that are referencing this file $fs->update_references_to_storedfile($newfile); } change $this to $newfile lib/filestorage/file_storage.php, line 1823 public function update_references_to_storedfile(stored_file $storedfile) { global $CFG,$DB; add $DB to global
          Hide
          Marina Glancy added a comment -

          thanks for spotting that and providing a fix
          I agree with the fix completely - $this should be replaced with $newfile

          Show
          Marina Glancy added a comment - thanks for spotting that and providing a fix I agree with the fix completely - $this should be replaced with $newfile
          Hide
          Marina Glancy added a comment -

          this duplicates MDL-35376

          Show
          Marina Glancy added a comment - this duplicates MDL-35376

            People

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

              Dates

              • Created:
                Updated:
                Resolved: