2015-07-03 00:00:30 +02:00
|
|
|
<?php
|
2020-04-16 17:57:14 +02:00
|
|
|
|
2015-07-10 19:07:14 +02:00
|
|
|
namespace Shikiryu\Backup\Backup;
|
2015-07-03 00:00:30 +02:00
|
|
|
|
2020-04-16 17:57:14 +02:00
|
|
|
use Shikiryu\Exceptions\BackupException;
|
|
|
|
|
2015-07-10 19:07:14 +02:00
|
|
|
class Files extends BackupAbstract
|
2015-07-03 00:00:30 +02:00
|
|
|
{
|
2020-04-16 17:57:14 +02:00
|
|
|
use IsLocalTrait;
|
|
|
|
|
2015-07-03 00:00:30 +02:00
|
|
|
/**
|
2015-07-10 23:13:46 +02:00
|
|
|
* @param array $config
|
2020-04-16 17:57:14 +02:00
|
|
|
* @throws BackupException
|
2015-07-03 00:00:30 +02:00
|
|
|
*/
|
2020-04-16 17:57:14 +02:00
|
|
|
public function __construct(array $config = [])
|
2015-07-03 00:00:30 +02:00
|
|
|
{
|
2015-07-10 23:13:46 +02:00
|
|
|
if (!isset($config['files'])) {
|
2020-04-16 17:57:14 +02:00
|
|
|
throw new BackupException('Files needs a "files" configuration.');
|
2015-07-10 23:13:46 +02:00
|
|
|
}
|
|
|
|
$filesToBackup = $config['files'];
|
2019-01-25 21:39:18 +01:00
|
|
|
if (!empty($filesToBackup) && is_array($filesToBackup)) {
|
2019-01-25 22:19:50 +01:00
|
|
|
$names = array_map('basename', $filesToBackup);
|
2019-01-25 21:39:18 +01:00
|
|
|
$this->files_to_backup = array_combine($filesToBackup, $names);
|
2015-07-03 00:00:30 +02:00
|
|
|
}
|
2015-08-18 17:02:37 +02:00
|
|
|
parent::__construct($config);
|
2015-07-03 00:00:30 +02:00
|
|
|
}
|
|
|
|
|
2019-01-25 21:39:18 +01:00
|
|
|
/**
|
|
|
|
* Check if the backup is valid
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*
|
|
|
|
* @SuppressWarnings("unused")
|
|
|
|
*/
|
2020-04-16 17:57:14 +02:00
|
|
|
public function isValid(): bool
|
2015-07-03 00:00:30 +02:00
|
|
|
{
|
2015-07-12 20:34:54 +02:00
|
|
|
$result = true;
|
2016-07-03 21:54:35 +02:00
|
|
|
foreach ($this->files_to_backup as $file => $name) {
|
2015-07-12 20:34:54 +02:00
|
|
|
if (!file_exists($file)) {
|
|
|
|
$result = false;
|
|
|
|
break;
|
|
|
|
}
|
2015-07-03 00:00:30 +02:00
|
|
|
}
|
2015-07-12 20:34:54 +02:00
|
|
|
return $result;
|
2015-07-03 00:00:30 +02:00
|
|
|
}
|
2019-01-25 21:39:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that can be used to initialize the backup
|
|
|
|
*/
|
2015-08-18 17:02:37 +02:00
|
|
|
protected function preBuild()
|
|
|
|
{
|
|
|
|
// TODO: Implement preBuild() method.
|
|
|
|
}
|
|
|
|
|
2019-01-25 21:39:18 +01:00
|
|
|
/**
|
|
|
|
* Function that can be used after the backup
|
|
|
|
*/
|
2015-08-18 17:02:37 +02:00
|
|
|
protected function postBuild()
|
|
|
|
{
|
|
|
|
// TODO: Implement postBuild() method.
|
|
|
|
}
|
|
|
|
|
2019-01-25 21:39:18 +01:00
|
|
|
/**
|
|
|
|
* Mandatory function doing the backup
|
|
|
|
*/
|
2015-08-18 17:02:37 +02:00
|
|
|
protected function build()
|
|
|
|
{
|
|
|
|
// TODO: Implement build() method.
|
|
|
|
}
|
2015-07-03 00:00:30 +02:00
|
|
|
}
|