From 0219edb4b1ad07bdbd6fdc858fb2241d43749494 Mon Sep 17 00:00:00 2001 From: tadhgboyle Date: Sat, 24 May 2025 16:53:46 -0700 Subject: [PATCH 01/16] Add backup feature --- .gitignore | 1 + composer.json | 3 +- core/classes/Core/Util.php | 14 ++ .../panel_templates/Default/core/backups.tpl | 120 ++++++++++++++ .../core/debugging_and_maintenance.tpl | 6 +- modules/Core/classes/Tasks/Backup.php | 147 ++++++++++++++++++ modules/Core/language/en_UK.json | 8 + modules/Core/module.php | 1 + modules/Core/pages/panel/backups.php | 135 ++++++++++++++++ .../pages/panel/debugging_and_maintenance.php | 7 + 10 files changed, 440 insertions(+), 2 deletions(-) create mode 100644 custom/panel_templates/Default/core/backups.tpl create mode 100644 modules/Core/classes/Tasks/Backup.php create mode 100644 modules/Core/pages/panel/backups.php diff --git a/.gitignore b/.gitignore index 0e69ddeac7..df9931cce2 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ composer.lock checksums.json /.node_cache/ /release/ +/backups/ diff --git a/composer.json b/composer.json index ac55acfb57..950a2855e2 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "geoip2/geoip2": "^3.0", "jenssegers/agent": "^2.6", "php-di/php-di": "^7.0", - "twig/twig": "^3.0" + "twig/twig": "^3.0", + "druidfi/mysqldump-php": "^2.0" }, "require-dev": { "phpstan/phpstan": "1.6.9", diff --git a/core/classes/Core/Util.php b/core/classes/Core/Util.php index aeb007627a..348f324b15 100644 --- a/core/classes/Core/Util.php +++ b/core/classes/Core/Util.php @@ -303,4 +303,18 @@ public static function isCompatible(string $version, string $nameless_version): return $major == $nameless_major && $minor == $nameless_minor; } + + /** + * Format bytes into a human-readable string. + * + * @param int $bytes Number of bytes to format. + * @return string Formatted string. + */ + public static function formatBytes(int $bytes): string + { + $sizes = ['B', 'KB', 'MB', 'GB', 'TB']; + $factor = floor((strlen($bytes) - 1) / 3); + + return sprintf("%.2f", $bytes / pow(1024, $factor)) . ' ' . $sizes[$factor]; + } } diff --git a/custom/panel_templates/Default/core/backups.tpl b/custom/panel_templates/Default/core/backups.tpl new file mode 100644 index 0000000000..7c36c3b421 --- /dev/null +++ b/custom/panel_templates/Default/core/backups.tpl @@ -0,0 +1,120 @@ +{include file='header.tpl'} + + + + +
+ + + {include file='sidebar.tpl'} + + +
+ + +
+ + + {include file='navbar.tpl'} + + +
+ + +
+

{$DEBUGGING_AND_MAINTENANCE}

+ +
+ + + {include file='includes/update.tpl'} + +
+
+ +
{$BACKUPS}
+ + +
+ + + {include file='includes/alerts.tpl'} + +
+
+
{$INFO}
+ {$BACKUPS_INFO} +
+
+ +
+ + +
{if isset($EXISTING_BACKUPS) && count($EXISTING_BACKUPS) > 0}Existing Backups{/if}
+ + {if isset($EXISTING_BACKUPS) && count($EXISTING_BACKUPS) > 0} +
+ + + + + + + + + + + {foreach from=$EXISTING_BACKUPS item=backup} + + + + + + + {/foreach} + +
{$FILENAME}{$DATE_CREATED}{$FILE_SIZE}Actions
{$backup.filename}{$backup.date}{$backup.size} + + {$DOWNLOAD} + +
+
+ {else} +
+ {$NO_BACKUPS} +
+ {/if} + +
+
+ + +
+ + +
+ + +
+ + {include file='footer.tpl'} + + +
+ + +
+ + {include file='scripts.tpl'} + + + + diff --git a/custom/panel_templates/Default/core/debugging_and_maintenance.tpl b/custom/panel_templates/Default/core/debugging_and_maintenance.tpl index 546c2bbdff..a1c19677e7 100644 --- a/custom/panel_templates/Default/core/debugging_and_maintenance.tpl +++ b/custom/panel_templates/Default/core/debugging_and_maintenance.tpl @@ -36,7 +36,11 @@
{if isset($ERROR_LOGS)} - {$ERROR_LOGS} + {$ERROR_LOGS} + {/if} + + {if isset($BACKUPS_LINK)} + {$BACKUPS} {/if}