Skip to content

Database Media Storage : Fixed error in database deleteFolder function. Now correctly deletes folder #24088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2019

Conversation

gwharton
Copy link
Contributor

@gwharton gwharton commented Aug 9, 2019

Description (*)

The Magento implementation of the deleteFolder function in MediaStorage's resource model for the database is broken.

Currently the delete command for $folder is

"delete from media_storage_file_storage WHERE filename LIKE $folder/%"

Unfortunately entries in the media_storage_file_storage table have entries with directory and filename as separate entries, hence the above will never work.

The query needs to be

"delete from media_storage_file_storage WHERE directory LIKE $folder/% OR directory=$folder"

Thus it will delete any entries where the file is in $folder, and also delete any files in any subdirectories of $folder.

This is the correct behaviour, and this is what this PR implements.

Fixed Issues (if relevant)

  1. Database Media Storage : clearing image cache does not clear cached image files from database #23936: Database Media Storage : clearing image cache does not clear cached image files from database

Manual testing scenarios (*)

Deploy 2.3-develop

Stores -> Configuration
    Advanced -> System
        Storage Configuration for Media
            Media Storage = Database
            Select Media Database = default_setup
            Synchronize
            Save Config
Catalog -> Products
    Add Product
        Name = Test
        Price = 111
        Images and Videos
            Upload image "a.jpg"
        Save & Close

Verify cached images exist in filesystem

www-data@dev:~/dev1$ find pub/media/catalog/product/cache -name *.jpg
pub/media/catalog/product/cache/6e14adab429f71aeb7223303a247c563/a/_/a.jpg
pub/media/catalog/product/cache/f62d29ead3f33fe6484fbdb6d3785dc1/a/_/a.jpg
pub/media/catalog/product/cache/be852cb44d0b54faab62ffaae6be8535/a/_/a.jpg
pub/media/catalog/product/cache/cec7ecf00f20929af760713af4400fed/a/_/a.jpg
pub/media/catalog/product/cache/37bfafdfb226dffa175577a00672b1ba/a/_/a.jpg
pub/media/catalog/product/cache/8b2dc6afd39ee28ff58514eb10993c8f/a/_/a.jpg
pub/media/catalog/product/cache/d975e82a925000253a32e9c4541ea68c/a/_/a.jpg
pub/media/catalog/product/cache/09c5a17c8da4235f70a8c07e75bb5ef0/a/_/a.jpg
pub/media/catalog/product/cache/9fda6c6842c3f655bbb560bcbe7ed6d5/a/_/a.jpg
pub/media/catalog/product/cache/d5f386a768d7e7f87cc4fb8a6c1ef14f/a/_/a.jpg
pub/media/catalog/product/cache/52952a29dad7e0f0b516b44cc9fe0760/a/_/a.jpg
pub/media/catalog/product/cache/06dfa18d55e0337076e1f5ddd2129562/a/_/a.jpg
pub/media/catalog/product/cache/faa05d146573dd135d15c4c56517ffdb/a/_/a.jpg
pub/media/catalog/product/cache/3ced2c8980660288e4ea38fe4970b4e9/a/_/a.jpg
pub/media/catalog/product/cache/2bdb51d37a492679108b7c6c17f34e97/a/_/a.jpg
pub/media/catalog/product/cache/4ed1686d54d03efa60ce0fb8e68e54e9/a/_/a.jpg
pub/media/catalog/product/cache/ee5242f5f0a2a47237a7610f0274bc15/a/_/a.jpg
pub/media/catalog/product/cache/8f18f3a902701264b776ead80189598e/a/_/a.jpg
pub/media/catalog/product/cache/39fe0b11cb432d7c2d562e3c5b5d5f43/a/_/a.jpg
pub/media/catalog/product/cache/34c2321368257a27e78b60f1cf77ce60/a/_/a.jpg
www-data@dev:~/dev1$

Verify cached images exist in database

mysql> mysql> select filename,directory from media_storage_file_storage where directory LIKE 'catalog/product/cache%';
+----------+------------------------------------------------------------+
| filename | directory                                                  |
+----------+------------------------------------------------------------+
| a.jpg    | catalog/product/cache/9fda6c6842c3f655bbb560bcbe7ed6d5/a/_ |
| a.jpg    | catalog/product/cache/f62d29ead3f33fe6484fbdb6d3785dc1/a/_ |
| a.jpg    | catalog/product/cache/d5f386a768d7e7f87cc4fb8a6c1ef14f/a/_ |
| a.jpg    | catalog/product/cache/52952a29dad7e0f0b516b44cc9fe0760/a/_ |
| a.jpg    | catalog/product/cache/ee5242f5f0a2a47237a7610f0274bc15/a/_ |
| a.jpg    | catalog/product/cache/cec7ecf00f20929af760713af4400fed/a/_ |
| a.jpg    | catalog/product/cache/09c5a17c8da4235f70a8c07e75bb5ef0/a/_ |
| a.jpg    | catalog/product/cache/39fe0b11cb432d7c2d562e3c5b5d5f43/a/_ |
| a.jpg    | catalog/product/cache/3ced2c8980660288e4ea38fe4970b4e9/a/_ |
| a.jpg    | catalog/product/cache/8f18f3a902701264b776ead80189598e/a/_ |
| a.jpg    | catalog/product/cache/06dfa18d55e0337076e1f5ddd2129562/a/_ |
| a.jpg    | catalog/product/cache/34c2321368257a27e78b60f1cf77ce60/a/_ |
| a.jpg    | catalog/product/cache/37bfafdfb226dffa175577a00672b1ba/a/_ |
| a.jpg    | catalog/product/cache/be852cb44d0b54faab62ffaae6be8535/a/_ |
| a.jpg    | catalog/product/cache/4ed1686d54d03efa60ce0fb8e68e54e9/a/_ |
| a.jpg    | catalog/product/cache/2bdb51d37a492679108b7c6c17f34e97/a/_ |
| a.jpg    | catalog/product/cache/d975e82a925000253a32e9c4541ea68c/a/_ |
| a.jpg    | catalog/product/cache/6e14adab429f71aeb7223303a247c563/a/_ |
| a.jpg    | catalog/product/cache/faa05d146573dd135d15c4c56517ffdb/a/_ |
| a.jpg    | catalog/product/cache/8b2dc6afd39ee28ff58514eb10993c8f/a/_ |
+----------+------------------------------------------------------------+
20 rows in set (0.00 sec)

mysql>
System -> Cache Management
    Flush Catalog Images Cache

Verify cached images no longer exist in filesystem

www-data@dev:~/dev1$ find pub/media/catalog/product/cache -name *.jpg
find: ‘pub/media/catalog/product/cache’: No such file or directory
www-data@dev:~/dev1$

Verify cached images no longer exist in database

mysql> select filename,directory from media_storage_file_storage where directory LIKE 'catalog/product/cache%';
Empty set (0.00 sec)

mysql>

When the image cache is cleared, all cached images are removed from filesystem and database

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Aug 9, 2019

Hi @gwharton. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Aug 9, 2019

CLA assistant check
All committers have signed the CLA.

@ghost ghost assigned ihor-sviziev Aug 9, 2019
@ihor-sviziev ihor-sviziev added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Progress: ready for testing labels Aug 9, 2019
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-5573 has been created to process this Pull Request

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

@m2-assistant
Copy link

m2-assistant bot commented Aug 14, 2019

Hi @gwharton, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@gwharton gwharton deleted the 2.3-develop-clearimagecache branch August 15, 2019 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants