crawler.cls.php
8 months ago
database.cls.php
8 months ago
debug.cls.php
8 months ago
image.cls.php
8 months ago
online.cls.php
8 months ago
option.cls.php
8 months ago
presets.cls.php
8 months ago
purge.cls.php
8 months ago
presets.cls.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Presets CLI for LiteSpeed Cache. |
| 4 | * |
| 5 | * @package LiteSpeed\CLI |
| 6 | */ |
| 7 | |
| 8 | namespace LiteSpeed\CLI; |
| 9 | |
| 10 | defined( 'WPINC' ) || exit(); |
| 11 | |
| 12 | use LiteSpeed\Debug2; |
| 13 | use LiteSpeed\Preset; |
| 14 | use WP_CLI; |
| 15 | |
| 16 | /** |
| 17 | * Presets CLI |
| 18 | */ |
| 19 | class Presets { |
| 20 | |
| 21 | /** |
| 22 | * Preset instance. |
| 23 | * |
| 24 | * @var Preset |
| 25 | */ |
| 26 | private $preset; |
| 27 | |
| 28 | /** |
| 29 | * Constructor for Presets CLI. |
| 30 | */ |
| 31 | public function __construct() { |
| 32 | Debug2::debug( 'CLI_Presets init' ); |
| 33 | |
| 34 | $this->preset = Preset::cls(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Applies a standard preset's settings. |
| 39 | * |
| 40 | * ## OPTIONS |
| 41 | * |
| 42 | * <preset> |
| 43 | * : The preset name to apply (e.g., basic). |
| 44 | * |
| 45 | * ## EXAMPLES |
| 46 | * |
| 47 | * # Apply the preset called "basic" |
| 48 | * $ wp litespeed-presets apply basic |
| 49 | * |
| 50 | * @param array $args Positional arguments (preset). |
| 51 | */ |
| 52 | public function apply( $args ) { |
| 53 | $preset = $args[0]; |
| 54 | |
| 55 | if ( empty( $preset ) ) { |
| 56 | WP_CLI::error( 'Please specify a preset to apply.' ); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | return $this->preset->apply( $preset ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns sorted backup names. |
| 65 | * |
| 66 | * ## OPTIONS |
| 67 | * |
| 68 | * ## EXAMPLES |
| 69 | * |
| 70 | * # Get all backups |
| 71 | * $ wp litespeed-presets get_backups |
| 72 | */ |
| 73 | public function get_backups() { |
| 74 | $backups = $this->preset->get_backups(); |
| 75 | |
| 76 | foreach ( $backups as $backup ) { |
| 77 | WP_CLI::line( $backup ); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Restores settings from the backup file with the given timestamp, then deletes the file. |
| 83 | * |
| 84 | * ## OPTIONS |
| 85 | * |
| 86 | * <timestamp> |
| 87 | * : The timestamp of the backup to restore. |
| 88 | * |
| 89 | * ## EXAMPLES |
| 90 | * |
| 91 | * # Restore the backup with the timestamp 1667485245 |
| 92 | * $ wp litespeed-presets restore 1667485245 |
| 93 | * |
| 94 | * @param array $args Positional arguments (timestamp). |
| 95 | */ |
| 96 | public function restore( $args ) { |
| 97 | $timestamp = $args[0]; |
| 98 | |
| 99 | if ( empty( $timestamp ) ) { |
| 100 | WP_CLI::error( 'Please specify a timestamp to restore.' ); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | return $this->preset->restore( $timestamp ); |
| 105 | } |
| 106 | } |
| 107 |