System update (detect new version)

This commit is contained in:
markseu 2017-06-21 17:57:20 +02:00
parent 9ab2ad06e9
commit 93205fcbfc
3 changed files with 23 additions and 15 deletions

View file

@ -48,7 +48,7 @@ Parser: markdown
ParserSafeMode: 0
MultiLanguageMode: 0
InstallationMode: 1
StartupUpdateNotification: none
StartupUpdate: none
UpdatePluginsUrl: https://github.com/datenstrom/yellow-plugins
UpdateThemesUrl: https://github.com/datenstrom/yellow-themes
UpdateInformationFile: update.ini

View file

@ -76,7 +76,7 @@ class YellowCore
$this->config->setDefault("parserSafeMode", "0");
$this->config->setDefault("multiLanguageMode", "0");
$this->config->setDefault("installationMode", "0");
$this->config->setDefault("startupUpdateNotification", "none");
$this->config->setDefault("startupUpdate", "none");
}
function __destruct()
@ -103,7 +103,7 @@ class YellowCore
// Handle startup
function startup()
{
$tokens = explode(',', $this->config->get("startupUpdateNotification"));
$tokens = explode(',', $this->config->get("startupUpdate"));
foreach($this->plugins->plugins as $key=>$value)
{
if(method_exists($value["obj"], "onStartup")) $value["obj"]->onStartup(in_array($value["plugin"], $tokens));
@ -112,10 +112,10 @@ class YellowCore
{
if(method_exists($value["obj"], "onStartup")) $value["obj"]->onStartup(in_array($value["theme"], $tokens));
}
if($this->config->get("startupUpdateNotification")!="none")
if($this->config->get("startupUpdate")!="none")
{
$fileNameConfig = $this->config->get("configDir").$this->config->get("configFile");
$this->config->update($fileNameConfig, array("startupUpdateNotification" => "none"));
$this->config->update($fileNameConfig, array("startupUpdate" => "none"));
}
if(defined("DEBUG") && DEBUG>=2) echo "YellowCore::startup<br/>\n";
}

View file

@ -23,14 +23,11 @@ class YellowUpdate
// Handle startup
function onStartup($update)
{
if(!$this->yellow->config->isExisting("startupUpdateNotification")) //TODO: remove later, detects old version
if(!$this->yellow->config->isExisting("startupUpdate")) //TODO: remove later, detects old version
{
$update = true;
$fileNameConfig = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
$this->yellow->config->update($fileNameConfig, array("startupUpdateNotification" => "none"));
$fileData = $this->yellow->toolbox->readFile("yellow.php");
$fileData = preg_replace("#yellow->plugins->load\(\)#", "yellow->load()", $fileData);
$this->yellow->toolbox->createFile("yellow.php", $fileData);
$this->yellow->config->update($fileNameConfig, array("startupUpdate" => "none"));
}
if($update) //TODO: remove later, converts old config
{
@ -66,6 +63,16 @@ class YellowUpdate
$_GET["clean-url"] = "theme-has-been-updated";
}
}
if($update) //TODO: remove later, converts old script
{
$fileName = "yellow.php";
if(is_file($fileName))
{
$fileData = $this->yellow->toolbox->readFile($fileName);
$fileDataNew = preg_replace("#yellow->plugins->load\(\)#", "yellow->load()", $fileData);
if($fileData!=$fileDataNew) $this->yellow->toolbox->createFile($fileName, $fileDataNew);
}
}
if($update) //TODO: remove later, converts old error page
{
$fileName = $this->yellow->config->get("configDir")."page-error-500.txt";
@ -287,6 +294,7 @@ class YellowUpdate
function updateSoftware($force = false)
{
$statusCode = 200;
opcache_reset();
$path = $this->yellow->config->get("pluginDir");
foreach($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry)
{
@ -469,12 +477,12 @@ class YellowUpdate
function updateSoftwareNotification($software)
{
$statusCode = 200;
$startupUpdateNotification = $this->yellow->config->get("startupUpdateNotification");
if($startupUpdateNotification=="none") $startupUpdateNotification = "";
if(!empty($startupUpdateNotification)) $startupUpdateNotification .= ",";
$startupUpdateNotification .= $software;
$startupUpdate = $this->yellow->config->get("startupUpdate");
if($startupUpdate=="none") $startupUpdate = "";
if(!empty($startupUpdate)) $startupUpdate .= ",";
$startupUpdate .= $software;
$fileNameConfig = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
if(!$this->yellow->config->update($fileNameConfig, array("startupUpdateNotification" => $startupUpdateNotification)))
if(!$this->yellow->config->update($fileNameConfig, array("startupUpdate" => $startupUpdate)))
{
$statusCode = 500;
$this->yellow->page->error(500, "Can't write file '$fileNameConfig'!");