Previews are not deleted
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Previews are not deleted
Hi community)
I use the next controller for my needs and when I call delete method previews files are not deleted, but main file is deleted.
take a look, there is !strcmp( $preview, $mimedir ) in the condition. As I know it will return true only if strings are the same.
But in my case $preview is 'preview/4/e/4ef58950ec3a7545446021f13fa419e4.jpg'
and $mimedir is 'packages/aimeos/shop/mimeicons'.
I don't understand why there is strcmp.
Please make this moment clear for me. Maybe I did something wrong, or I need overwrite delete method and remove strcmp from there..
I use the next controller for my needs and when I call delete method previews files are not deleted, but main file is deleted.
Code: Select all
https://github.com/aimeos/aimeos-core/blob/master/controller/common/src/Controller/Common/Media/Standard.php#L147
But in my case $preview is 'preview/4/e/4ef58950ec3a7545446021f13fa419e4.jpg'
and $mimedir is 'packages/aimeos/shop/mimeicons'.
I don't understand why there is strcmp.
Please make this moment clear for me. Maybe I did something wrong, or I need overwrite delete method and remove strcmp from there..
Re: Previews are not deleted
You mean here: https://github.com/aimeos/aimeos-core/b ... d.php#L147
strcmp() return 0 if both string are equal and -1/+1 if they are different, so "!strcmp()" returns true if strings are different. The reason why the previews aren't deleted must be somewhere else.
strcmp() return 0 if both string are equal and -1/+1 if they are different, so "!strcmp()" returns true if strings are different. The reason why the previews aren't deleted must be somewhere else.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: Previews are not deleted
Hah.. strange thing.
I have added some code to debug:
This is the output:
Strings are different! if you run in php console var_dump(!-1) - it returns false ))
I have added some code to debug:
Code: Select all
dump($preview);
dump($mimedir);
dump(!strcmp( $preview, $mimedir ));
dd($fs->has( $preview ));
try
{
if( $preview !== '' && !strcmp( $preview, $mimedir ) && $fs->has( $preview ) ) {
$fs->rm( $preview );
}
}
catch( \Exception $e ) { ; } // continue if removing file fails
Code: Select all
"preview/4/e/4ef58950ec3a7545446021f13fa419e4.jpg"
"packages/aimeos/shop/mimeicons"
false
true
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: Previews are not deleted
it is surprise from PHP (bool) -1 = true ))
Re: Previews are not deleted
I think, "!strcmp()" is wrong, it should be "strcmp()" only (without exclamation mark).
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: Previews are not deleted
Yes, will you fix it in future ?) for now I will fix it for myself with extending class.
Also let me ask you something else. Files stored like this folder structure: files->3->6->file.img. Can we delete 3 and 6 folders also when we delete file ? I don't want to have a lot of empty folders. As I know it is not implemented in aimeos, is it good idea if I implement this folder deletion ?
Also let me ask you something else. Files stored like this folder structure: files->3->6->file.img. Can we delete 3 and 6 folders also when we delete file ? I don't want to have a lot of empty folders. As I know it is not implemented in aimeos, is it good idea if I implement this folder deletion ?
Re: Previews are not deleted
Yes, but I think the really correct form would be:MikaelNazarenko wrote: ↑06 Dec 2019, 12:15 Yes, will you fix it in future ?) for now I will fix it for myself with extending class.
Code: Select all
strncmp( $preview, $mimedir, strlen($mimedir) )
You would have to check if there are more files or folders in the current one. As storage operations are costly and not all storages support folders or retrieving entries of a folder (e.g. AWS S3), I think it's acceptable to have max 16x16=256 folders even if some are empty when you delete files.MikaelNazarenko wrote: ↑06 Dec 2019, 12:15 Also let me ask you something else. Files stored like this folder structure: files->3->6->file.img. Can we delete 3 and 6 folders also when we delete file ? I don't want to have a lot of empty folders. As I know it is not implemented in aimeos, is it good idea if I implement this folder deletion ?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: Previews are not deleted
Thank you for the clarification! But where did you get this calculation 16x16=256 ? Is this from the code and it means that files storage logic built such way that it will keep maximum 256 folders ?
Re: Previews are not deleted
Folder names use the first two characters of the file name. As the file names are hex-encoded MD5 strings, you have 16 characters 0-9,a,b,c,d,e,f -> 16 folders x 16 subfolders each = 256 folders in total. More are not possible.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star