Browse Source

added custom backup location FR#160

CauseFX 3 years ago
parent
commit
072cea5943
3 changed files with 19 additions and 6 deletions
  1. 2 1
      api/classes/organizr.class.php
  2. 2 1
      api/config/default.php
  3. 15 4
      api/functions/backup-functions.php

+ 2 - 1
api/classes/organizr.class.php

@@ -2431,6 +2431,7 @@ class Organizr
 				$this->settingsOption('enable', 'autoBackupCronEnabled', ['label' => 'Auto-Backup Organizr']),
 				$this->settingsOption('cron', 'autoBackupCronSchedule'),
 				$this->settingsOption('number', 'keepBackupsCountCron', ['label' => '# Backups Keep', 'help' => 'Number of backups to keep', 'attr' => 'min="1"']),
+				$this->settingsOption('folder', 'backupLocation', ['label' => 'Backup Save Path', 'help' => 'Folder path to save Organizr Backups - Please test before saving', 'value' => $this->getOrganizrBackupLocation()]),
 				$this->settingsOption('blank'),
 
 			],
@@ -6047,7 +6048,7 @@ class Organizr
 				}
 				$this->setAPIResponse('success', '', 200, $sponsors);
 				return $sponsors;
-			} catch (\PHPHtmlParser\Exceptions\ChildNotFoundException | \PHPHtmlParser\Exceptions\CircularException | \PHPHtmlParser\Exceptions\LogicalException | \PHPHtmlParser\Exceptions\StrictException | \PHPHtmlParser\Exceptions\ContentLengthException | \PHPHtmlParser\Exceptions\NotLoadedException $e) {
+			} catch (\PHPHtmlParser\Exceptions\ChildNotFoundException|\PHPHtmlParser\Exceptions\CircularException|\PHPHtmlParser\Exceptions\LogicalException|\PHPHtmlParser\Exceptions\StrictException|\PHPHtmlParser\Exceptions\ContentLengthException|\PHPHtmlParser\Exceptions\NotLoadedException $e) {
 				$this->setAPIResponse('error', 'Error connecting to Github', 409);
 				return false;
 			}

+ 2 - 1
api/config/default.php

@@ -373,7 +373,7 @@ return [
 	'homepageOrderBookmarks' => '40',
 	'homepageOrderDonate' => '41',
 	'homepageOrderAdguard' => '42',
-  'homepageOrderProwlarr' => '43',
+	'homepageOrderProwlarr' => '43',
 	'homepageShowStreamNames' => false,
 	'homepageShowStreamNamesAuth' => '1',
 	'homepageShowStreamNamesWithoutIp' => false,
@@ -684,6 +684,7 @@ return [
 	'autoBackupCronEnabled' => false,
 	'autoBackupCronSchedule' => '@weekly',
 	'keepBackupsCountCron' => '20',
+	'backupLocation' => '',
 	'useRandomMediaImage' => false,
 	'sendLogsToSlack' => false,
 	'slackLogLevel' => 'WARNING',

+ 15 - 4
api/functions/backup-functions.php

@@ -2,6 +2,17 @@
 
 trait BackupFunctions
 {
+	public function getOrganizrBackupLocation()
+	{
+		$defaultPath = $this->config['dbLocation'] . 'backups' . DIRECTORY_SEPARATOR;
+		$userPath = $this->config['backupLocation'];
+		if ($this->config['backupLocation'] !== '') {
+			if (file_exists($userPath)) {
+				return $userPath;
+			}
+		}
+		return $defaultPath;
+	}
 
 	public function fileArray($files)
 	{
@@ -18,7 +29,7 @@ trait BackupFunctions
 	public function deleteBackup($filename)
 	{
 		$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
-		$path = $this->config['dbLocation'] . 'backups' . DIRECTORY_SEPARATOR;
+		$path = $this->getOrganizrBackupLocation();
 		$filename = $path . $filename;
 		if ($ext == 'zip') {
 			if (file_exists($filename)) {
@@ -37,7 +48,7 @@ trait BackupFunctions
 
 	public function downloadBackup($filename)
 	{
-		$path = $this->config['dbLocation'] . 'backups' . DIRECTORY_SEPARATOR;
+		$path = $this->getOrganizrBackupLocation();
 		$filename = $path . $filename;
 		if (file_exists($filename)) {
 			header('Content-Type: application/zip');
@@ -54,7 +65,7 @@ trait BackupFunctions
 
 	public function backupOrganizr($type = 'config')
 	{
-		$directory = $this->config['dbLocation'] . 'backups' . DIRECTORY_SEPARATOR;
+		$directory = $this->getOrganizrBackupLocation();
 		@mkdir($directory, 0770, true);
 		switch ($type) {
 			case 'config':
@@ -115,7 +126,7 @@ trait BackupFunctions
 
 	public function getBackups()
 	{
-		$path = $this->config['dbLocation'] . 'backups' . DIRECTORY_SEPARATOR;
+		$path = $this->getOrganizrBackupLocation();
 		@mkdir($path, 0770, true);
 		$files = array_diff(scandir($path), array('.', '..'));
 		$fileList = [];