atarim-visual-collaboration
/
third-party
/
backup
/
jetbackup
/
class-avcf-abilities-jetbackup-system.php
class-avcf-abilities-jetbackup-backups.php
3 days ago
class-avcf-abilities-jetbackup-destinations.php
2 weeks ago
class-avcf-abilities-jetbackup-jobs.php
2 weeks ago
class-avcf-abilities-jetbackup-queue.php
3 days ago
class-avcf-abilities-jetbackup-restore-point.php
3 days ago
class-avcf-abilities-jetbackup-restore.php
3 days ago
class-avcf-abilities-jetbackup-schedules.php
2 weeks ago
class-avcf-abilities-jetbackup-settings.php
2 weeks ago
class-avcf-abilities-jetbackup-system.php
2 weeks ago
class-avcf-jetbackup-detector.php
2 weeks ago
class-avcf-jetbackup-helpers.php
3 days ago
class-avcf-abilities-jetbackup-system.php
225 lines
| 1 | <?php |
| 2 | /** |
| 3 | * JetBackup — System ability cluster. |
| 4 | * |
| 5 | * Read-only introspection: dashboard summary, system info (with the same path |
| 6 | * redaction JetBackup applies), task logs, database-table listings (for |
| 7 | * selective backup/restore), and destination file browsing. |
| 8 | * |
| 9 | * Gated by manage_options. Built on JetBackup 3.1.23.x; not runtime-tested here. |
| 10 | * |
| 11 | * @package atarim-visual-collaboration |
| 12 | */ |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | class AVCF_Abilities_JetBackup_System extends AVCF_Abilities_Base { |
| 19 | |
| 20 | /** @var AVCF_JetBackup_Detector */ |
| 21 | private $detector; |
| 22 | |
| 23 | public function __construct() { |
| 24 | $this->detector = new AVCF_JetBackup_Detector(); |
| 25 | } |
| 26 | |
| 27 | public function register() { |
| 28 | if ( ! $this->detector->avcf_jetbackup_is_available() ) { |
| 29 | return; |
| 30 | } |
| 31 | $this->register_get_dashboard(); |
| 32 | $this->register_get_system_info(); |
| 33 | $this->register_get_log(); |
| 34 | $this->register_list_database_tables(); |
| 35 | $this->register_get_database_tables(); |
| 36 | $this->register_file_manager(); |
| 37 | } |
| 38 | |
| 39 | /* ------------------------------ shared ----------------------------- */ |
| 40 | |
| 41 | private function ro_meta() { |
| 42 | return [ 'mcp' => [ 'public' => true, 'type' => 'tool' ], 'annotations' => [ 'readonly' => true, 'destructive' => false, 'idempotent' => true ] ]; |
| 43 | } |
| 44 | public function can() { |
| 45 | return AVCF_JetBackup_Helpers::can_manage(); |
| 46 | } |
| 47 | private function out_schema() { |
| 48 | return [ |
| 49 | 'type' => 'object', |
| 50 | 'properties' => [ |
| 51 | 'success' => [ 'type' => 'boolean' ], |
| 52 | 'message' => [ 'type' => 'string' ], |
| 53 | 'data' => [ 'type' => 'object' ], |
| 54 | ], |
| 55 | 'required' => [ 'success', 'message' ], |
| 56 | ]; |
| 57 | } |
| 58 | private function no_input_schema() { |
| 59 | return [ 'type' => 'object', 'properties' => new \stdClass(), 'additionalProperties' => false ]; |
| 60 | } |
| 61 | |
| 62 | /* ---------------------------- get-dashboard ------------------------- */ |
| 63 | |
| 64 | private function register_get_dashboard() { |
| 65 | $self = $this; |
| 66 | wp_register_ability( 'atarim/jetbackup-get-dashboard', [ |
| 67 | 'label' => 'Get JetBackup Dashboard', |
| 68 | 'category' => 'atarim', |
| 69 | 'description' => 'Get the JetBackup dashboard summary (recent backups, next runs, status overview).', |
| 70 | 'input_schema' => $this->no_input_schema(), |
| 71 | 'output_schema' => $this->out_schema(), |
| 72 | 'execute_callback' => function( $input = [] ) { |
| 73 | return AVCF_JetBackup_Helpers::invoke( 'GetDashboard', [] ); |
| 74 | }, |
| 75 | 'permission_callback' => function() use ( $self ) { return $self->can(); }, |
| 76 | 'meta' => $this->ro_meta(), |
| 77 | ] ); |
| 78 | } |
| 79 | |
| 80 | /* --------------------------- get-system-info ------------------------ */ |
| 81 | |
| 82 | private function register_get_system_info() { |
| 83 | $self = $this; |
| 84 | wp_register_ability( 'atarim/jetbackup-get-system-info', [ |
| 85 | 'label' => 'Get JetBackup System Info', |
| 86 | 'category' => 'atarim', |
| 87 | 'description' => 'Get JetBackup system information (PHP/environment/paths). Sensitive path fields are redacted, matching JetBackup\'s own behaviour.', |
| 88 | 'input_schema' => $this->no_input_schema(), |
| 89 | 'output_schema' => $this->out_schema(), |
| 90 | 'execute_callback' => function( $input = [] ) { |
| 91 | $result = AVCF_JetBackup_Helpers::invoke( 'GetSystemInfo', [] ); |
| 92 | if ( ! empty( $result['success'] ) && ! empty( $result['data'] ) && is_array( $result['data'] ) ) { |
| 93 | $result['data'] = AVCF_JetBackup_Helpers::redact_system_info( $result['data'] ); |
| 94 | } |
| 95 | return $result; |
| 96 | }, |
| 97 | 'permission_callback' => function() use ( $self ) { return $self->can(); }, |
| 98 | 'meta' => $this->ro_meta(), |
| 99 | ] ); |
| 100 | } |
| 101 | |
| 102 | /* ------------------------------ get-log ----------------------------- */ |
| 103 | |
| 104 | private function register_get_log() { |
| 105 | $self = $this; |
| 106 | wp_register_ability( 'atarim/jetbackup-get-log', [ |
| 107 | 'label' => 'Get JetBackup Log', |
| 108 | 'category' => 'atarim', |
| 109 | 'description' => 'Get the log for a queue item (backup/restore/etc.) by queue_item_id. Set content:true to include the log body.', |
| 110 | 'input_schema' => [ |
| 111 | 'type' => 'object', |
| 112 | 'properties' => [ |
| 113 | 'queue_item_id' => [ 'type' => 'integer', 'minimum' => 1, 'description' => 'Queue item id whose log to fetch.' ], |
| 114 | 'content' => [ 'type' => 'boolean', 'description' => 'Include the full log content (default false).' ], |
| 115 | ], |
| 116 | 'required' => [ 'queue_item_id' ], |
| 117 | 'additionalProperties' => false, |
| 118 | ], |
| 119 | 'output_schema' => $this->out_schema(), |
| 120 | 'execute_callback' => function( $input = [] ) { |
| 121 | $input = (array) $input; |
| 122 | if ( empty( $input['queue_item_id'] ) ) { |
| 123 | return [ 'success' => false, 'message' => 'Missing queue_item_id.', 'data' => [] ]; |
| 124 | } |
| 125 | $data = [ 'queue_item_id' => (int) $input['queue_item_id'] ]; |
| 126 | if ( array_key_exists( 'content', $input ) ) { |
| 127 | $data['content'] = filter_var( $input['content'], FILTER_VALIDATE_BOOLEAN ); |
| 128 | } |
| 129 | return AVCF_JetBackup_Helpers::invoke( 'GetLog', $data ); |
| 130 | }, |
| 131 | 'permission_callback' => function() use ( $self ) { return $self->can(); }, |
| 132 | 'meta' => $this->ro_meta(), |
| 133 | ] ); |
| 134 | } |
| 135 | |
| 136 | /* ----------------------- list-database-tables ----------------------- */ |
| 137 | |
| 138 | private function register_list_database_tables() { |
| 139 | $self = $this; |
| 140 | wp_register_ability( 'atarim/jetbackup-list-database-tables', [ |
| 141 | 'label' => 'List JetBackup Database Tables', |
| 142 | 'category' => 'atarim', |
| 143 | 'description' => 'List the site\'s database tables (useful for building database exclude lists on a backup job). Optional skip, limit (1-100, default 50).', |
| 144 | 'input_schema' => [ |
| 145 | 'type' => 'object', |
| 146 | 'properties' => [ |
| 147 | 'skip' => [ 'type' => 'integer', 'minimum' => 0, 'default' => 0 ], |
| 148 | 'limit' => [ 'type' => 'integer', 'minimum' => 1, 'maximum' => 100, 'default' => 50 ], |
| 149 | ], |
| 150 | 'additionalProperties' => false, |
| 151 | ], |
| 152 | 'output_schema' => $this->out_schema(), |
| 153 | 'execute_callback' => function( $input = [] ) { |
| 154 | return AVCF_JetBackup_Helpers::invoke( 'ListDatabaseTables', AVCF_JetBackup_Helpers::paginate( (array) $input ) ); |
| 155 | }, |
| 156 | 'permission_callback' => function() use ( $self ) { return $self->can(); }, |
| 157 | 'meta' => $this->ro_meta(), |
| 158 | ] ); |
| 159 | } |
| 160 | |
| 161 | /* ------------------------ get-database-tables ----------------------- */ |
| 162 | |
| 163 | private function register_get_database_tables() { |
| 164 | $self = $this; |
| 165 | wp_register_ability( 'atarim/jetbackup-get-database-tables', [ |
| 166 | 'label' => 'Get JetBackup Backup Database Tables', |
| 167 | 'category' => 'atarim', |
| 168 | 'description' => 'Get the database tables contained in a specific backup snapshot by id (useful for selective database restore — pass these to jetbackup-restore-backup as tables).', |
| 169 | 'input_schema' => [ |
| 170 | 'type' => 'object', |
| 171 | 'properties' => [ 'id' => [ 'type' => 'integer', 'minimum' => 1, 'description' => 'Backup snapshot id.' ] ], |
| 172 | 'required' => [ 'id' ], |
| 173 | 'additionalProperties' => false, |
| 174 | ], |
| 175 | 'output_schema' => $this->out_schema(), |
| 176 | 'execute_callback' => function( $input = [] ) { |
| 177 | $input = (array) $input; |
| 178 | if ( empty( $input['id'] ) ) { |
| 179 | return [ 'success' => false, 'message' => 'Missing id (backup snapshot id).', 'data' => [] ]; |
| 180 | } |
| 181 | return AVCF_JetBackup_Helpers::invoke( 'GetDatabaseTables', AVCF_JetBackup_Helpers::id_payload( $input ) ); |
| 182 | }, |
| 183 | 'permission_callback' => function() use ( $self ) { return $self->can(); }, |
| 184 | 'meta' => $this->ro_meta(), |
| 185 | ] ); |
| 186 | } |
| 187 | |
| 188 | /* ---------------------------- file-manager -------------------------- */ |
| 189 | |
| 190 | private function register_file_manager() { |
| 191 | $self = $this; |
| 192 | wp_register_ability( 'atarim/jetbackup-file-manager', [ |
| 193 | 'label' => 'Browse JetBackup Files', |
| 194 | 'category' => 'atarim', |
| 195 | 'description' => 'Browse files/folders (e.g. on a destination or within a backup) to build include/exclude paths for backup or restore. Provide destination_id and/or a location path; id optionally scopes to a backup snapshot.', |
| 196 | 'input_schema' => [ |
| 197 | 'type' => 'object', |
| 198 | 'properties' => [ |
| 199 | 'destination_id' => [ 'type' => 'integer', 'minimum' => 0, 'description' => 'Destination id to browse.' ], |
| 200 | 'location' => [ 'type' => 'string', 'description' => 'Path/location to list.' ], |
| 201 | 'id' => [ 'type' => 'integer', 'minimum' => 0, 'description' => 'Optional backup snapshot id to scope browsing.' ], |
| 202 | ], |
| 203 | 'additionalProperties' => false, |
| 204 | ], |
| 205 | 'output_schema' => $this->out_schema(), |
| 206 | 'execute_callback' => function( $input = [] ) { |
| 207 | $input = (array) $input; |
| 208 | $data = []; |
| 209 | if ( array_key_exists( 'destination_id', $input ) ) { |
| 210 | $data['destination_id'] = (int) $input['destination_id']; |
| 211 | } |
| 212 | if ( array_key_exists( 'location', $input ) ) { |
| 213 | $data['location'] = (string) $input['location']; |
| 214 | } |
| 215 | if ( ! empty( $input['id'] ) ) { |
| 216 | $data[ AVCF_JetBackup_Helpers::ID_FIELD ] = (int) $input['id']; |
| 217 | } |
| 218 | return AVCF_JetBackup_Helpers::invoke( 'FileManager', $data ); |
| 219 | }, |
| 220 | 'permission_callback' => function() use ( $self ) { return $self->can(); }, |
| 221 | 'meta' => $this->ro_meta(), |
| 222 | ] ); |
| 223 | } |
| 224 | } |
| 225 |