setServer($MCONF['update_servers']);
$update->setCurrentVersion($MCONF['version']);
$update->setUpdateDir('../');
$update->thingsToNotUpdate = [
'apps/',
'config/',
'content/',
'vendor/',
'templates_c'
];
//Update-Checker
if (isset($_GET['checkUpdate']))
{
//sleep(50);
if (hasPerm('update') && $MCONF['update_enabled'])
{
//Check for newer Version
try
{
$new = $update->checkUpdateAvailable();
} catch (\Exception $e)
{
echo 'Error. ' . $e->getMessage();
}
// If we have a new version, show it
if (isset($new))
{
echo $lang->get('update_new_version') . ' ' . $new['version'] . ' ' . $lang->get('update_title') . '';
if (isset($new['changelog']))
{
echo ' Changelog';
}
} else
{
echo $lang->get('update_version_current_new');
}
}
exit;
}
//Show Changelog
if (isset($_GET['showChangelog']))
{
printHeader($lang->get('update_showChangelog'));
echo '
';
if (hasPerm('update'))
{
if(isset($_GET['url']))
{
$parsedown = new Parsedown();
$change = $update->getChangelog(urldecode($_GET['url']));
echo $parsedown->parse($change);
}
else
{
echo 'Missing Url';
}
} else
{
echo msg('info', $lang->get('missing_permission'));
}
echo '
'.$lang->get('back').' ';
exit;
}
//Update
if (isset($_GET['update']))
{
printHeader($lang->get('update_title'));
if (hasPerm('update') && $MCONF['update_enabled'])
{
//Check for newer Version
try
{
$new = $update->checkUpdateAvailable();
} catch (\Exception $e)
{
echo 'Error. ' . $e->getMessage();
}
// Update if we have one
if(isset($new))
{
//Check writing permissions
if($update->updateFolderIsWritable())
{
// Download the update
if ($update->downloadUpdate($new))
{
// Check downloaded update file
if($update->verifyUpdate($new))
{
// Put the site in "under construction mode"
if (copy('../content/.system/construction2.txt', '../content/.system/construction.txt'))
{
stream_message('{user} put the site into construction mode.', 2);
// Create a backup
if($update->backupUpdateFolder())
{
// The actual update
try
{
$update->rollTheUpdate();
}
catch (\Exception $e)
{
echo msg('fail', $lang->get('update_fail_unzip'). ' ('.$e->getMessage().')');
}
// Execute migrations
$update->migrate();
// Clean afterwards
if($update->cleanup())
{
// Update new Version in Config file
$conf = \Symfony\Component\Yaml\Yaml::parse(file_get_contents('../config/config.yml'));
$conf['Versioning']['version'] = $update->getCurrentVersion();
$configfile = \Symfony\Component\Yaml\Yaml::dump($conf);
if (file_put_contents('../config/config.yml', $configfile))
{
// Disable Construction mode
if (unlink('../content/.system/construction.txt'))
{
echo msg('success', $lang->get('update_succss') . '