Author Topic: Product Images - Clean up unused images ?  (Read 4090 times)

manwlios

  • Beginner
  • *
  • Posts: 10
  • A beginner
Re: Product Images - Clean up unused images ?
« Reply #30 on: October 21, 2016, 14:19:42 pm »
Studio 42 thank you very much fot this usefull plugin!

stankoz

  • Beginner
  • *
  • Posts: 1
  • A beginner
Re: Product Images - Clean up unused images ?
« Reply #31 on: June 26, 2017, 13:21:34 pm »
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

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2353
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Product Images - Clean up unused images ?
« Reply #32 on: June 26, 2017, 13:30:36 pm »
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

  • Jr. Member
  • **
  • Posts: 132
Re: Product Images - Clean up unused images ?
« Reply #33 on: September 10, 2017, 13:13:12 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

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2353
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Product Images - Clean up unused images ?
« Reply #34 on: September 10, 2017, 13:48:13 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

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10272
  • VirtueMart Version: 3+
Re: Product Images - Clean up unused images ?
« Reply #35 on: September 11, 2017, 19:33:59 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.
I do NOT do development work for hire.

razor7

  • Jr. Member
  • **
  • Posts: 309
    • MGSCreativa - Professional VM!
Re: Product Images - Clean up unused images ?
« Reply #36 on: October 13, 2017, 22:15:21 pm »
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.

Code: [Select]
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

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2353
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Product Images - Clean up unused images ?
« Reply #37 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.

razor7

  • Jr. Member
  • **
  • Posts: 309
    • MGSCreativa - Professional VM!
Re: Product Images - Clean up unused images ?
« Reply #38 on: October 14, 2017, 19:55:50 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

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2353
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Product Images - Clean up unused images ?
« Reply #39 on: October 14, 2017, 21:27:36 pm »
This raw query should displayed all unused medias.

Code: [Select]
$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

  • Jr. Member
  • **
  • Posts: 309
    • MGSCreativa - Professional VM!
Re: Product Images - Clean up unused images ?
« Reply #40 on: October 17, 2017, 02:12:55 am »
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