| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
|
| 4 |
namespace Imagify\CLI; |
| 5 |
|
| 6 |
use Imagify\Bulk\Bulk; |
| 7 |
|
| 8 |
/** |
| 9 |
* Command class for the bulk optimization |
| 10 |
*/ |
| 11 |
class BulkOptimizeCommand extends AbstractCommand { |
| 12 |
/** |
| 13 |
* Executes the command. |
| 14 |
* |
| 15 |
* @param array $arguments Positional argument. |
| 16 |
* @param array $options Optional arguments. |
| 17 |
*/ |
| 18 |
public function __invoke( $arguments, $options ) { |
| 19 |
$level = 2; |
| 20 |
|
| 21 |
if ( isset( $options['lossless'] ) ) { |
| 22 |
$level = 0; |
| 23 |
} |
| 24 |
|
| 25 |
foreach ( $arguments as $context ) { |
| 26 |
Bulk::get_instance()->run_optimize( $context, $level ); |
| 27 |
} |
| 28 |
|
| 29 |
\WP_CLI::log( 'Imagify bulk optimization triggered.' ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* {@inheritdoc} |
| 34 |
*/ |
| 35 |
protected function get_command_name(): string { |
| 36 |
return 'bulk-optimize'; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* {@inheritdoc} |
| 41 |
*/ |
| 42 |
public function get_description(): string { |
| 43 |
return 'Run the bulk optimization'; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* {@inheritdoc} |
| 48 |
*/ |
| 49 |
public function get_synopsis(): array { |
| 50 |
return [ |
| 51 |
[ |
| 52 |
'type' => 'positional', |
| 53 |
'name' => 'contexts', |
| 54 |
'description' => 'The context(s) to run the bulk optimization for. Possible values are wp and custom-folders.', |
| 55 |
'optional' => false, |
| 56 |
'repeating' => true, |
| 57 |
], |
| 58 |
[ |
| 59 |
'type' => 'flag', |
| 60 |
'name' => 'lossless', |
| 61 |
'description' => 'Use lossless compression.', |
| 62 |
'optional' => true, |
| 63 |
], |
| 64 |
]; |
| 65 |
} |
| 66 |
} |
| 67 |
|