├── modman ├── app ├── etc │ └── modules │ │ └── Defcon2_Imaclean.xml └── code │ └── community │ └── Defcon2 │ └── Imaclean │ ├── Model │ ├── Imaclean.php │ ├── Mysql4 │ │ ├── Imaclean.php │ │ └── Imaclean │ │ │ └── Collection.php │ └── Status.php │ ├── controllers │ ├── IndexController.php │ └── Adminhtml │ │ └── ImacleanController.php │ ├── sql │ └── defcon2imaclean_setup │ │ ├── mysql4-upgrade-1.0.0-1.0.1.php │ │ └── mysql4-install-1.0.0.php │ ├── Block │ ├── Imaclean.php │ └── Adminhtml │ │ ├── Imaclean.php │ │ ├── Renderer │ │ └── Image.php │ │ └── Imaclean │ │ └── Grid.php │ ├── etc │ ├── adminhtml.xml │ └── config.xml │ └── Helper │ └── Data.php ├── composer.json └── README.md /modman: -------------------------------------------------------------------------------- 1 | app/code/community/Defcon2/Imaclean app/code/community/Defcon2/Imaclean 2 | app/etc/modules/Defcon2_Imaclean.xml app/etc/modules/Defcon2_Imaclean.xml 3 | -------------------------------------------------------------------------------- /app/etc/modules/Defcon2_Imaclean.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | true 16 | community 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/Model/Imaclean.php: -------------------------------------------------------------------------------- 1 | _init('defcon2imaclean/imaclean'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/controllers/IndexController.php: -------------------------------------------------------------------------------- 1 | loadLayout(); 16 | $this->renderLayout(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "defcon2/imaclean", 3 | "type": "magento-module", 4 | "description": "This extension allows to list all the product images that already are not in use and to erase them.", 5 | "homepage": "https://www.magentocommerce.com/magento-connect/image-clean.html", 6 | "license": "OSL-3.0", 7 | "require": { 8 | "magento-hackathon/magento-composer-installer": "*" 9 | }, 10 | "authors": [ 11 | { 12 | "name": "Manuel Canepa", 13 | "email": "manuelcanepa@gmail.com", 14 | "role": "Author/Maintainer" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/sql/defcon2imaclean_setup/mysql4-upgrade-1.0.0-1.0.1.php: -------------------------------------------------------------------------------- 1 | startSetup(); 14 | 15 | $installer->run("ALTER TABLE {$this->getTable('imaclean')} CHANGE `filename` `filename` VARCHAR(255) CHARSET utf8 COLLATE utf8_bin DEFAULT '' NOT NULL"); 16 | 17 | $installer->endSetup(); 18 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/Model/Mysql4/Imaclean.php: -------------------------------------------------------------------------------- 1 | _init('defcon2imaclean/imaclean', 'imaclean_id'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/Model/Status.php: -------------------------------------------------------------------------------- 1 | Mage::helper('defcon2imaclean')->__('Enabled'), 20 | self::STATUS_DISABLED => Mage::helper('defcon2imaclean')->__('Disabled') 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/Block/Imaclean.php: -------------------------------------------------------------------------------- 1 | hasData('imaclean')) { 21 | $this->setData('imaclean', Mage::registry('imaclean')); 22 | } 23 | return $this->getData('imaclean'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/Block/Adminhtml/Imaclean.php: -------------------------------------------------------------------------------- 1 | _controller = 'adminhtml_imaclean'; 16 | $this->_blockGroup = 'defcon2imaclean'; 17 | $this->_headerText = Mage::helper('defcon2imaclean')->__('Items Manager. These files are not in database.'); 18 | $this->_addButtonLabel = Mage::helper('defcon2imaclean')->__('Refresh'); 19 | parent::__construct(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | After comments at https://github.com/OpenMage/magento-lts/issues/1475 i'll archive this in favor of https://github.com/fballiano/magento1-image-cleaner. 4 | 5 | # Magento: Image Clean 6 | 7 | This estension lists all the product images that they find in the directory "media/catalog/product" and that they do not in the database. It allows to select and to erase these files 8 | 9 | ## Compatible with: 10 | - 1.0 11 | - 1.1 12 | - 1.2 13 | - 1.3 14 | - 1.4 15 | - 1.4.1.1 16 | - 1.4.2 17 | - 1.5 18 | - 1.6 19 | - 1.6.1 20 | - 1.6.2.0 21 | - 1.7 22 | - 1.8 23 | - 1.8.1 24 | - 1.9 25 | - 1.9.1 26 | - 1.9.2 27 | 28 | ## Magento Connect: 29 | https://www.magentocommerce.com/magento-connect/image-clean.html 30 | 31 | ## Installation: 32 | 33 | ### Via modman 34 | ``` 35 | modman clone https://github.com/sreichel/magento-Defcon2-Imaclean.git 36 | ``` 37 | ### Via composer: 38 | ``` 39 | { 40 | "require": { 41 | "defcon2/imaclean": "*", 42 | }, 43 | "repositories": [ 44 | { 45 | "type": "vcs", 46 | "url": "https://github.com/sreichel/magento-Defcon2-Imaclean.git" 47 | } 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/etc/adminhtml.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | ImaClean 18 | adminhtml/imaclean 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | ImaClean 31 | 0 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/Model/Mysql4/Imaclean/Collection.php: -------------------------------------------------------------------------------- 1 | _init('defcon2imaclean/imaclean'); 19 | } 20 | 21 | /** 22 | * trae imagenes que estan guardadas en la base de datos... 23 | */ 24 | public function getImages() 25 | { 26 | try { 27 | $this->setConnection($this->getResource()->getReadConnection()); 28 | $this->getSelect() 29 | ->from(array('main_table' => $this->getTable('catalog/product_attribute_media_gallery')), 'value') 30 | ->group(array('value_id')); 31 | 32 | $images = array_unique($this->getColumnValues('value')); 33 | } catch (Exception $e) { 34 | Mage::log($e->getMessage()); 35 | } 36 | 37 | return $images; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/sql/defcon2imaclean_setup/mysql4-install-1.0.0.php: -------------------------------------------------------------------------------- 1 | startSetup(); 14 | 15 | $installer->run(" 16 | CREATE TABLE IF NOT EXISTS {$this->getTable('imaclean')} ( 17 | `imaclean_id` int(11) unsigned NOT NULL auto_increment, 18 | `filename` varchar(255) NOT NULL default '', 19 | PRIMARY KEY (`imaclean_id`), 20 | UNIQUE KEY `filename` (`filename`) 21 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 22 | "); 23 | 24 | $oldDir = Mage::getModuleDir('', 'Mage_Imaclean'); 25 | if (file_exists($oldDir)) { 26 | $etcFile = Mage::getBaseDir('etc') . DS . 'modules' . DS . 'Mage_Imaclean.xml'; 27 | if (file_exists($etcFile) && is_file($etcFile)) { 28 | if (unlink($etcFile)) { 29 | unlink(Mage::getBaseDir('design') . DS . 'adminhtml' . DS . 'default' . DS . 'default' . DS . 'layout' . DS . 'imaclean.xml'); 30 | Varien_Io_File::rmdirRecursive($oldDir); 31 | $installer->run("DELETE FROM {$this->getTable('core_resource')} WHERE `code` = 'imaclean_setup'"); 32 | } 33 | } 34 | } 35 | $installer->endSetup(); 36 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/Block/Adminhtml/Renderer/Image.php: -------------------------------------------------------------------------------- 1 | getColumn()->getFormat() ) ? $this->getColumn()->getFormat() : null; 31 | $defaultValue = $this->getColumn()->getDefault(); 32 | if (is_null($format)) { 33 | // If no format and it column not filtered specified return data as is. 34 | $data = parent::_getValue($row); 35 | $string = is_null($data) ? $defaultValue : $data; 36 | $url = htmlspecialchars($string); 37 | } elseif (preg_match_all($this->_variablePattern, $format, $matches)) { 38 | // Parsing of format string 39 | $formatedString = $format; 40 | foreach ($matches[0] as $matchIndex => $match) { 41 | $value = $row->getData($matches[1][$matchIndex]); 42 | $formatedString = str_replace($match, $value, $formatedString); 43 | } 44 | $url = $formatedString; 45 | } else { 46 | $url = htmlspecialchars($format); 47 | } 48 | 49 | $location = Mage::getStoreConfig('web/secure/base_url'); 50 | return "{$url}"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/Helper/Data.php: -------------------------------------------------------------------------------- 1 | listDirectories($path . DS . $entry); 25 | } elseif (!in_array($entry, array('cache', 'watermark')) && (strpos($entry, '.') != 0)) { 26 | $this->result[] = substr($path . DS . $entry, 21); 27 | } 28 | } 29 | } 30 | closedir($dir); 31 | } 32 | } 33 | return $this->result; 34 | } 35 | 36 | public function compareList() 37 | { 38 | $model = Mage::getModel('defcon2imaclean/imaclean'); 39 | 40 | $resource = $model->getResource(); 41 | $connection = $resource->getReadConnection(); 42 | $connection->truncateTable($resource->getMainTable()); 43 | $connection->changeTableAutoIncrement($resource->getMainTable(), 1); 44 | 45 | $path = 'media' . DS . 'catalog' . DS . 'product'; 46 | $files = $this->listDirectories($path); 47 | 48 | $gallery = Mage::getModel('defcon2imaclean/imaclean')->getCollection()->getImages(); 49 | 50 | foreach ($files as $item) { 51 | try { 52 | $item = strtr($item, '\\', '/'); 53 | if (!in_array($item, $gallery)) { 54 | $model->setId(null); 55 | $model->setData(array('filename' => $item)); 56 | $model->save(); 57 | } 58 | } catch (Zend_Db_Exception $e) { 59 | } catch (Exception $e) { 60 | Mage::log($e->getMessage()); 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 1.2.1 16 | 17 | 18 | 19 | 20 | 21 | Defcon2_Imaclean_Model 22 | defcon2imaclean_mysql4 23 | 24 | 25 | Defcon2_Imaclean_Model_Mysql4 26 | 27 | 28 | imaclean
29 |
30 |
31 |
32 |
33 | 34 | 35 | 36 | Defcon2_Imaclean 37 | 38 | 39 | core_setup 40 | 41 | 42 | 43 | 44 | core_write 45 | 46 | 47 | 48 | 49 | core_read 50 | 51 | 52 | 53 | 54 | 55 | Defcon2_Imaclean_Block 56 | 57 | 58 | 59 | 60 | Defcon2_Imaclean_Helper 61 | 62 | 63 |
64 | 65 | 66 | 67 | 68 | 69 | Defcon2_Imaclean_Adminhtml 70 | 71 | 72 | 73 | 74 | 75 |
-------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/Block/Adminhtml/Imaclean/Grid.php: -------------------------------------------------------------------------------- 1 | setId('imacleanGrid'); 17 | $this->setDefaultSort('imaclean_id'); 18 | $this->setDefaultDir('ASC'); 19 | $this->setSaveParametersInSession(true); 20 | } 21 | 22 | // **** // trae las imagenes que no estan en base de datos... 23 | protected function _prepareCollection() 24 | { 25 | $collection = Mage::getModel('defcon2imaclean/imaclean')->getCollection(); 26 | 27 | $this->setCollection($collection); 28 | 29 | return parent::_prepareCollection(); 30 | } 31 | 32 | protected function _prepareColumns() 33 | { 34 | $this->addColumn('filename', array( 35 | 'header' => Mage::helper('defcon2imaclean')->__('Filename'), 36 | 'renderer' => 'Defcon2_Imaclean_Block_Adminhtml_Renderer_Image', 37 | 'align' => 'left', 38 | 'index' => 'filename' 39 | )); 40 | 41 | $this->addColumn( 42 | 'action', 43 | array( 44 | 'header' => Mage::helper('defcon2imaclean')->__('Action'), 45 | 'width' => '100', 46 | 'type' => 'action', 47 | 'getter' => 'getId', 48 | 'actions' => array( 49 | array( 50 | 'caption' => Mage::helper('defcon2imaclean')->__('delete'), 51 | 'url' => array('base' => '*/*/delete'), 52 | 'field' => 'id' 53 | ) 54 | ), 55 | 'filter' => false, 56 | 'sortable' => false, 57 | 'index' => 'stores', 58 | 'is_system' => true, 59 | ) 60 | ); 61 | 62 | return parent::_prepareColumns(); 63 | } 64 | 65 | protected function _prepareMassaction() 66 | { 67 | $this->setMassactionIdField('imaclean_id'); 68 | $this->getMassactionBlock()->setFormFieldName('imaclean'); 69 | 70 | $this->getMassactionBlock()->addItem('delete', array( 71 | 'label' => Mage::helper('defcon2imaclean')->__('Delete'), 72 | 'url' => $this->getUrl('*/*/massDelete'), 73 | 'confirm' => Mage::helper('defcon2imaclean')->__('Are you sure?') 74 | )); 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/code/community/Defcon2/Imaclean/controllers/Adminhtml/ImacleanController.php: -------------------------------------------------------------------------------- 1 | loadLayout() 16 | ->_setActiveMenu('defcon2imaclean/items') 17 | ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager')); 18 | 19 | return $this; 20 | } 21 | 22 | public function indexAction() 23 | { 24 | $this->loadLayout(); 25 | $this->_setActiveMenu('system/d2imaclean'); 26 | $this->_addContent($this->getLayout()->createBlock('defcon2imaclean/adminhtml_imaclean')); 27 | $this->renderLayout(); 28 | } 29 | 30 | public function newAction() 31 | { 32 | Mage::helper('defcon2imaclean')->compareList(); 33 | $this->_redirect('*/*/'); 34 | } 35 | 36 | public function deleteAction() 37 | { 38 | if ($this->getRequest()->getParam('id') > 0) { 39 | try { 40 | $model = Mage::getModel('defcon2imaclean/imaclean'); 41 | $model->load($this->getRequest()->getParam('id')); 42 | unlink('media/catalog/product' . $model->getFilename()); 43 | $model->setId($this->getRequest()->getParam('id'))->delete(); 44 | 45 | Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted')); 46 | $this->_redirect('*/*/'); 47 | } catch (Exception $e) { 48 | Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 49 | $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); 50 | } 51 | } 52 | $this->_redirect('*/*/'); 53 | } 54 | 55 | public function massDeleteAction() 56 | { 57 | $imacleanIds = $this->getRequest()->getParam('imaclean'); 58 | if (!is_array($imacleanIds)) { 59 | Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)')); 60 | } else { 61 | try { 62 | $model = Mage::getModel('defcon2imaclean/imaclean'); 63 | foreach ($imacleanIds as $imacleanId) { 64 | $model->load($imacleanId); 65 | unlink('media/catalog/product' . $model->getFilename()); 66 | $model->setId($imacleanId)->delete(); 67 | } 68 | Mage::getSingleton('adminhtml/session')->addSuccess( 69 | Mage::helper('adminhtml')->__( 70 | 'Total of %d record(s) were successfully deleted', 71 | count($imacleanIds) 72 | ) 73 | ); 74 | } catch (Exception $e) { 75 | Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 76 | } 77 | } 78 | $this->_redirect('*/*/index'); 79 | } 80 | 81 | protected function _isAllowed() 82 | { 83 | return Mage::getSingleton('admin/session')->isAllowed('system/d2imaclean'); 84 | } 85 | } 86 | --------------------------------------------------------------------------------