Skip to content

Commit

Permalink
New disableRestore setting
Browse files Browse the repository at this point in the history
New setting that allows the restore functionality to be disabled. For example, enables Craft admins to disable restore on one environment, like production, to avoid accidental overwrites.
  • Loading branch information
tvd0x2a committed Mar 19, 2024
1 parent ff7aae3 commit f70e937
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/config/remote-sync.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
],
'dev' => [],
'staging' => [],
'production' => [],
'production' => [
// Disable pull and restore only in production environment
'disableRestore' => true,
],
];
8 changes: 8 additions & 0 deletions src/controllers/RemoteSyncController.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ public function actionPullDatabase()
$plugin = RemoteSync::getInstance();
$settings = $plugin->getSettings();

if ($settings->disableRestore) {
return $this->asErrorJson(Craft::t('remote-sync', 'Restore not enabled for this environment'));
}

try {
if ($settings->useQueue) {
Craft::$app->queue->push(new PullDatabaseJob([
Expand Down Expand Up @@ -231,6 +235,10 @@ public function actionPullVolume()
$plugin = RemoteSync::getInstance();
$settings = $plugin->getSettings();

if ($settings->disableRestore) {
return $this->asErrorJson(Craft::t('remote-sync', 'Restore not enabled for this environment'));
}

try {
if ($settings->useQueue) {
Craft::$app->queue->push(new PullVolumeJob([
Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function rules(): array
$rules = parent::rules();
return $rules + [
[
['keepEmergencyBackup', 'prune'],
['disableRestore', 'keepEmergencyBackup', 'prune'],
'boolean'
],
[
Expand Down
2 changes: 2 additions & 0 deletions src/templates/utilities/_includes/_remote-sync-section.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ <h2 data-icon="{{ icon }}">{{ "Remote " ~ labelPlural|t('remote-sync') }}</h2>
<td></td>
<td></td>
<td class="thin">
{% if not disableRestore %}
<button class="btn small pull-button" title="{{ 'Pull and restore ' ~ label|lower|t }}">{{ 'Restore'|t }}</button>
{% endif %}
<button class="btn small delete-button" title="{{ 'Delete ' ~ label|lower|t }}">{{ 'Delete'|t }}</button>
</td>
</tr>
Expand Down
2 changes: 2 additions & 0 deletions src/templates/utilities/remote-sync.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
pushAction: 'remote-sync/remote-sync/push-database',
pullAction: 'remote-sync/remote-sync/pull-database',
deleteAction: 'remote-sync/remote-sync/delete-database',
disableRestore: disableRestore,
disabled: false
} %}
{% endif %}
Expand All @@ -62,6 +63,7 @@
pushAction: 'remote-sync/remote-sync/push-volume',
pullAction: 'remote-sync/remote-sync/pull-volume',
deleteAction: 'remote-sync/remote-sync/delete-volume',
disableRestore: disableRestore,
disabled: not haveVolumes
} %}
{% block message %}
Expand Down
1 change: 1 addition & 0 deletions src/utilities/RemoteSyncUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static function contentHtml(): string
"hideDatabases" => $settings->hideDatabases,
"hideVolumes" => $settings->hideVolumes,
"haveVolumes" => !$settings->hideVolumes && $haveVolumes,
"disableRestore" => $settings->disableRestore,
"queueActive" => $queueActive
]);
}
Expand Down

0 comments on commit f70e937

Please sign in to comment.