Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Dbafs does not handle files that are being replaced #7828

Closed
Toflar opened this issue May 18, 2015 · 7 comments
Closed

Dbafs does not handle files that are being replaced #7828

Toflar opened this issue May 18, 2015 · 7 comments
Assignees
Labels
Milestone

Comments

@Toflar
Copy link
Member

Toflar commented May 18, 2015

I just digged into the Dbafs class once again and I found that when I do this

// foobar.jpg contains a 2000 x 2000 Pixel image
Dbafs::addResource('foobar.jpg');


// foobar.jpg now contains a 100 x 100 Pixel image
Dbafs::addResource('foobar.jpg');

the md5 hash is not updated. I found that you do that check here: https://github.com/contao/core/blob/develop/system/modules/core/drivers/DC_Folder.php#L920-L933

However, I think that's wrong because then everybody has to do that? It should be done in Dbafs::addResource(), right?

@leofeyer leofeyer added this to the 3.5.0 milestone May 19, 2015
@leofeyer leofeyer self-assigned this May 19, 2015
@leofeyer
Copy link
Member

leofeyer commented Jun 2, 2015

That's actually correct, because addResource() only adds the file if it does not yet exist.

@leofeyer leofeyer removed the defect label Jun 2, 2015
@leofeyer leofeyer removed this from the 3.5.0 milestone Jun 2, 2015
@leofeyer leofeyer removed their assignment Jun 2, 2015
@Toflar
Copy link
Member Author

Toflar commented Sep 24, 2015

Hmm...still, that method should be centralized, no?

@fritzmg
Copy link
Contributor

fritzmg commented Sep 24, 2015

👍 I also think this should be done in \Dbafs::addResource()

@leofeyer leofeyer added this to the 3.5.4 milestone Sep 26, 2015
@leofeyer leofeyer modified the milestones: 3.5.4, 3.5.5 Oct 9, 2015
@leofeyer
Copy link
Member

As discussed on Mumble on October 14th, we should update the timestamp and file hash in the Dbafs class on line 100 (Return the model if it exists already).

@leofeyer
Copy link
Member

I have been working on this one today and it turned out that it is not a good idea to always update the folder hash (as @ausi already mentioned). In the core, we are using Dbafs::addResource() 11 times, from which 6 times we do not need to update the hash and 5 times we do.

So there are two possible implementations:

// 1. Always update the folder hash but check for existence beforehand
$file = FilesModel::findByPath('');

if (null === $file) {
    $file = Dbafs::addResource($file);
}

// do something with $file
// 2. We add another flag to the method
$file = Dbafs::addResource($file, true, true); // the second true means "update the hash"

I tend to number 1, because I think it is wrong to use Dbafs::addResource() to retrieve the model. We should use FilesModel::findByPath() instead.

@contao/developers Any objections against implementation no. 1?

@Toflar
Copy link
Member Author

Toflar commented Oct 15, 2015

👍 for 1.

leofeyer added a commit to contao/core-bundle that referenced this issue Oct 15, 2015
@leofeyer leofeyer added feature and removed defect labels Oct 15, 2015
@leofeyer leofeyer modified the milestones: 4.1.0, 3.5.5 Oct 15, 2015
@leofeyer leofeyer self-assigned this Oct 15, 2015
@leofeyer
Copy link
Member

Changed in contao/core-bundle@dcb46f3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants