*/ protected function input_properties(): array { return array( 'id' => array( 'type' => 'string', 'description' => __( 'Backup identifier from all-in-one/list-backups.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.35 * @return array */ protected function required_input(): array { return array('id'); } /** * @since 0.0.35 * @return array */ protected function output_properties(): array { return array( 'backup_id' => array( 'type' => 'string' ), 'files_removed' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ), 'bytes_freed' => array( 'type' => 'integer' ), 'remaining' => array( 'type' => 'integer' ), 'note' => array( 'type' => 'string' ), ); } /** * @since 0.0.35 * @return array */ protected function annotations(): array { return array( 'readonly' => false, 'destructive' => true, 'idempotent' => false, ); } /** * @since 0.0.35 * @param array $input Input. * @return array|WP_Error */ protected function run( array $input ) { $result = Archive_Repository::delete_backup( (string) $input['id'] ); if ( is_wp_error( $result ) ) { return $result; } // Read the count back rather than assuming the delete landed, and say plainly when it was // the last one: a site with no backups left is a different situation from one with nine. $remaining = Archive_Repository::status(); $left = isset( $remaining['backup_count'] ) ? (int) $remaining['backup_count'] : 0; $result['remaining'] = $left; if ( 0 === $left ) { $result['note'] = trim( ( isset( $result['note'] ) ? (string) $result['note'] . ' ' : '' ) . __( 'That was the last backup set All-in-One WP Migration held. There is now nothing to restore this site from.', 'acrossai-abilities-manager' ) ); } return $result; } }