NuBOXDevCom /
Database-Backup
| 1 | <?php |
||
| 2 | |||
| 3 | namespace NDC\DatabaseBackup; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Class FileManager |
||
| 7 | * @package NDC\DatabaseBackup |
||
| 8 | */ |
||
| 9 | class FileManager |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | private $params; |
||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | private $files = []; |
||
| 19 | /** |
||
| 20 | * @var self |
||
| 21 | */ |
||
| 22 | private static $_instance; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @return FileManager|null |
||
| 26 | */ |
||
| 27 | public static function getInstance(): ?self |
||
| 28 | { |
||
| 29 | |||
| 30 | if (self::$_instance === null) { |
||
| 31 | self::$_instance = new self; |
||
| 32 | } |
||
| 33 | return self::$_instance; |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * FileManager constructor. |
||
| 38 | */ |
||
| 39 | public function __construct() |
||
| 40 | { |
||
| 41 | System::getInstance(); |
||
|
0 ignored issues
–
show
|
|||
| 42 | $this->params = [ |
||
| 43 | 'files_path' => env('FILES_PATH_TO_SAVE_BACKUP', './Backups'), |
||
| 44 | 'days_interval' => env('FILES_DAYS_HISTORY', 3) |
||
| 45 | ]; |
||
| 46 | $this->_getFiles(); |
||
| 47 | env('FILES_DAYS_HISTORY', 3) > 0 ?: $this->removeOldFilesByIntervalDays(); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | private function _getFiles(): void |
||
| 54 | { |
||
| 55 | $files = scandir($this->params['files_path'], SCANDIR_SORT_ASCENDING); |
||
| 56 | $this->files = array_filter($files, function ($k) { |
||
| 57 | $return = []; |
||
| 58 | if ($k !== '..' && $k !== '.') { |
||
| 59 | $return[] = $k; |
||
| 60 | } |
||
| 61 | return $return; |
||
| 62 | }); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return void |
||
| 67 | */ |
||
| 68 | private function removeOldFilesByIntervalDays(): void |
||
| 69 | { |
||
| 70 | $time_before = time() - $this->params['days_interval'] * 86400; |
||
| 71 | foreach ($this->files as $file) { |
||
| 72 | $f = explode('-', $file); |
||
| 73 | $f = str_replace('.sql', '', $f); |
||
| 74 | if ($f[1] < $time_before) { |
||
| 75 | @unlink($this->params['files_path'] . '/' . $file); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths