Skip to content

Commit 845a7c0

Browse files
committed
feat(backup): enhance site disabled state handling
1 parent 4197ff8 commit 845a7c0

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/helper/Site_Backup_Restore.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ public function __construct() {
5050

5151
public function backup( $args, $assoc_args = [] ) {
5252
delem_log( 'site backup start' );
53-
$args = auto_site_name( $args, 'site', __FUNCTION__ );
53+
$args = auto_site_name( $args, 'site', __FUNCTION__ );
5454
$list_backups = \EE\Utils\get_flag_value( $assoc_args, 'list' );
5555
$dash_auth = \EE\Utils\get_flag_value( $assoc_args, 'dash-auth' );
5656

57-
// For dash-auth commands, we need to handle site disabled state specially
58-
// to send API callback instead of just exiting with error
59-
if ( $dash_auth ) {
57+
// For --list or --dash-auth, we handle site disabled state specially
58+
// --list is read-only and should work regardless of site state
59+
// --dash-auth needs to send API callback instead of just exiting with error
60+
if ( $list_backups || $dash_auth ) {
6061
$this->site_data = get_site_info( $args, false, true, true );
6162
} else {
6263
$this->site_data = get_site_info( $args, true, true, true );
@@ -77,11 +78,6 @@ public function backup( $args, $assoc_args = [] ) {
7778
// Parse backup-id:backup-verification-token format
7879
$auth_parts = explode( ':', $dash_auth, 2 );
7980
if ( count( $auth_parts ) !== 2 || empty( $auth_parts[0] ) || empty( $auth_parts[1] ) ) {
80-
$this->capture_error(
81-
'Invalid --dash-auth format. Expected: backup-id:backup-verification-token',
82-
self::ERROR_TYPE_VALIDATION,
83-
1001
84-
);
8581
EE::error( 'Invalid --dash-auth format. Expected: backup-id:backup-verification-token' );
8682
}
8783

@@ -92,6 +88,7 @@ public function backup( $args, $assoc_args = [] ) {
9288
}
9389

9490
// Store dash auth info in class properties for shutdown handler
91+
// Must be set before any capture_error calls so API callbacks work
9592
$this->dash_auth_enabled = true;
9693
$this->dash_backup_id = $auth_parts[0];
9794
$this->dash_verify_token = $auth_parts[1];
@@ -106,13 +103,10 @@ public function backup( $args, $assoc_args = [] ) {
106103
register_shutdown_function( [ $this, 'dash_shutdown_handler' ] );
107104

108105
// Check if site is disabled - send API callback with error
109-
if ( empty( $this->site_data['site_enabled'] ) ) {
110-
$this->capture_error(
111-
sprintf( 'Site %s is disabled. Enable it with `ee site enable %s` to create backup.', $this->site_data['site_url'], $this->site_data['site_url'] ),
112-
self::ERROR_TYPE_VALIDATION,
113-
1003
114-
);
115-
EE::error( sprintf( 'Site %s is disabled. Enable it with `ee site enable %s` to create backup.', $this->site_data['site_url'], $this->site_data['site_url'] ) );
106+
if ( ! $this->site_data['site_enabled'] ) {
107+
$error_msg = sprintf( 'Site %s is disabled. Enable it with `ee site enable %s` to create backup.', $this->site_data['site_url'], $this->site_data['site_url'] );
108+
$this->capture_error( $error_msg, self::ERROR_TYPE_VALIDATION, 1003 );
109+
EE::error( $error_msg );
116110
}
117111
}
118112

@@ -174,6 +168,8 @@ public function backup( $args, $assoc_args = [] ) {
174168
// Release global backup lock (also released by shutdown handler as safety net)
175169
$this->release_global_backup_lock();
176170

171+
EE::success( 'Backup created successfully.' );
172+
177173
delem_log( 'site backup end' );
178174
}
179175

@@ -1580,7 +1576,7 @@ private function send_dash_request( $endpoint, $payload ) {
15801576
) );
15811577
}
15821578
sleep( $retry_delay );
1583-
$attempt++; // Increment at end of loop iteration
1579+
$attempt ++; // Increment at end of loop iteration
15841580
} else {
15851581
// Either not a retryable error, or we've exhausted all retries
15861582
if ( $error ) {

0 commit comments

Comments
 (0)