Skip to content

Commit

Permalink
update/create rebuild command
Browse files Browse the repository at this point in the history
  • Loading branch information
y4roc committed Aug 14, 2017
1 parent 7065001 commit 4381e4e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
44 changes: 20 additions & 24 deletions Command/RebuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,34 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @var $fs \Gaufrette\Filesystem
*/
$this->fs = Config::getTargetFs();
$backupList = BackupList::factory();
$backupList = new BackupList(null, true);
$this->checkKnownBackups($backupList);

foreach ($backupTypes as $type) {
$files = $this->fs->listKeys($type)["keys"];
foreach ($files as $file) {
if (false === $backupList->findByFilename($file) instanceof Backup) {
$matches = array();
preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}/', $file, $matches);
$datetime = \DateTime::createFromFormat("Y-m-d_H-i", $matches[0]);
$backup = new Backup();
$backup->setType($type);
$backup->setDateTime($datetime);
$backupList->addBackup($backup);
}
}
}

$backupList->sortByDate();

}

protected function checkKnownBackups(BackupList $backupList)
{
$updatedBackups = new ArrayCollection();
$files = $this->fs->listKeys()["keys"];
foreach ($backupList->getDumps() as $backup) {
if (in_array($backup->getAbsolutePath(), $files)) {
$updatedBackups->add($backup);

$types = array(
Backup::TYPE_DAILY,
Backup::TYPE_MONTHLY,
Backup::TYPE_WEEKLY,
Backup::TYPE_YEARLY
);

foreach ($types as $type) {
$files = $this->fs->listKeys($type);
foreach ($files['keys'] as $file) {
list($year, $month, $day, $hour, $minute) = sscanf($file, $type . '/%d-%d-%d_%d-%d.tar.gz');

$backup = new Backup();
$backup->setType($type);
$timestamp = mktime($hour, $minute, 0, $month, $day, $year);
$backup->setTimestamp($timestamp);
$backupList->addBackup($backup);
}
}
$backupList->setDumps($updatedBackups);

}

}
44 changes: 23 additions & 21 deletions Model/BackupList.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,38 @@ class BackupList implements \JsonSerializable
*/
protected $storage = array();

public function __construct($type = null)
public function __construct($type = null, $clean = false)
{
$this->storage = new ArrayCollection();
$this->type = $type;
$this->list = new ArrayCollection();

if (self::$instance instanceof self) {
return self::$instance;
}
if (false === $clean) {
if (self::$instance instanceof self) {
return self::$instance;
}

if ($this->getFile() == false) {
return $this;
}
if ($this->getFile() == false) {
return $this;
}

$json_data = $this->getFile()->getContent();
$json_data = json_decode($json_data, true);
foreach ($json_data as $k => $v) {
$backup = new Backup();
$backup->setTimestamp($v["timestamp"]);
$backup->setVersion($v["version"]);
$backup->setCommit($v["commit"]);

$this->storage->add($backup);
if (isset($v["type"])) {
$backup->setType($v["type"]);
if (isset($v["type"]) && $type != null && $type != $v["type"]) {
continue;
$json_data = $this->getFile()->getContent();
$json_data = json_decode($json_data, true);
foreach ($json_data as $k => $v) {
$backup = new Backup();
$backup->setTimestamp($v["timestamp"]);
$backup->setVersion($v["version"]);
$backup->setCommit($v["commit"]);

$this->storage->add($backup);
if (isset($v["type"])) {
$backup->setType($v["type"]);
if (isset($v["type"]) && $type != null && $type != $v["type"]) {
continue;
}
}
$this->list->add($backup);
}
$this->list->add($backup);
}
}

Expand Down

0 comments on commit 4381e4e

Please sign in to comment.