Skip to content

Commit afdb202

Browse files
author
Daniel Fernández Giménez
committed
fix: actualizar año de copyright y reorganizar propiedades de clase
1 parent 877af37 commit afdb202

1 file changed

Lines changed: 75 additions & 69 deletions

File tree

Controller/Backup.php

Lines changed: 75 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* This file is part of Backup plugin for FacturaScripts
4-
* Copyright (C) 2021-2025 Carlos Garcia Gomez <carlos@facturascripts.com>
4+
* Copyright (C) 2021-2026 Carlos Garcia Gomez <carlos@facturascripts.com>
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Lesser General Public License as
@@ -47,20 +47,20 @@ class Backup extends Controller
4747
/** @var array */
4848
public $backup_list = [];
4949

50-
/** @var string */
51-
public $current_charset = '';
52-
5350
/** @var string */
5451
public $cron_frequency = '';
5552

5653
/** @var int */
5754
public $cron_hour = 3;
5855

5956
/** @var int */
60-
public $cron_weekly_day = 1;
57+
public $cron_monthly_day = 1;
6158

6259
/** @var int */
63-
public $cron_monthly_day = 1;
60+
public $cron_weekly_day = 1;
61+
62+
/** @var string */
63+
public $current_charset = '';
6464

6565
/**
6666
* Return the max file size that can be uploaded.
@@ -204,6 +204,26 @@ private function checkDbBackupCharset(string $filePath): bool
204204
return false;
205205
}
206206

207+
private function createAdminUserAfterRestore(string $nick, string $password): void
208+
{
209+
$user = new User();
210+
$user->nick = $nick;
211+
$user->admin = true;
212+
$user->enabled = true;
213+
214+
if (false === $user->setPassword($password)) {
215+
Tools::log()->error('restore-admin-password-weak');
216+
return;
217+
}
218+
219+
if (false === $user->save()) {
220+
Tools::log()->error('record-save-error');
221+
return;
222+
}
223+
224+
Tools::log()->notice('restore-admin-user-created', ['%nick%' => $nick]);
225+
}
226+
207227
protected function createSqlAction(): void
208228
{
209229
if ($this->permissions->allowExport === false) {
@@ -429,6 +449,12 @@ protected function loadBackupFiles(): void
429449
$grouped = [];
430450

431451
foreach (Tools::folderScan($folder) as $file) {
452+
// solo procesamos archivos .zip o .sql, el resto los ignoramos
453+
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
454+
if (false === in_array($extension, ['zip', 'sql'], true)) {
455+
continue;
456+
}
457+
432458
// la clave del día es la parte antes del primer guion bajo (YYYYMMDD)
433459
$underscorePos = strpos($file, '_');
434460
if (false === $underscorePos) {
@@ -635,69 +661,6 @@ private function restoreBackupAction(): void
635661
$this->redirect('login');
636662
}
637663

638-
private function createAdminUserAfterRestore(string $nick, string $password): void
639-
{
640-
$user = new User();
641-
$user->nick = $nick;
642-
$user->admin = true;
643-
$user->enabled = true;
644-
645-
if (false === $user->setPassword($password)) {
646-
Tools::log()->error('restore-admin-password-weak');
647-
return;
648-
}
649-
650-
if (false === $user->save()) {
651-
Tools::log()->error('record-save-error');
652-
return;
653-
}
654-
655-
Tools::log()->notice('restore-admin-user-created', ['%nick%' => $nick]);
656-
}
657-
658-
private function updateAdminPasswordAfterRestore(string $newPassword, bool $disable2fa = false): void
659-
{
660-
// buscamos primero el usuario con nick 'admin'
661-
$user = new User();
662-
if (false === $user->load('admin')) {
663-
// si no existe, buscamos cualquier usuario con permisos de administrador
664-
$users = $user->all();
665-
$adminUser = null;
666-
foreach ($users as $u) {
667-
if ($u->admin) {
668-
$adminUser = $u;
669-
break;
670-
}
671-
}
672-
673-
if (null === $adminUser) {
674-
Tools::log()->warning('restore-no-admin-found');
675-
return;
676-
}
677-
678-
$user = $adminUser;
679-
}
680-
681-
// actualizamos la contraseña
682-
if (false === $user->setPassword($newPassword)) {
683-
Tools::log()->error('restore-admin-password-weak');
684-
return;
685-
}
686-
687-
// desactivamos la autenticación en dos pasos si se ha solicitado
688-
if ($disable2fa) {
689-
$user->two_factor_enabled = false;
690-
$user->two_factor_secret_key = null;
691-
}
692-
693-
if (false === $user->save()) {
694-
Tools::log()->error('record-save-error');
695-
return;
696-
}
697-
698-
Tools::log()->notice('restore-admin-password-updated');
699-
}
700-
701664
private function restoreFilesAction(): void
702665
{
703666
if (false === $this->validateFormToken()) {
@@ -821,4 +784,47 @@ private function unzipDatabase(string $gzFilePath): string
821784

822785
return $name;
823786
}
787+
788+
private function updateAdminPasswordAfterRestore(string $newPassword, bool $disable2fa = false): void
789+
{
790+
// buscamos primero el usuario con nick 'admin'
791+
$user = new User();
792+
if (false === $user->load('admin')) {
793+
// si no existe, buscamos cualquier usuario con permisos de administrador
794+
$users = $user->all();
795+
$adminUser = null;
796+
foreach ($users as $u) {
797+
if ($u->admin) {
798+
$adminUser = $u;
799+
break;
800+
}
801+
}
802+
803+
if (null === $adminUser) {
804+
Tools::log()->warning('restore-no-admin-found');
805+
return;
806+
}
807+
808+
$user = $adminUser;
809+
}
810+
811+
// actualizamos la contraseña
812+
if (false === $user->setPassword($newPassword)) {
813+
Tools::log()->error('restore-admin-password-weak');
814+
return;
815+
}
816+
817+
// desactivamos la autenticación en dos pasos si se ha solicitado
818+
if ($disable2fa) {
819+
$user->two_factor_enabled = false;
820+
$user->two_factor_secret_key = null;
821+
}
822+
823+
if (false === $user->save()) {
824+
Tools::log()->error('record-save-error');
825+
return;
826+
}
827+
828+
Tools::log()->notice('restore-admin-password-updated');
829+
}
824830
}

0 commit comments

Comments
 (0)