Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: None
    • Labels:
      None
    • Affected Branches:
      MOODLE_23_STABLE
    • Rank:
      39934

      Description

      Ensure that MDL-28666 and MDL-31901 work together.

      What we need to make sure:

      1. Files that are references to external resources (let's call them REF) must have special shortcut icon in filemanager

      2. When user selects a REF file in filemanager, he can see the 'Origin' of the file in the way that original repository wants to show it.

      3. (wish list) Repository return different detail level of original location for the user who is owner of the REF file and anybody else. Trick is that the owner is not definitely the user who is currently editing.

      4. Files in 'Private files' or 'Course legacy files' that are themselves the source of references of other files in the system (let's call them SRC) need to have "link" icon in filemanager. When user tries to remove/rename/overwrite SRC file he is warned that all ## existing references will be updated/converted to copies.

      5. When SRC file is updated during editing (i.e. author/license information is changed, or file was overwritten by another file with the same name), all references to this file remain!

      6. When SRC file was deleted during editing (or moved/renamed which resulted in that there is no file in the original location), all references to this file must be converted to copies.

        Issue Links

          Activity

          Hide
          Marina Glancy added a comment -

          Martin, Dongsheng, added you as watchers

          Show
          Marina Glancy added a comment - Martin, Dongsheng, added you as watchers
          Hide
          Marina Glancy added a comment -

          7. User can update author/license of TRG file, rename or move it without loosing the reference

          8. File can be at the same time both SRC and TRG

          Show
          Marina Glancy added a comment - 7. User can update author/license of TRG file, rename or move it without loosing the reference 8. File can be at the same time both SRC and TRG
          Hide
          Marina Glancy added a comment - - edited

          I created dummy functions in my branch to test UI changes.
          Dongsheng, please tell me if you decide to change their names/location:

          1. stored_file::is_external_file() - whether file is TRG, reference to somewhere else. Works as well for files in draft file area

          2. filestorage::get_reference_count(stored_file $file) - if file is SRC returns number of files in moodle pointing to it. $file can be file in draft file area

          3. stored_file::get_reference_details() - returns human-readable original location for TRG file. Also works for files in draft file area

          Show
          Marina Glancy added a comment - - edited I created dummy functions in my branch to test UI changes. Dongsheng, please tell me if you decide to change their names/location: 1. stored_ file::is_external_file( ) - whether file is TRG, reference to somewhere else. Works as well for files in draft file area 2. filestorage::get_reference_count(stored_file $file) - if file is SRC returns number of files in moodle pointing to it. $file can be file in draft file area 3. stored_ file::get_reference_details( ) - returns human-readable original location for TRG file. Also works for files in draft file area
          Hide
          Marina Glancy added a comment -

          and also I still use function stored_file::update() to update author/license information. Hope it will be replaced with something more secure

          Show
          Marina Glancy added a comment - and also I still use function stored_ file::update( ) to update author/license information. Hope it will be replaced with something more secure
          Hide
          Marina Glancy added a comment -

          My suggestion on linking file in draft area to the original file without DB changes:

          I would use the file reference field in file in draft area to point to the original file.
          And all the functions that return information about real references will check if area='draft' => find the original and run the same function for original

          Show
          Marina Glancy added a comment - My suggestion on linking file in draft area to the original file without DB changes: I would use the file reference field in file in draft area to point to the original file. And all the functions that return information about real references will check if area='draft' => find the original and run the same function for original
          Hide
          Marina Glancy added a comment - - edited

          stored_file::get_references() - return list of files referencing to this file, works for draft area files as well

          Show
          Marina Glancy added a comment - - edited stored_ file::get_references( ) - return list of files referencing to this file, works for draft area files as well
          Hide
          Martin Dougiamas added a comment -

          Yep, we'll stuff the "source" field with all the necessary data to allow draft files to find out about external references.

          Show
          Martin Dougiamas added a comment - Yep, we'll stuff the "source" field with all the necessary data to allow draft files to find out about external references.
          Hide
          Dongsheng Cai added a comment -

          Sample code for the source field hack:

          
          fs = get_file_storage();
          // Or use get_area_files to get all draft files
          $draftfile = $fs->get_file_by_id(194);
          $source = unserialize($draftfile->get_source());
          $ref = $source->original;
          $count = $fs->search_references_count($ref);
          var_dump($count);
          
          Show
          Dongsheng Cai added a comment - Sample code for the source field hack: fs = get_file_storage(); // Or use get_area_files to get all draft files $draftfile = $fs->get_file_by_id(194); $source = unserialize($draftfile->get_source()); $ref = $source->original; $count = $fs->search_references_count($ref); var_dump($count);
          Hide
          Marina Glancy added a comment -

          Dongsheng,

          imagine I have a draft area file $file.

          Can you write me the exact code how I can:
          1. check if this is an external file
          2. find number of reference pointing to this file
          3. find out the human-readable original location
          4. get list of files that reference this file

          from your code I see some function search_references_count() which was never discussed above

          Show
          Marina Glancy added a comment - Dongsheng, imagine I have a draft area file $file. Can you write me the exact code how I can: 1. check if this is an external file 2. find number of reference pointing to this file 3. find out the human-readable original location 4. get list of files that reference this file from your code I see some function search_references_count() which was never discussed above
          Hide
          Dongsheng Cai added a comment -

          1. check if this is an external file

          $file->is_external_file()
          

          2. find number of reference pointing to this file

          $source = unserialize($file->get_source());
          $ref = $source->original;
          $count = $fs->search_references_count($ref);
          

          3. find out the human-readable original location

          $text = $file->get_reference_details();
          

          4. get list of files that reference this file

          $source = unserialize($file->get_source());
          $ref = $source->original;
          $draftfiles = $fs->search_references($ref);
          foreach ($draftfiles as $file) {
              // $file is a stored_file instance
          }
          
          Show
          Dongsheng Cai added a comment - 1. check if this is an external file $file->is_external_file() 2. find number of reference pointing to this file $source = unserialize($file->get_source()); $ref = $source->original; $count = $fs->search_references_count($ref); 3. find out the human-readable original location $text = $file->get_reference_details(); 4. get list of files that reference this file $source = unserialize($file->get_source()); $ref = $source->original; $draftfiles = $fs->search_references($ref); foreach ($draftfiles as $file) { // $file is a stored_file instance }
          Hide
          Marina Glancy added a comment -

          Thank you!

          Show
          Marina Glancy added a comment - Thank you!
          Show
          Dongsheng Cai added a comment - I added some unit tests: https://github.com/dongsheng/moodle/commit/d2fc251bb676b98d3a829765b566320f6bf86035
          Hide
          Marina Glancy added a comment -

          Dongsheng,
          I started testing what happens with links when renaming/moving/deleting files.

          This is the list of bugs I discovered:

          1. I can not rename ( using stored_file::rename() ) a folder, because filename '.' does not pass validation in stored_file::update()

          2. when I delete the SRC file, the links become broken (they are not transferred into copies as supposed to)

          3. when I rename the SRC file, the same

          4. COMPLETELY WEIRD and accidentally discovered. I was able to pick up a file from recent files that used to be a reference and it displayed to me as a reference. But actually this was a reference to the file that was deleted in the previous test. So it was altogether completely strage behaviour. I suppose, references should not appear in recent files at all.

          I will continue testing after your fixes
          Thanks.

          Show
          Marina Glancy added a comment - Dongsheng, I started testing what happens with links when renaming/moving/deleting files. This is the list of bugs I discovered: 1. I can not rename ( using stored_ file::rename( ) ) a folder, because filename '.' does not pass validation in stored_ file::update( ) 2. when I delete the SRC file, the links become broken (they are not transferred into copies as supposed to) 3. when I rename the SRC file, the same 4. COMPLETELY WEIRD and accidentally discovered. I was able to pick up a file from recent files that used to be a reference and it displayed to me as a reference. But actually this was a reference to the file that was deleted in the previous test. So it was altogether completely strage behaviour. I suppose, references should not appear in recent files at all. I will continue testing after your fixes Thanks.
          Hide
          Dongsheng Cai added a comment -

          Marina, can you review commit: 6eaa0f1

          Show
          Dongsheng Cai added a comment - Marina, can you review commit: 6eaa0f1
          Hide
          Marina Glancy added a comment -

          this is what I tested:
          1. added file "France.jpg" to my private files, saved private files.
          2. picked this file by reference into folder resource files, saved changes.
          3. checked that I can download file from folder and from filemanager when editing folder.
          4. removed the file "France.jpg" from private files, saved private files.
          5. made sure I can download file "France.jpg" from folder.
          6. entered the editing mode for folder. I am able to download file "France.jpg", but it is still shown as a reference to Privatefiles/France.jpg (which does not exist any more.

          Show
          Marina Glancy added a comment - this is what I tested: 1. added file "France.jpg" to my private files, saved private files. 2. picked this file by reference into folder resource files, saved changes. 3. checked that I can download file from folder and from filemanager when editing folder. 4. removed the file "France.jpg" from private files, saved private files. 5. made sure I can download file "France.jpg" from folder. 6. entered the editing mode for folder. I am able to download file "France.jpg", but it is still shown as a reference to Privatefiles/France.jpg (which does not exist any more.
          Hide
          Dongsheng Cai added a comment -

          I cannot reproduce that on my end, let do test again.

          Show
          Dongsheng Cai added a comment - I cannot reproduce that on my end, let do test again.
          Hide
          Marina Glancy added a comment -

          sorry, I forgot to save the private files. (headbang)
          I integrated your fix into the branch

          Show
          Marina Glancy added a comment - sorry, I forgot to save the private files. (headbang) I integrated your fix into the branch
          Hide
          Marina Glancy added a comment -

          Tim, I added you as a watcher. Actually this issue looks more like test case.

          Show
          Marina Glancy added a comment - Tim, I added you as a watcher. Actually this issue looks more like test case.
          Hide
          Dongsheng Cai added a comment -

          Marina

          Can you integrate these two: 75c211476deae60fdecea4c8172102cd0cc4b5dc and 725e71c64f2b3be30b7051744ce48473a9004175

          Show
          Dongsheng Cai added a comment - Marina Can you integrate these two: 75c211476deae60fdecea4c8172102cd0cc4b5dc and 725e71c64f2b3be30b7051744ce48473a9004175

            People

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

              Dates

              • Created:
                Updated:
                Resolved: