Skip to content

[CE 2.1.0] Fatal issue on BO edit page if a media has been directly deleted on the server #5871

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

Closed
spipu opened this issue Jul 28, 2016 · 6 comments
Assignees
Labels
bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@spipu
Copy link

spipu commented Jul 28, 2016

Hi,

The steps are :

  • Create a product and add a media in the "Images and Videos" tab.
  • Go on the product view page in BO : it works
  • Delete the image directly on the server to simulate a accidental lost of data
  • Go on the product view page in BO : the following error occurs without the possibility to edit the product :

Cannot gather stats! Warning!stat(): stat failed for /var/www/xxxx/pub/media/catalog/product/w/s/ws02-green_main.jpg

It is because there is no protection here:

https://github.com/magento/magento2/blob/2.1/app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php#L135

I think it could be a good think to do something like this :

    public function getImagesJson()
    {
        $value = $this->getElement()->getImages();
        if (is_array($value) &&
            array_key_exists('images', $value) &&
            is_array($value['images']) &&
            count($value['images'])
        ) {
            $directory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
            $images = $this->sortImagesByPosition($value['images']);
            foreach ($images as &$image) {
                $image['url'] = $this->_mediaConfig->getMediaUrl($image['file']);
                try {
                    $fileHandler = $directory->stat($this->_mediaConfig->getMediaPath($image['file']));
                    $image['size'] = $fileHandler['size'];
                } catch (\Exception $e) {
                    $image['size'] = 0;
                    // @todo add some log
                }
            }
            return $this->_jsonEncoder->encode($images);
        }
        return '[]';
    }
@erikhansen
Copy link
Contributor

I'm seeing the same issue on 2.1.

@pboisvert
Copy link

Anton--can you take a look at this? While marked as "improvement" i think the impact here feels like a bug in terms of missing protection from scenario of one or more product images being deleted from the server. We must fix to ensure product edit page still available.

@antboiko antboiko added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report and removed improvement TECH labels Aug 18, 2016
@antboiko
Copy link

Hi @spipu , thanks for reporting. We already have internal ticket MAGETWO-54718 for fixing this issue and we're working on it.

Best
Anton.

mmansoor-magento pushed a commit that referenced this issue Sep 2, 2016
[EAST] MAGETWO-54718: [GitHub] Exception thrown where no Product Image file found #5184 #5497 #5871
@KevinMace
Copy link
Member

I'm seeing the same issue on 2.1.1 EE

@spipu spipu closed this as completed Dec 9, 2016
okorshenko pushed a commit that referenced this issue Dec 14, 2016
- MAGETWO-54718: [GitHub] Exception thrown where no Product Image file found #5184 #5497 #5871

- (cherry picked from commit 1ef843d)
okorshenko pushed a commit that referenced this issue Dec 14, 2016
- MAGETWO-54718: [GitHub] Exception thrown where no Product Image file found #5184 #5497 #5871

- (cherry picked from commit 2240a1e)
okorshenko pushed a commit that referenced this issue Dec 14, 2016
- MAGETWO-54718: [GitHub] Exception thrown where no Product Image file found #5184 #5497 #5871

- (cherry picked from commit da52cad)
okorshenko pushed a commit that referenced this issue Dec 14, 2016
- MAGETWO-54718: [GitHub] Exception thrown where no Product Image file found #5184 #5497 #5871

- (cherry picked from commit 0bad8ab)
@elenleonova
Copy link

The issue has been delivered to 2.1.3

@spipu
Copy link
Author

spipu commented May 12, 2017

tested, ok

pdohogne-magento pushed a commit that referenced this issue Jul 28, 2020
[pangolin] deliver MFTF 3.0.0 to 2.4.0-develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests

7 participants