*

umimo

  • ***
  • 88 posts
Re: WebP Images generator - delete jpegs.
« Reply #15 on: October 27, 2022, 02:18:53 PM »
@mwindey

Thanks brother


I have 700 plus folders

How to delete all?

Try this  * but not working

*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/*/*.jpg

*

mwindey

  • *****
  • 472 posts
Re: WebP Images generator - delete jpegs.
« Reply #16 on: October 27, 2022, 03:23:53 PM »
@umimo

I guess with next cron it will work (separate all folders with comma) .... Maybe there is a better way than this but it's the first one i could think of....
Code: [Select]
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/{1,2,3,4,5,6,7,8,9,10,11,12,13,14}/*.jpg




*

MB Themes

Re: WebP Images generator - delete jpegs.
« Reply #17 on: October 28, 2022, 01:41:31 PM »
Such amount should be managed from command line
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

MB Themes

Re: WebP Images generator - delete jpegs.
« Reply #18 on: October 30, 2022, 09:08:19 AM »
You will have folders 0, 1, 2, 3...
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 472 posts
Re: WebP Images generator - delete jpegs.
« Reply #19 on: January 21, 2024, 04:00:48 PM »
Finally a solution found to clear all jpg files with directadmin cron. it will delete all files jpg in all numeric folders starting from 0,1,2,3, etc.... folders with names inside the upload directory stay untouched.

For DA  cron is

/usr/bin/find /home/u45******/domains/do***.com/public_html/oc-content/uploads/ -mindepth 2 -maxdepth 2 -type f -regex '.*/[0-9]+/[^/]+\.jpg' -print0 | xargs -0 /bin/rm -f >/dev/null 2>&1

This works easier than create a cronjob for every folder as it was before :-)
Enjoy ;)

Next was a DAO to set item_resource table to set s_extension to webp... To do this create a php file called photowebp.php in your public_html directory.
Use code:
Code: [Select]
<?php

if (php_sapi_name() !== 'cli') {
    die(
'Access denied.');
}

define('ABS_PATH'dirname(__FILE__) . '/');
require_once 
ABS_PATH 'oc-load.php';

require_once 
ABS_PATH 'oc-content/plugins/webp_images/model/ModelUP.php';
$modelUP ModelUP::newInstance();

// Attempt to update item resources
try {
    
$modelUP->updateItemResource();
} catch (
Exception $e) {
    
// Handle the exception if needed
}

?>


Then in folder oc-content/plugins/webp_images/model create a php file named ModelUP.php with code:
Code: [Select]
<?php
class ModelUP extends DAO {
    private static 
$instance;

    public function 
query($sql) {
        return 
$this->dao->query($sql);
    }

    public static function 
newInstance() {
        if (!
self::$instance instanceof self) {
            
self::$instance = new self;
        }
        return 
self::$instance;
    }

    function 
__construct() {
        
parent::__construct();
    }

    public function 
getTableItemResource() {
        return 
DB_TABLE_PREFIX 't_item_resource';
    }

    public function 
updateItemResource() {
        
$sql "UPDATE " $this->getTableItemResource() . " SET s_extension='webp' WHERE s_extension IN ('jpg', 'png', 'gif', 'jpeg')";

        
$this->query($sql);
    }
}
?>


Call file photowebp.php when you want to run it using cronjob in directadmin with command:

Code: [Select]
/usr/local/bin/php -q -f /home/u441*****/domains/domain.com/public_html/photowebp.php >/dev/null 2>&1

Your done :-) Enjoy

« Last Edit: January 21, 2024, 04:19:49 PM by mwindey »