Skip to content

Commit

Permalink
Merge pull request #47 from enupal/develop
Browse files Browse the repository at this point in the history
Adds v2.1.0
  • Loading branch information
andrelopez authored Oct 20, 2023
2 parents 6f76d82 + b8c7763 commit 1d9b4c4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Enupal Backup Changelog

## 2.1.0 - 2023.10.20

### Added
- Added support to remove settings when `allowAdminChanges` is disabled ([#46])

### Fixed
- Fixed bug where assets were not added on backups ([#45])
- Fixed bug where the backup ID link disappears on the Backups view on the CP.

[#45]: https://github.com/enupal/stripe/issues/45
[#46]: https://github.com/enupal/stripe/issues/46

## 2.0.0 - 2022.05.20

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "enupal/backup",
"description": "Fully integrated Backup solution for Craft CMS",
"type": "craft-plugin",
"version": "2.0.0",
"version": "2.1.0",
"keywords": [
"craft",
"cms",
Expand Down
15 changes: 10 additions & 5 deletions src/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,23 @@ protected function createSettingsModel(): ?\craft\base\Model
public function getCpNavItem(): ?array
{
$parent = parent::getCpNavItem();
return array_merge($parent, [
$current = array_merge($parent, [
'subnav' => [
'backups' => [
"label" => Backup::t("Backups"),
"url" => 'enupal-backup/backups'
],
'settings' => [
"label" => Backup::t("Settings"),
"url" => 'enupal-backup/settings'
]
]
]);

if (Craft::$app->getConfig()->getGeneral()->allowAdminChanges) {
$current['subnav']['settings'] = [
"label" => Backup::t("Settings"),
"url" => 'enupal-backup/settings'
];
}

return $current;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Craft;
use craft\web\Controller as BaseController;
use enupal\backup\Backup;
use yii\web\ForbiddenHttpException;

class SettingsController extends BaseController
{
Expand All @@ -23,6 +24,11 @@ class SettingsController extends BaseController
*/
public function actionSaveSettings()
{
// Make sure admin changes are allowed
if (!Craft::$app->getConfig()->getGeneral()->allowAdminChanges) {
throw new ForbiddenHttpException('Administrative changes are disallowed in this environment.');
}

$this->requirePostRequest();
$request = Craft::$app->getRequest();
$settings = $request->getBodyParam('settings');
Expand Down
12 changes: 10 additions & 2 deletions src/elements/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Craft;
use craft\base\Element;
use craft\elements\db\ElementQueryInterface;
use craft\elements\User;
use craft\helpers\UrlHelper;
use craft\elements\actions\Delete;

Expand Down Expand Up @@ -244,6 +245,14 @@ public function getStatus(): ?string
return $colors[$statusId];
}

/**
* @inheritdoc
*/
public function canView(User $user): bool
{
return true;
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -320,7 +329,6 @@ protected static function defineSortOptions(): array
protected static function defineTableAttributes(): array
{
$attributes = [];
$attributes['backupId'] = ['label' => BackupPlugin::t('Backup Id')];
$attributes['size'] = ['label' => BackupPlugin::t('Size')];
$attributes['dateCreated'] = ['label' => BackupPlugin::t('Date')];
$attributes['status'] = ['label' => BackupPlugin::t('Status')];
Expand All @@ -330,7 +338,7 @@ protected static function defineTableAttributes(): array

protected static function defineDefaultTableAttributes(string $source): array
{
$attributes = ['backupId', 'size', 'dateCreated', 'status'];
$attributes = ['size', 'dateCreated', 'status'];

return $attributes;
}
Expand Down
10 changes: 6 additions & 4 deletions src/services/Backups.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Craft;
use craft\db\Query;
use craft\fs\Local;
use craft\mail\Message;
use enupal\backup\events\NotificationEvent;
use enupal\backup\jobs\ProcessPendingBackups;
Expand All @@ -27,7 +28,6 @@

use craft\helpers\FileHelper;
use craft\errors\ShellCommandException;
use craft\volumes\Local;
use craft\helpers\App as CraftApp;
use mikehaertl\shellcommand\Command as ShellCommand;
use yii\base\Exception;
Expand Down Expand Up @@ -666,13 +666,15 @@ private function getAssetsConfigFormat($backup, $config, $settings, $syncs, $enc
$assets = Backup::$app->settings->getAllLocalVolumesObjects();
}
}

// Adding the assets
$assetFileNames = [];
foreach ($assets as $key => $asset) {
// Supports local volumes for now.
if (get_class($asset) == Local::class) {
$fs = $asset->getFs();
if (get_class($fs) == Local::class) {
// Check if the path exists
if (is_dir($asset->getRootPath())) {
if (is_dir($fs->getRootPath())) {
// So we need store assets files as json could be more than one
$assetName = 'assets-' . $asset->handle . '-' . $backup->backupId . $this->getCompressType();
$assetFileName = $assetName;
Expand All @@ -685,7 +687,7 @@ private function getAssetsConfigFormat($backup, $config, $settings, $syncs, $enc

$assetBackup = new DirectoryBackup();
$assetBackup->name = 'Asset' . $asset->id;
$assetBackup->path = $asset->getRootPath();
$assetBackup->path = $fs->getRootPath();
$assetBackup->fileName = $assetName;
$assetBackup->dirName = $this->getAssetsPath();
$assetBackup->syncs = $syncs;
Expand Down
17 changes: 14 additions & 3 deletions src/services/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

use Craft;
use craft\db\Query;
use craft\fs\Local;
use craft\helpers\App as CraftApp;
use craft\helpers\UrlHelper;
use craft\models\Volume;
use yii\base\Component;
use craft\volumes\Local;
use Google_Client;
use Google_Service_Drive;
use enupal\backup\models\Settings as SettingsModel;
Expand Down Expand Up @@ -105,8 +106,13 @@ public function getAllLocalVolumes()
$volumes = Craft::$app->getVolumes()->getAllVolumes();
$response = [];

/**
* @var $key
* @var Volume $volume
*/
foreach ($volumes as $key => $volume) {
if (get_class($volume) == Local::class) {
$fs = $volume->getFs();
if (get_class($fs) == Local::class) {
$response[] = [
'value' => $volume->id,
'label' => $volume->name
Expand All @@ -125,8 +131,13 @@ public function getAllLocalVolumesObjects()
$volumes = Craft::$app->getVolumes()->getAllVolumes();
$response = [];

/**
* @var $key
* @var Volume $volume
*/
foreach ($volumes as $key => $volume) {
if (get_class($volume) == Local::class) {
$fs = $volume->getFs();
if (get_class($fs) == Local::class) {
$response[] = $volume;
}
}
Expand Down

0 comments on commit 1d9b4c4

Please sign in to comment.