Giter Club home page Giter Club logo

openmage-image-cleaner's Introduction

openmage-image-cleaner's People

Contributors

fballiano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

luizsantos1

openmage-image-cleaner's Issues

Action Names - suggestion

Here is a suggestion for button actions:

Sync Categories
Sync Products
Sync WYSIWYG
Flush /media/tmp
Reset IC Table

We reduce the space by removing Images word. The last button name should explain what is doing as action. Reset was a generic name.

New feature cleaning up /media/tmp directory

When someone uploads an image first time it goes to /media/tmp/catalog/product directory. After pressing the [Save] button the file goes to /media/catalog/product directory then it is deleted from /tmp. Over the time there are still a lot of files in /media/tmp without any reason. What about including this directory in our clean up process? By filtering on a column we can get where is the file stored.

I did not check if for categories is the same pattern like for products (e.g. /media/tmp/catalog/category).

SQL Constraint vialoation when 2 images with same name but different capitalization are present

First: thanks for the tool, really helpful.

I had a case where /f/o/foo_bar.jpg and /f/o/foo_Bar.jpg were lying around and got an sql constraint vialoation error despite it being two different files that should have been picked up.
I suspect that using utf8 as collation could fix the issue (https://stackoverflow.com/questions/6448825/sql-unique-varchar-case-sensitivity-question) but I have not tested it yet.

Improvements to Image Column

First one
Having a Download link there is no need to keep an tag on image. In this way by clicking on the image we can select the whole row without having an discontinuance.

I suggest in /Block/Adminhtml/Fbimagecleaner/Renderer/Image.php the following change in line 41 from this:

return "<a href='{$url}{$row->getPath()}' target='_blank'><img src='{$url}{$row->getPath()}' style='max-width: 200px' /></a>";

to

return "<img src='{$url}{$row->getPath()}' style='max-width: 200px' />";

Second one
Remove the filter for this column. It doesn't help since we can do this on the File Name column. In file /Block/Adminhtml/Fbimagecleaner/Grid.php line 70:

        $this->addColumn('image', array(
            'header' => $this->__('Image'),
            'type' => 'text',
            'width' => '250px',
            'align'=> 'center',
            'filter'=> false,
            'index' => 'path',
            'sortable' => false,
            'is_system' => true,
            'renderer' => 'Fballiano_ImageCleaner_Block_Adminhtml_Fbimagecleaner_Renderer_Image',
        ));

error in sync products cache

I have executed the following steps in this order:

  • Sync product cache
  • Sync categories
  • Sync products cache

The last step of synchronizing the products cache returned this error:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '-4-1/image/600x/17f82f742ffe127f42dca9de82fb58b1/l/e/letto-matri' for key 'entity_type_id', query was: INSERT INTO `fb_imagecleaner_image` (`entity_type_id`, `path`) VALUES (?, ?)
#0 /var/www/xxxxxxx/htdocs/lib/Varien/Db/Statement/Pdo/Mysql.php(104): Zend_Db_Statement_Pdo->_execute()
#1 /var/www/xxxxxxx/htdocs/app/code/core/Zend/Db/Statement.php(289): Varien_Db_Statement_Pdo_Mysql->_execute()
#2 /var/www/xxxxxxx/htdocs/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute()
#3 /var/www/xxxxxxx/htdocs/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query()
#4 /var/www/xxxxxxx/htdocs/lib/Varien/Db/Adapter/Pdo/Mysql.php(492): Zend_Db_Adapter_Pdo_Abstract->query()
#5 /var/www/xxxxxxx/htdocs/lib/Zend/Db/Adapter/Abstract.php(576): Varien_Db_Adapter_Pdo_Mysql->query()
#6 /var/www/xxxxxxx/htdocs/.modman/openmage-image-cleaner/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php(164): Zend_Db_Adapter_Abstract->insert()
#7 /var/www/xxxxxxx/htdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(428): Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController->syncproductCacheAction()
#8 /var/www/xxxxxxx/htdocs/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(262): Mage_Core_Controller_Varien_Action->dispatch()
#9 /var/www/xxxxxxx/htdocs/app/code/core/Mage/Core/Controller/Varien/Front.php(188): Mage_Core_Controller_Varien_Router_Standard->match()
#10 /var/www/xxxxxxx/htdocs/app/code/core/Mage/Core/Model/App.php(371): Mage_Core_Controller_Varien_Front->dispatch()
#11 /var/www/xxxxxxx/htdocs/app/Mage.php(735): Mage_Core_Model_App->run()
#12 /var/www/xxxxxxx/htdocs/index.php(83): Mage::run()

there is no entry in fb_imagecleaner_image table with this path value (maybe in the stack trace is truncated?):
image/600x/17f82f742ffe127f42dca9de82fb58b1/l/e/letto-matri

i have this contains:
contains

php 7.4
openmage 19.4.21

Open image in a new window

Now that we have more configuration options in Backend by adding the size of the image and the blacklist, I propose to add another option, whether clicking on the image opens or not in a new window.

Basically we add a new option in /etc/system.xml and change the code in /Block/Adminhtml/Fbimagecleaner/Renderer/image.php to line 41.

return "<a href='{$url}{$row->getPath()}' target='_blank'><img src='{$url}{$row->getPath()}' style='max-width:{$max_width}px' /></a>";

Export to CSV/Excel XML

screenshot

There are no actions created for this feature (exportCSV, exportExcel). It should be disabled until the actions are created.

Color Swatches feature?

What do you thing about adding Color Swatches in the list for removing the orphan images?

Orphan images after importing process

If you import a CSV file to create/update products and if this file contains columns related to images like _media_attribute_id, _media_image, _media_lable, _media_position, _media_is_disabled then you have to place the images in /media/import directory.

After the import process is done successfully the files from /media/import go to /media/catalog/product but they are not deleted from the initial location remaining there as orphans.

Please take this in consideration as a new feature to your extension.

Small Improvements

First Change
Do we need the ID column? Let's say we note the ID's for some images we want to select and delete. But we can do the same thing using file name which is more intuitive for a human without noting too many information on a paper.

Second Change
200px for the image size is too big and a scrolling efforts is needed. I recommend 100px.

Third Changes

  • I would suggest adding a header for the last column at the right named Action. We keep the same format like in other sections in Magento.
  • Instead of adding a link on the image and open it in a new window you could insert on column Action, bellow Delete link a new link named Save. It is more elegant and intuitive. See bellow

snip

Set auto_increment to 1 after truncating the table

Here is the code from ImaClean for resetting the table:

        $model = Mage::getModel('defcon2imaclean/imaclean');

        $resource = $model->getResource();
        $connection = $resource->getReadConnection();
        $connection->truncateTable($resource->getMainTable());
        $connection->changeTableAutoIncrement($resource->getMainTable(), 1);

Please set auto_increment value to 1 after truncating the table.

Sync grid when there is no directory

If any of these do not exist

/media/catalog/folder
/media/catalog/product
/media/wysiwyg

but there are results in grid you should sync the results by removing from database table those related to category/product/wysiwyg. Otherwise you will get errors.

To reproduce this issue go to Magento Backend and fill the grid with results by pressing any of the Sync buttons (e.g. category). Then go to the file system and change the category directory name. Press again [Sync Category Images] button and nothing will change. If you select multiple images or individuals and give any action like Mass Delete, Download, Delete you will get the following errors:

Mass Delete, Delete:

Warning: unlink(/home/mydomain/public_html/media/catalog/category/adventure-food-1p-brown-bean-soup-pouch.jpg): No such file or directory  in /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php on line 185

#0 [internal function]: mageCoreErrorHandler(2, 'unlink(/home/mm...', '/home/mydomain/p...', 185, Array)
#1 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php(185): unlink('/home/mydomain/p...')
#2 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(437): Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController->deleteAction()
#3 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(262): Mage_Core_Controller_Varien_Action->dispatch('delete')
#4 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(192): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#5 /home/mydomain/public_html/app/code/core/Mage/Core/Model/App.php(381): Mage_Core_Controller_Varien_Front->dispatch()
#6 /home/mydomain/public_html/app/Mage.php(729): Mage_Core_Model_App->run(Array)
#7 /home/mydomain/public_html/index.php(78): Mage::run('', 'store')
#8 {main}

Download:

Warning: file_get_contents(/home/mydomain/public_html/media/catalog/category/adventure-food-1p-brown-bean-soup-pouch.jpg): failed to open stream: No such file or directory  in /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php on line 223

#0 [internal function]: mageCoreErrorHandler(2, 'file_get_conten...', '/home/mydomain/p...', 223, Array)
#1 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php(223): file_get_contents('/home/mydomain/p...')
#2 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(437): Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController->downloadAction()
#3 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(262): Mage_Core_Controller_Varien_Action->dispatch('download')
#4 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(192): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#5 /home/mydomain/public_html/app/code/core/Mage/Core/Model/App.php(381): Mage_Core_Controller_Varien_Front->dispatch()
#6 /home/mydomain/public_html/app/Mage.php(729): Mage_Core_Model_App->run(Array)
#7 /home/mydomain/public_html/index.php(78): Mage::run('', 'store')
#8 {main}

As a fix I see as follows when you click on a Sync button first all records from database tables related to that action (category/product/wysiwyg) should be removed. If the folder exists fill the table with results else show the error message.

Delete Link

ask_delete

Please ask the user before deleting an individual image. "Are you sure?". Once someone is pressing Delete the file is gone forever.

Center ID column

I did a small change to center the ID column. It looks better now, because Entity Type is centered too.

/app/code/community/Fballiano/ImageCleaner/Block/Adminhtml/Fbimagecleaner/Grid.php

    protected function _prepareColumns()
    {
        $this->addColumn('image_id', array(
            'header' => $this->__('ID'),
            'type' => 'text',
            'width' => '100px',
            'align'=> 'center',
            'index' => 'image_id'
        ));

Sync Category/Product Images

Here are the steps to reproduce this issue.

Go to /media/catalog folder and delete category folder. The idea is not having this folder. Now press on [Sync Category Images] button. Browser page reloads with the warning bellow:

Warning: scandir(/home/mydomain/public_html/media/catalog/category): failed to open dir: No such file or directory  in /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php on line 49

#0 [internal function]: mageCoreErrorHandler(2, 'scandir(/home/m...', '/home/mydomain/p...', 49, Array)
#1 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php(49): scandir('/home/mydomain/p...')
#2 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(437): Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController->synccategoryAction()
#3 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(262): Mage_Core_Controller_Varien_Action->dispatch('synccategory')
#4 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(192): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#5 /home/mydomain/public_html/app/code/core/Mage/Core/Model/App.php(381): Mage_Core_Controller_Varien_Front->dispatch()
#6 /home/mydomain/public_html/app/Mage.php(729): Mage_Core_Model_App->run(Array)
#7 /home/mydomain/public_html/index.php(78): Mage::run('', 'store')
#8 {main}

A small change in the script is needed if folder /media/catalog/category doesn't exist. This should be done also for other folders that the extension is using like /media/catalog/product. By pressing the buttons it will be no warnings in pages.

Image Cleaner name

I suggest in Tools menu and the grid page the following name from "Image Cleaner" to "Orphan Images Cleaner". It is closer to the purpose of this extension, not giving the impression that it would be a utility for deleting all kind of images.

I did the changes in the following files:

/etc/adminhtml.xml
/Block/Adminthml/Image.php
/controllers/Adminhtml/FbimagecleanerController.php

Sync WYSIWYG Button

I changed the name for [Sync WYSIWYG] button to [Sync WYSIWYG Images] to keep the same format with the other buttons. It is a harmless change that points only to the artistic impression :)

Sync WYSIWYG

I pushed [Sync WYSIWYG] button and the page loaded with the following warning:

Warning: scandir(/home/mydomain/public_html/skin/frontend/base/default/aw_zblocks/js/slider.js): failed to open dir: Not a directory  in /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php on line 66

#0 [internal function]: mageCoreErrorHandler(2, 'scandir(/home/m...', '/home/mydomain/p...', 66, Array)
#1 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(66): scandir('/home/mydomain/p...')
#2 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#3 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#4 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#5 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#6 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#7 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(56): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#8 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php(117): Fballiano_ImageCleaner_Helper_Data->getAllCSSFilesContents()
#9 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(437): Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController->syncwysiwygAction()
#10 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(262): Mage_Core_Controller_Varien_Action->dispatch('syncwysiwyg')
#11 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(192): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#12 /home/mydomain/public_html/app/code/core/Mage/Core/Model/App.php(381): Mage_Core_Controller_Varien_Front->dispatch()
#13 /home/mydomain/public_html/app/Mage.php(729): Mage_Core_Model_App->run(Array)
#14 /home/mydomain/public_html/index.php(78): Mage::run('', 'store')
#15 {main}

This path /home/mydomain/public_html/skin/frontend/base/default/aw_zblocks/js/slider.js exits and the file has the right permissions.

I deleted this file and reload the page. A new warning was generated:

Warning: scandir(/home/mydomain/public_html/skin/frontend/base/default/favicon.ico): failed to open dir: Not a directory  in /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php on line 66

#0 [internal function]: mageCoreErrorHandler(2, 'scandir(/home/m...', '/home/mydomain/p...', 66, Array)
#1 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(66): scandir('/home/mydomain/p...')
#2 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#3 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#4 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#5 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(56): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#6 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php(117): Fballiano_ImageCleaner_Helper_Data->getAllCSSFilesContents()
#7 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(437): Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController->syncwysiwygAction()
#8 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(262): Mage_Core_Controller_Varien_Action->dispatch('syncwysiwyg')
#9 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(192): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#10 /home/mydomain/public_html/app/code/core/Mage/Core/Model/App.php(381): Mage_Core_Controller_Varien_Front->dispatch()
#11 /home/mydomain/public_html/app/Mage.php(729): Mage_Core_Model_App->run(Array)
#12 /home/mydomain/public_html/index.php(78): Mage::run('', 'store')
#13 {main}

I removed one by one all the files reported in warnings. Now here is the final warning:

Notice: Undefined variable: result  in /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php on line 79

#0 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(79): mageCoreErrorHandler(8, 'Undefined varia...', '/home/mydomain/p...', 79, Array)
#1 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#2 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#3 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#4 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(74): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#5 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/Helper/Data.php(56): Fballiano_ImageCleaner_Helper_Data->getAllCSSFiles('/home/mydomain/p...')
#6 /home/mydomain/public_html/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php(117): Fballiano_ImageCleaner_Helper_Data->getAllCSSFilesContents()
#7 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(437): Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController->syncwysiwygAction()
#8 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(262): Mage_Core_Controller_Varien_Action->dispatch('syncwysiwyg')
#9 /home/mydomain/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(192): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#10 /home/mydomain/public_html/app/code/core/Mage/Core/Model/App.php(381): Mage_Core_Controller_Varien_Front->dispatch()
#11 /home/mydomain/public_html/app/Mage.php(729): Mage_Core_Model_App->run(Array)
#12 /home/mydomain/public_html/index.php(78): Mage::run('', 'store')
#13 {main}

As I understand this feature Sync WYSIWYG should check /media/wysiwyg folder and if it finds an image not used in any place will report it. But as you may see the extension is looking in other folders as reported before.

As a personal opinion this feature should be removed because the images from /media/wysiwyg are very hard to be identified where they are used. They could be in many places like CMS pages, Blocks, Product Description.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.