News:

Support the VirtueMart project and become a member

Main Menu

Product Images - Clean up unused images ?

Started by Shimon Hirschhorn, May 16, 2016, 13:54:43 PM

Previous topic - Next topic

stankoz

Hi, I have problem with Studio42 Virtuemart media clear plugin. After click on button Clear I receive message:

Warning
Removed 0 file(s).
11272 file(s) found in DB


After click on button Error I receive message:

Warning
Removed 0 Records(s).
19733 record(s) found with file(s)

What is wrong?
I have 19733 files, but I can't delete unused pictures (after updates many product I have many pictures unused).
Can somebody help me please

Studio 42

Hi, it only remove DB errors.
1st button remove media that are not in DB
2nd button remove Db entry that have no file image.

If you need more advanced feature (not only removing images) you can buy my other tool : https://shop.st42.fr/en/products/vm-be-pro-batch-product-edit.htm
YOu have a filter "unused images" and you can select all or each file you need to remove.

MKI-Miro

Quote from: Studio 42 on May 17, 2016, 12:11:31 PM
Updated file for http://shop.st42.fr/en/products/virtuemart-media-folder-clear.htm
So now Joomla library is not missing.

we nice plugin but resized images are not cleaned, is this functionality implemented or do i something wrong?

Studio 42

Quote from: MKI-Miro on September 10, 2017, 13:13:12 PM

we nice plugin but resized images are not cleaned, is this functionality implemented or do i something wrong?

resized images are not cleaned.
Only bad entries. Missing files but entry exist in DB or unused files

PRO

Quote from: MKI-Miro on September 10, 2017, 13:13:12 PM
Quote from: Studio 42 on May 17, 2016, 12:11:31 PM
Updated file for http://shop.st42.fr/en/products/virtuemart-media-folder-clear.htm
So now Joomla library is not missing.

we nice plugin but resized images are not cleaned, is this functionality implemented or do i something wrong?

you can delete all thumbs and resize easily.

razor7

#35
Hi! This snippet gives you a list of unused product media entries. Just paste werever you like in your joomla project, just remember to remove it later.

echo '<h2>Unused Product Media Entries</h2>';

    $db = JFactory::getDbo();

    $query = $db->getQuery( true );
    $query->select( 'virtuemart_media_id' );
    $query->from( $db->quoteName( '#__virtuemart_product_medias' ) );
    $db->setQuery( $query );
    $resultArray = $db->loadAssocList();
    $ids = array();

    foreach ( $resultArray as $row )
    {
        $ids[] = $row['virtuemart_media_id'];
    }

    $query = $db->getQuery( true );
    $query->select( '*' );
    $query->from( $db->quoteName( '#__virtuemart_medias' ) );
    $query->where( $db->quoteName( 'virtuemart_media_id' ) . " NOT IN ( " . implode(",", $ids) . ")" );
    $query->andWhere($db->quoteName( 'file_type' ) . " = " . $db->quote( 'product' ));
    $db->setQuery( $query );
    $resultArray = $db->loadAssocList();

    if (!empty($resultArray)) { ?>
        <table>
            <thead>
                <tr>
                    <th>virtuemart_media_id</th>
                    <th>file_url</th>
                    <th>file_type</th>
                </tr>
            </thead>
            <tbody>
            <?php
            
foreach ( $resultArray as $row )
            { 
?>

                <tr>
                    <td><?php echo $row['virtuemart_media_id']; ?></td>
                    <td><?php echo $row['file_url']; ?></td>
                    <td><?php echo $row['file_type']; ?></td>
                </tr>
                <?php
            
}
            
?>

            </tbody>
        </table>
    <?php
    
} else {
        echo 
'No unused medias in products!';
    }
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store

Studio 42

Sorry razor7, but your script is really poor and don't remove or check any files and NOT IN() is limited depending the server.
For 10000 medias, your script fail and return a Db error in most case.

razor7

#37
Quote from: Studio 42 on October 13, 2017, 23:41:44 PM
Sorry razor7, but your script is really poor and don't remove or check any files and NOT IN() is limited depending the server.
For 10000 medias, your script fail and return a Db error in most case.

Hi! I stated clearly this snippet gives you a list of unused product media entries. It's not the holy grial of PHP code, just my two cents to find unused product media files. If you feel it's poor, then you may get it better and post the code here.

EDIT: Forgot to mention that with this script I was able to delete 1800+ unused product media entries in DB (using the ID's given by the script), then with Studio 42 plugin I was able to phisically remove the files (because there was no DB entry in the medias table for those files).
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store

Studio 42

This raw query should displayed all unused medias.

$query = 'SELECT m.* FROM #__virtuemart_medias as m LEFT JOIN  `#__virtuemart_product_medias` pm  on m.virtuemart_media_id = pm.virtuemart_media_id where pm.virtuemart_media_id IS NULL AND file_type="product" ';
$db->setQuery( $query );
$resultArray = $db->loadAssocList();


Only one query and unlimited results ;)

razor7

Great! you see...it could be always better!
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store

AzMandius

#40
Hi all,
Sorry for rising a necro-thread.
Just wanted to know if someone tested Studio 42's plugin (https://shop.st42.fr/en/products/virtuemart-media-folder-clear.htm) with Joomla 2.5.xx?
Thanks
AzBlog.me | Mentally healthy content & lnks.

Studio 42


AzMandius

Hooray! I confirm, it works on Joomla! 2.5.28 with VirtueMart 3.0.4! I was able to safely remove all orphan images and database entries.
Thank you Studio 42!
AzBlog.me | Mentally healthy content & lnks.