From 51ba6c757e6e4de81286687b2bb7043564103d77 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Sun, 27 Mar 2022 13:19:26 +0200 Subject: [PATCH] migrate customer::backups Signed-off-by: Michael Kaufmann --- customer_extras.php | 28 ++------ .../customer/tablelisting.backups.php | 68 +++++++++++++++++++ .../Froxlor/user/form-datatable.html.twig | 16 +++++ 3 files changed, 90 insertions(+), 22 deletions(-) create mode 100644 lib/tablelisting/customer/tablelisting.backups.php create mode 100644 templates/Froxlor/user/form-datatable.html.twig diff --git a/customer_extras.php b/customer_extras.php index d60bd2b6..19d4d9c0 100644 --- a/customer_extras.php +++ b/customer_extras.php @@ -291,15 +291,12 @@ if ($page == 'overview' || $page == 'htpasswds') { // check whether there is a backup-job for this customer try { - $json_result = CustomerBackups::getLocal($userinfo)->listing(); + $backup_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/customer/tablelisting.backups.php'; + $collection = (new \Froxlor\UI\Collection(\Froxlor\Api\Commands\CustomerBackups::class, $userinfo)) + ->withPagination($backup_list_data['backup_list']['columns']); } catch (Exception $e) { \Froxlor\UI\Response::dynamic_error($e->getMessage()); } - $result = json_decode($json_result, true)['data']; - $existing_backupJob = null; - if ($result['count'] > 0) { - $existing_backupJob = array_shift($result['list']); - } if (isset($_POST['send']) && $_POST['send'] == 'send') { try { @@ -309,26 +306,13 @@ if ($page == 'overview' || $page == 'htpasswds') { } \Froxlor\UI\Response::standard_success('backupscheduled'); } else { - - if (!empty($existing_backupJob)) { - $action = "abort"; - $row = $existing_backupJob['data']; - - $row['path'] = \Froxlor\FileDir::makeCorrectDir(str_replace($userinfo['documentroot'], "/", $row['destdir'])); - $row['backup_web'] = ($row['backup_web'] == '1') ? $lng['panel']['yes'] : $lng['panel']['no']; - $row['backup_mail'] = ($row['backup_mail'] == '1') ? $lng['panel']['yes'] : $lng['panel']['no']; - $row['backup_dbs'] = ($row['backup_dbs'] == '1') ? $lng['panel']['yes'] : $lng['panel']['no']; - - // overwrite backup_form after we took everything from it we needed - eval("\$backup_form = \"" . \Froxlor\UI\Template::getTemplate("extras/backup_listexisting") . "\";"); - } - $pathSelect = \Froxlor\FileDir::makePathfield($userinfo['documentroot'], $userinfo['guid'], $userinfo['guid']); $backup_data = include_once dirname(__FILE__) . '/lib/formfields/customer/extras/formfield.backup.php'; - UI::view('user/form.html.twig', [ + UI::view('user/form-datatable.html.twig', [ 'formaction' => $linker->getLink(array('section' => 'extras')), - 'formdata' => $backup_data['backup'] + 'formdata' => $backup_data['backup'], + 'tabledata' => \Froxlor\UI\Listing::format($collection, $backup_list_data['backup_list']), ]); } } diff --git a/lib/tablelisting/customer/tablelisting.backups.php b/lib/tablelisting/customer/tablelisting.backups.php new file mode 100644 index 00000000..1a31a284 --- /dev/null +++ b/lib/tablelisting/customer/tablelisting.backups.php @@ -0,0 +1,68 @@ + (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Tabellisting + * + */ + +use Froxlor\UI\Callbacks\Ftp; +use Froxlor\UI\Callbacks\Text; +use Froxlor\UI\Listing; + +return [ + 'backup_list' => [ + 'title' => $lng['error']['customerhasongoingbackupjob'], + 'icon' => 'fa-solid fa-server', + 'columns' => [ + 'destdir' => [ + 'label' => $lng['panel']['path'], + 'field' => 'data.destdir', + 'callback' => [Ftp::class, 'pathRelative'] + ], + 'backup_web' => [ + 'label' => $lng['extras']['backup_web'], + 'field' => 'data.backup_web', + 'callback' => [Text::class, 'boolean'], + ], + 'backup_mail' => [ + 'label' => $lng['extras']['backup_mail'], + 'field' => 'data.backup_mail', + 'callback' => [Text::class, 'boolean'], + ], + 'backup_dbs' => [ + 'label' => $lng['extras']['backup_dbs'], + 'field' => 'data.backup_dbs', + 'callback' => [Text::class, 'boolean'], + ] + ], + 'visible_columns' => Listing::getVisibleColumnsForListing('backup_list', [ + 'destdir', + 'backup_web', + 'backup_mail', + 'backup_dbs' + ]), + 'actions' => [ + 'delete' => [ + 'icon' => 'fa fa-trash', + 'title' => $lng['panel']['abort'], + 'class' => 'btn-warning', + 'href' => [ + 'section' => 'extras', + 'page' => 'backup', + 'action' => 'abort', + 'id' => ':id' + ], + ] + ] + ] +]; diff --git a/templates/Froxlor/user/form-datatable.html.twig b/templates/Froxlor/user/form-datatable.html.twig new file mode 100644 index 00000000..75c7830d --- /dev/null +++ b/templates/Froxlor/user/form-datatable.html.twig @@ -0,0 +1,16 @@ +{% extends "Froxlor/user/form.html.twig" %} + +{% block content %} + {% if tabledata is not empty and tabledata is iterable %} +
+ {% set type = 'warning' %} + {% set alert_msg = lng('error.customerhasongoingbackupjob') %} + {% include 'Froxlor/misc/alertbox.html.twig' %} +
+ {% import "Froxlor/table/table.html.twig" as table %} + {{ table.table(tabledata) }} + {% endif %} + + {{ parent() }} + +{% endblock %}