Skip to content

Commit c277a47

Browse files
author
Carlos Garcia
committed
Modificado el modelo AttachedFile para usar las nuevas clases.
1 parent b0d40b0 commit c277a47

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

Core/Model/AttachedFile.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* This file is part of FacturaScripts
4-
* Copyright (C) 2018-2024 Carlos Garcia Gomez <carlos@facturascripts.com>
4+
* Copyright (C) 2018-2025 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
@@ -22,8 +22,8 @@
2222
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
2323
use FacturaScripts\Core\Cache;
2424
use FacturaScripts\Core\Lib\MyFilesToken;
25-
use FacturaScripts\Core\Model\Base\ModelOnChangeClass;
26-
use FacturaScripts\Core\Model\Base\ModelTrait;
25+
use FacturaScripts\Core\Template\ModelClass;
26+
use FacturaScripts\Core\Template\ModelTrait;
2727
use FacturaScripts\Core\Tools;
2828
use finfo;
2929

@@ -33,7 +33,7 @@
3333
* @author Carlos García Gómez <carlos@facturascripts.com>
3434
* @author Francesc Pineda Segarra <francesc.pineda.segarra@gmail.com>
3535
*/
36-
class AttachedFile extends ModelOnChangeClass
36+
class AttachedFile extends ModelClass
3737
{
3838
use ModelTrait;
3939

@@ -252,16 +252,11 @@ protected function getNextCode(): int
252252
return $this->newCode();
253253
}
254254

255-
/**
256-
* @param string $field
257-
*
258-
* @return bool
259-
*/
260-
protected function onChange($field)
255+
protected function onChange(string $field): bool
261256
{
262257
switch ($field) {
263258
case 'path':
264-
if ($this->previousData['path']) {
259+
if ($this->getOriginal('path')) {
265260
// remove old file
266261
unlink(FS_FOLDER . '/' . $this->previousData['path']);
267262
}
@@ -310,10 +305,4 @@ protected function setFile(): bool
310305

311306
return true;
312307
}
313-
314-
protected function setPreviousData(array $fields = [])
315-
{
316-
$more = ['path'];
317-
parent::setPreviousData(array_merge($more, $fields));
318-
}
319308
}

Test/Core/Model/AttachedFileTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121

2222
use FacturaScripts\Core\Model\AttachedFile;
2323
use FacturaScripts\Core\Tools;
24+
use FacturaScripts\Test\Traits\LogErrorsTrait;
2425
use PHPUnit\Framework\TestCase;
2526

2627
final class AttachedFileTest extends TestCase
2728
{
29+
use LogErrorsTrait;
30+
2831
public function testSaveFile(): void
2932
{
3033
$original = 'xss_img_src_onerror_alert(123).jpeg';
@@ -94,4 +97,9 @@ public function testDontReuseIds(): void
9497
// eliminamos el archivo
9598
$this->assertTrue($att2->delete(), 'can-not-delete-file');
9699
}
100+
101+
protected function tearDown(): void
102+
{
103+
$this->logErrors();
104+
}
97105
}

0 commit comments

Comments
 (0)