Skip to content

Commit d18eaf2

Browse files
authored
fix: detection of flash backup activation state (#1769)
Resolves #1767 plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php:415 still reads the API version from _var($mystatus,'version'), but commit 441e180 removed the code that populates $mystatus (the parse of /var/local/emhttp/myservers.cfg). As a result $mystatus is undefined, so we now send api_version= to the flash activation endpoint. The PHP runtime also emits “Undefined variable: mystatus” / “Trying to access array offset on value of type null” notices before headers are written. Those notices corrupt the JSON response, the keyserver rejects the request because the api_version is missing, and the flash backup state file is never updated—so the web GUI stays stuck at “Loading”. Because the status request always invokes UpdateFlashBackup.php, every page load trips the same failure path, leaving /var/local/emhttp/flashbackup.ini with loading=Loading. The frontend only listens for /sub/flashbackup events, so until that INI file is rewritten the spinner never clears and the enable button never becomes active. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * UI now initializes flash backup status on page load so backup controls reflect current server state immediately. * Backup state saves now publish remote updates, improving synchronization of backup status. * **Bug Fixes** * Improved API version handling for flash backup operations: sends version when available and falls back gracefully when unknown. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 42406e7 commit d18eaf2

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,30 @@ _(Flash backup)_:
575575
<script>
576576
changeRemoteAccess($('#remoteAccess'));
577577
var flashbackupsub = new NchanSubscriber('/sub/flashbackup');
578+
var initialFlashBackupState = <?=
579+
json_encode(
580+
$flashbackup_status ?: [],
581+
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP
582+
)
583+
?> || {};
584+
585+
if (Object.keys(initialFlashBackupState).length === 0) {
586+
initialFlashBackupState = {
587+
activated: 'no',
588+
uptodate: 'no',
589+
loading: '',
590+
error: '',
591+
remoteerror: ''
592+
};
593+
}
594+
578595
flashbackupsub.on('message', function(data) {
579596
var ini = parseINI(data);
580597

581598
buttonStateReset(ini['flashbackup']);
582599
});
583600
$(function() {
601+
buttonStateReset(initialFlashBackupState);
584602
flashbackupsub.start();
585603
if ( typeof caPluginUpdateCheck === "function" ) {
586604
caPluginUpdateCheck("dynamix.unraid.net.plg",{name:"Unraid Connect"});
@@ -602,4 +620,3 @@ _(OIDC Configuration)_:
602620

603621
<!-- start unraid-api section -->
604622
<unraid-connect-settings></unraid-connect-settings>
605-

plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
2020
require_once "$docroot/webGui/include/Wrappers.php";
21+
require_once "$docroot/webGui/include/publish.php";
2122
require_once "$docroot/plugins/dynamix.my.servers/include/connect-config.php";
2223

2324
$isRegistered = ConnectConfig::isUserSignedIn();
@@ -32,6 +33,7 @@
3233
}
3334

3435
$isConnected = ($connectionStatus === 'CONNECTED') ? true : false;
36+
$apiVersion = ApiConfig::getApiVersion();
3537

3638
$flashbackup_ini = '/var/local/emhttp/flashbackup.ini';
3739

@@ -75,6 +77,7 @@ function save_flash_backup_state($loading='') {
7577
$flashbackup_tmp = '/var/local/emhttp/flashbackup.new';
7678
file_put_contents($flashbackup_tmp, $text);
7779
rename($flashbackup_tmp, $flashbackup_ini);
80+
publish('flashbackup', $text);
7881
}
7982

8083
function default_flash_backup_state() {
@@ -416,7 +419,7 @@ function deleteLocalRepo() {
416419
curl_setopt($ch, CURLOPT_POSTFIELDS, [
417420
'keyfile' => $keyfile,
418421
'version' => _var($var,'version'),
419-
'api_version' => _var($mystatus, 'version'),
422+
'api_version' => ($apiVersion && $apiVersion !== 'unknown') ? $apiVersion : '',
420423
'bzfiles' => implode(',', $bzfilehashes)
421424
]);
422425
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

0 commit comments

Comments
 (0)