You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The if ($this->owner->Parent()) check will always return true, because even if the file has no actual parent (i.e. no ParentID), the ORM will give us an empty File object, which passes this vague condition.
This check should say if ($this->owner->Parent()->exists()) (or ->Parent()->isInDB() or simply ->ParentID)
However, the current behaviour (although clearly not what was originally intended) is actually good! The file only gets the subsite ID if it is uploaded to a parent folder which also has a subsite ID. It doesn't just get the ID of whatever subsite you happen to be on. This means files, by default, are available to all subsites. I think this is good default behaviour
Basically, this condition just needs to be refactored so that it says it does what it already actually does, lest someone notice this inconsistency and break the current behaviour by "fixing" it.
This is already its own separate issue, but it's part of this overarching theme of file inconsistencies so I'm noting it here.
This can lead to files being inaccessible in the CMS - if I am viewing a Folder assigned to subsite B, I can't swap to another subsite without backing out of this folder. If files in this folder are still assigned to subsite A, I won't be able to view them because I can't swap to that subsite.
If I upload a file in the root (so it doesn't have a SubsiteID) and then move it into a folder which does have a subsite assigned, the file will not inherit the SubsiteID of its new parent folder. This is inconsistent with files which are uploaded directly into this folder, which will inherit the SubsiteID.
There is no way to change the SubsiteID of a file from the CMS UI, so the only way to resolve this is to run some bespoke task to update SubsiteIDs to match their parent folders.
This is related to the issue above, though it is technically a separate issue.
Proposed solution
Files should always inherit their SubsiteID from the parent folder.
The onBeforeWrite() method in the FileSubsites extension should set the SubsiteID of a file to match its parent folder
This excludes folders in the root
This does not exclude folders which are children of other folders
Folders which are children of other folders should not have a dropdown to select their subsite, unless the parent folder is set to the "main site" (i.e. no subsite)
The root is considered to be a folder with SubsiteID of 0
If moving a folder outside another folder into the root, it should retain its current SubsiteID
If moving any other file outside a folder into the root, its SubsiteID should be 0
If the SubsiteID of a folder is changed, it will need to propogate this change down to its children
This would ensure that files always have a subsite ID which matches the parent folder, leading to a much more consistent and predictable experience.
The text was updated successfully, but these errors were encountered:
FileSubsites::onAfterUpload()
doesn't do what it seems to say it doesif ($this->owner->Parent())
check will always returntrue
, because even if the file has no actual parent (i.e. noParentID
), the ORM will give us an emptyFile
object, which passes this vague condition.if ($this->owner->Parent()->exists())
(or->Parent()->isInDB()
or simply->ParentID
)Proposed solution
onBeforeWrite()
method in theFileSubsites
extension should set theSubsiteID
of a file to match its parent folderThis would ensure that files always have a subsite ID which matches the parent folder, leading to a much more consistent and predictable experience.
The text was updated successfully, but these errors were encountered: