Author Topic: delete unused images script  (Read 104082 times)

Gruz

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 159
  • Copyleft (є) all rights reversed
Re: delete unused images script
« Reply #15 on: July 21, 2012, 10:13:07 am »
What VM version do you have?
Your installable language for VM2: http://gruz.org.ua/virtuemart-language-files.html

pierregulpen

  • Beginner
  • *
  • Posts: 28
Re: delete unused images script
« Reply #16 on: July 21, 2012, 11:20:59 am »
1.1.9 but i have a one page checkout build in and template from a third party.. Maybe there's the problem ?

Gruz

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 159
  • Copyleft (є) all rights reversed
Re: delete unused images script
« Reply #17 on: July 21, 2012, 11:27:00 am »
When adding the script to the template index.php you must run the web-site at a VM page. If a VM is not at the main page, then the VM class ps_DB is not loaded.

Add the script (from my web-site) and run proper url site.com/?option=com_virtuemart
Your installable language for VM2: http://gruz.org.ua/virtuemart-language-files.html

pierregulpen

  • Beginner
  • *
  • Posts: 28
Re: delete unused images script
« Reply #18 on: July 21, 2012, 11:49:42 am »
so instead of :  http://yoursite.com?tmpl=somefile

i should do :  site.com/?option=com_virtuemart

Gruz

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 159
  • Copyleft (є) all rights reversed
Re: delete unused images script
« Reply #19 on: July 21, 2012, 12:08:42 pm »
http://yoursite.com?tmpl=somefile&option=com_virtuemart

The somefile  must be placed in the active Joomla template.
Your installable language for VM2: http://gruz.org.ua/virtuemart-language-files.html

pierregulpen

  • Beginner
  • *
  • Posts: 28
Re: delete unused images script
« Reply #20 on: July 21, 2012, 12:10:56 pm »
ok, thnx i will try

let you know later if worked

pierregulpen

  • Beginner
  • *
  • Posts: 28
Re: delete unused images script
« Reply #21 on: July 21, 2012, 12:23:21 pm »
 8) Works Great !!

Thank you , Total removed files :480 !!  saves me several MB in Webspace :-)

amorino

  • Jr. Member
  • **
  • Posts: 151
    • Création sites web Tunisie
Re: delete unused images script
« Reply #22 on: March 29, 2013, 15:26:41 pm »
Hello,
this script worked fine for me
thank you very much
Best regards
Amorino
Création sites web Tunisie
http://www.idealconception.com

nunoms

  • Beginner
  • *
  • Posts: 1
Re: delete unused images script
« Reply #23 on: October 03, 2013, 18:04:59 pm »
Hi,

I am using Joomla 2.5 and Virtuemart 2.0.24.

I can not run this script, always gives the error: "Fatal error: Class 'ps_DB' "

I'm putting the following address: "http://localhost/site/?tmpl=script&option=com_virtuemart"


Someone can help me?


Thanks,
Nuno Amaral

ex3mist

  • Jr. Member
  • **
  • Posts: 90
Re: delete unused images script
« Reply #24 on: August 29, 2014, 09:09:01 am »
Hello,
Now I'm also looking for a slution of this issue for VM2. Can anyone help? I've tried what is mentioned for VM1 by changing the path for the images folder, but unfortunately it doesn't work. Any help would be appreciated!

ocean1

  • Guest
Re: delete unused images script
« Reply #25 on: September 25, 2014, 22:09:52 pm »
I've updated my article here:
http://gruz.org.ua/en/about-joomla/34-virtuemart/27-vydalennja-zobrazhen-shcho-ne-vykorystovujutsja-z-virtuemart-11x.html

Some other fixes also.


Hi, great script.
Is it possible that you update it also for VM2 and Joomla 2.5.x?


d0ublezer0

  • Jr. Member
  • **
  • Posts: 213
Re: delete unused images script
« Reply #26 on: October 06, 2015, 20:16:13 pm »
For vm2 or vm3:
Code: [Select]
<?php
$type 
'product'// type of image: "product" or "category"
$imgPath $_SERVER['DOCUMENT_ROOT']."/images/stories/virtuemart/$type/"// default path to full-sized images
$resizedPath $_SERVER['DOCUMENT_ROOT']."/images/stories/virtuemart/$type/resized/"// default path to thumbnail images
set_time_limit(0); 
require 
$_SERVER['DOCUMENT_ROOT'].'/configuration.php'
$conf = new JConfig
$db = new mysqli($conf->host$conf->user$conf->password$conf->db);

$images array_slice(scandir($imgPath), 2);
$resized array_slice(scandir($resizedPath), 2);

$query="SELECT 
virtuemart_media_id, 
file_url, 
file_url_thumb 
FROM 
{$conf->dbprefix}virtuemart_medias
WHERE virtuemart_media_id IN(SELECT DISTINCT virtuemart_media_id FROM 
{$conf->dbprefix}virtuemart_{$type}_medias)";

$res $db->query($query);

if (!
$res) die("Cannot get database resource!");

while(
$r $res->fetch_array()){
    
$activeID[] = $r[0];

    
$p pathinfo($r[1]);
    
$activeImg[] = $p['basename'];

    
$p pathinfo($r[2]);
    
$activeResized[] = $p['basename'];
}       
if (!
is_null($activeImg)){
    
$notActiveImg array_diff($images$activeImg);   
};
if (!
is_null($activeResized)){
    
$notActiveResized array_diff($resized$activeResized);
}

if (!
is_null($activeID)){
    
$db->query("DELETE FROM {$conf->dbprefix}virtuemart_medias WHERE file_type='$type' AND virtuemart_media_id NOT IN(".implode(','$activeID).")");
}
$db->close();


$full=0;
$thumb=0;
if (!
is_null($activeImg)){

    foreach(
$notActiveImg as $i){
        if(
is_file($imgPath.$i) && $i != 'index.html'){
            if (
unlink($imgPath.$i)) $full++; else echo "Cannot delete $imgPath$i<br>";
        } else 
"File not exists $imgPath.$i<br>";
    }
}
if (!
is_null($activeResized)){

    foreach(
$notActiveResized as $i){
        if(
is_file($resizedPath.$i)  && $i != 'index.html'){
            if (
unlink($resizedPath.$i)) $thumb++; else echo "Cannot delete $imgPath$i<br>";
        } else 
"File not exists $imgPath.$i<br>";
    }
}
if (
$full>0) echo "Deleted $full full-sized images<br>";
if (
$thumb>0) echo "Deleted $thumb thumbnail images<br>";
if (
$full==&& $thumb==0) echo "Nothing to delete";
?>

ex3mist

  • Jr. Member
  • **
  • Posts: 90
Re: delete unused images script
« Reply #27 on: October 27, 2015, 17:19:26 pm »
Hello d0ublezer0,

I've just tried your code but for some reason it didn't work. What I do is to create file /templates/YOURTEMPLATE/somefile.php and then execute it by typing this http://yoursite.com?tmpl=somefile in the browser. But nothing happens. Is it what I have to do? Am I missing something or doing anything wrong? Thanks!

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10743
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.8.8
Re: delete unused images script
« Reply #28 on: October 27, 2015, 22:42:55 pm »
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ex3mist

  • Jr. Member
  • **
  • Posts: 90
Re: delete unused images script
« Reply #29 on: October 28, 2015, 08:45:59 am »
Now it worked! I guess I was doing something wrong... Thanks a lot for the sollution!