1
0
mirror of https://github.com/Mowie/Mowie synced 2024-06-17 07:54:08 +00:00

Finished implementing of new update mechanism

This commit is contained in:
kolaente 2017-10-06 00:12:03 +02:00
parent e8e1ff2451
commit a485c1763c
3 changed files with 72 additions and 24 deletions

View File

@ -11,8 +11,7 @@ $update->thingsToNotUpdate = [
'config/',
'content/',
'vendor/',
'templates_c',
'docker-dev'
'templates_c'
];
//Update-Checker
@ -124,10 +123,10 @@ if (isset($_GET['update']))
if($update->cleanup())
{
// Update new Version in Config file
$conf = \Symfony\Component\Yaml\Yaml::parse(file_get_contents('../config.yml'));
$conf = \Symfony\Component\Yaml\Yaml::parse(file_get_contents('../config/config.yml'));
$conf['Versioning']['version'] = $update->getCurrentVersion();
$configfile = \Symfony\Component\Yaml\Yaml::dump($CONFIG);
$configfile = \Symfony\Component\Yaml\Yaml::dump($conf);
if (file_put_contents('../config/config.yml', $configfile))
{
// Disable Construction mode

View File

@ -13,6 +13,8 @@ class updater
private $updateServer;
private $updateDir;
private $newUpdateFiles;
/**
* Every file/folder, including subdirectories which should not be updated or deleted after the update.
* @var string
@ -263,6 +265,18 @@ class updater
// Upzip the downloaded update
$zippy = Zippy::load();
$update = $zippy->open('.update.tmp.zip');
foreach ($update as $file)
{
$name = $this->updateDir . '/' . $file->getLocation();
if ($file->isDir())
{
$name = substr($name, 0, strlen($name) - 1);
}
$this->newUpdateFiles[] = $name;
}
if (!$update->extract($this->updateDir))
{
throw new \Exception('Could not extract the update!');
@ -293,17 +307,27 @@ class updater
*/
public function cleanup()
{
// cleanup downloaded zips
$success = unlink('.update.tmp.zip');
$success = unlink('.update-backup.zip');
// Delete all Files which don't exist anymore in the update. Ommit everything in $filesToNotUpdate
$diff = array_diff($this->getDirContents($this->updateDir), $update);
$diff = array_diff($this->getDirContents($this->updateDir), $this->newUpdateFiles);
foreach ($diff as $file)
{
if (is_dir($file))
{
$success = $this->rrmdir($file);
} else
{
// Empty files wont show up in the zip, which is why we check this here.
if(filesize($file) != 0)
{
$success = unlink($file);
}
}
}
// cleanup downloaded zips
$success = unlink('.update.tmp.zip');
$success = unlink('.update-backup.zip');
return $success;
}
@ -427,4 +451,29 @@ class updater
return preg_replace($search, $replace, $subject, 1);
}
/**
* Deletes a non-empty folder
* @param $dir
* @return bool
*/
private function rrmdir($dir)
{
if (is_dir($dir))
{
$objects = scandir($dir);
foreach ($objects as $object)
{
if ($object != "." && $object != "..")
{
if (filetype($dir . "/" . $object) == "dir") $this->rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object);
}
}
reset($objects);
return rmdir($dir);
} else
{
return false;
}
}
}

View File

@ -2,6 +2,6 @@ User-Agent: *
Disallow: /admin/
Disallow: /apps/
Disallow: /cache/
Disallow: /Files/
Disallow: /vendor/
Disallow: /inc/
Disallow: /templates_c/