Skip to content

Commit ae6786e

Browse files
authored
Merge pull request #475 from mrrobot47/backup/site-disabled-check
Improvements for handling site disabled state in backup
2 parents 877a78c + ae2dd9a commit ae6786e

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/helper/Site_Backup_Restore.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,18 @@ 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__ );
54-
$this->site_data = get_site_info( $args, true, true, true );
55-
$list_backups = \EE\Utils\get_flag_value( $assoc_args, 'list' );
53+
$args = auto_site_name( $args, 'site', __FUNCTION__ );
54+
$list_backups = \EE\Utils\get_flag_value( $assoc_args, 'list' );
55+
$dash_auth = \EE\Utils\get_flag_value( $assoc_args, 'dash-auth' );
56+
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 ) {
61+
$this->site_data = get_site_info( $args, false, true, true );
62+
} else {
63+
$this->site_data = get_site_info( $args, true, true, true );
64+
}
5665

5766
// Handle --list flag to display available backups
5867
if ( $list_backups ) {
@@ -62,20 +71,13 @@ public function backup( $args, $assoc_args = [] ) {
6271
}
6372

6473
// Handle --dash-auth flag for EasyDash integration
65-
$dash_auth = \EE\Utils\get_flag_value( $assoc_args, 'dash-auth' );
66-
6774
if ( $dash_auth ) {
6875
// Debug: Log the raw dash_auth value received
6976
EE::debug( 'Received --dash-auth value: ' . $dash_auth );
7077

7178
// Parse backup-id:backup-verification-token format
7279
$auth_parts = explode( ':', $dash_auth, 2 );
7380
if ( count( $auth_parts ) !== 2 || empty( $auth_parts[0] ) || empty( $auth_parts[1] ) ) {
74-
$this->capture_error(
75-
'Invalid --dash-auth format. Expected: backup-id:backup-verification-token',
76-
self::ERROR_TYPE_VALIDATION,
77-
1001
78-
);
7981
EE::error( 'Invalid --dash-auth format. Expected: backup-id:backup-verification-token' );
8082
}
8183

@@ -86,6 +88,7 @@ public function backup( $args, $assoc_args = [] ) {
8688
}
8789

8890
// Store dash auth info in class properties for shutdown handler
91+
// Must be set before any capture_error calls so API callbacks work
8992
$this->dash_auth_enabled = true;
9093
$this->dash_backup_id = $auth_parts[0];
9194
$this->dash_verify_token = $auth_parts[1];
@@ -98,6 +101,13 @@ public function backup( $args, $assoc_args = [] ) {
98101

99102
// Register shutdown handler to send failure callback if backup doesn't complete
100103
register_shutdown_function( [ $this, 'dash_shutdown_handler' ] );
104+
105+
// Check if site is disabled - send API callback with error
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 );
110+
}
101111
}
102112

103113
// Acquire global lock to serialize backups (prevents OOM from concurrent backups)
@@ -158,6 +168,8 @@ public function backup( $args, $assoc_args = [] ) {
158168
// Release global backup lock (also released by shutdown handler as safety net)
159169
$this->release_global_backup_lock();
160170

171+
EE::success( 'Backup created successfully.' );
172+
161173
delem_log( 'site backup end' );
162174
}
163175

@@ -1564,7 +1576,7 @@ private function send_dash_request( $endpoint, $payload ) {
15641576
) );
15651577
}
15661578
sleep( $retry_delay );
1567-
$attempt++; // Increment at end of loop iteration
1579+
$attempt ++; // Increment at end of loop iteration
15681580
} else {
15691581
// Either not a retryable error, or we've exhausted all retries
15701582
if ( $error ) {

src/helper/class-ee-site.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,9 +2498,8 @@ public function sync( $args, $assoc_args ) {
24982498
* $ ee site backup example.com --list
24992499
*/
25002500
public function backup( $args, $assoc_args ) {
2501-
$args = auto_site_name( $args, 'site', __FUNCTION__ );
2502-
$this->site_data = get_site_info( $args, true, true, true );
2503-
$backup_restore = new Site_Backup_Restore();
2501+
$args = auto_site_name( $args, 'site', __FUNCTION__ );
2502+
$backup_restore = new Site_Backup_Restore();
25042503
$backup_restore->backup( $args, $assoc_args );
25052504
}
25062505

@@ -2525,9 +2524,8 @@ public function backup( $args, $assoc_args ) {
25252524
*
25262525
*/
25272526
public function restore( $args, $assoc_args ) {
2528-
$args = auto_site_name( $args, 'site', __FUNCTION__ );
2529-
$this->site_data = get_site_info( $args, true, true, true );
2530-
$backup_restore = new Site_Backup_Restore();
2527+
$args = auto_site_name( $args, 'site', __FUNCTION__ );
2528+
$backup_restore = new Site_Backup_Restore();
25312529
$backup_restore->restore( $args, $assoc_args );
25322530
}
25332531

0 commit comments

Comments
 (0)