commit b035c4838cea1dad0f9fcd3c236a07d04b6f535a
parent 5cabfcfed1d5e4b829a16002e7ab8a5890b77df0
Author: markseu <mark2011@mayberg.se>
Date: Fri, 15 Jul 2016 18:35:11 +0200
System update (better installation)
Diffstat:
4 files changed, 70 insertions(+), 35 deletions(-)
diff --git a/system/plugins/commandline.php b/system/plugins/commandline.php
@@ -5,7 +5,7 @@
// Command line plugin
class YellowCommandline
{
- const Version = "0.6.12";
+ const Version = "0.6.13";
var $yellow; //access to API
var $files; //number of files
var $errors; //number of errors
@@ -249,7 +249,7 @@ class YellowCommandline
$path = rtrim(empty($path) ? $this->yellow->config->get("staticDir") : $path, '/');
if(empty($location))
{
- $statusCode = max($statusCode, $this->commandForward("clean"));
+ $statusCode = max($statusCode, $this->commandBroadcast("clean", "all"));
$statusCode = max($statusCode, $this->cleanStaticDirectory($path));
} else {
$statusCode = $this->cleanStaticFile($path, $location);
@@ -288,18 +288,18 @@ class YellowCommandline
return $statusCode;
}
- // Forward command to other plugins
- function commandForward($args)
+ // Broadcast command to other plugins
+ function commandBroadcast($args)
{
$statusCode = 0;
foreach($this->yellow->plugins->plugins as $key=>$value)
{
- if(method_exists($value["obj"], "onCommand") && $found)
+ if($key == "commandline") continue;
+ if(method_exists($value["obj"], "onCommand"))
{
$statusCode = $value["obj"]->onCommand(func_get_args());
if($statusCode != 0) break;
}
- if($key == "commandline") $found = true;
}
return $statusCode;
}
@@ -345,6 +345,7 @@ class YellowCommandline
if(!empty($path))
{
if($path == rtrim($this->yellow->config->get("staticDir"), '/')) $ok = true;
+ if($path == rtrim($this->yellow->config->get("trashDir"), '/')) $ok = true;
if(is_file("$path/".$this->yellow->config->get("staticDefaultFile"))) $ok = true;
if(is_file("$path/yellow.php")) $ok = false;
}
diff --git a/system/plugins/core.php b/system/plugins/core.php
@@ -261,13 +261,13 @@ class YellowCore
if($statusCode != 0) break;
}
}
- $this->toolbox->timerStop($time);
if($statusCode == 0)
{
$statusCode = 400;
list($command) = func_get_args();
echo "Yellow $command: Command not found\n";
}
+ $this->toolbox->timerStop($time);
if(defined("DEBUG") && DEBUG>=1) echo "YellowCore::command time:$time ms<br/>\n";
return $statusCode;
}
@@ -1604,6 +1604,11 @@ class YellowPlugins
global $yellow;
require_once($entry);
}
+ $callback = function($a, $b)
+ {
+ return $a["priority"] - $b["priority"];
+ };
+ uasort($this->plugins, $callback);
foreach($this->plugins as $key=>$value)
{
$this->plugins[$key]["obj"] = new $value["plugin"];
@@ -1613,13 +1618,15 @@ class YellowPlugins
}
// Register plugin
- function register($name, $plugin, $version)
+ function register($name, $plugin, $version, $priority = 0)
{
if(!$this->isExisting($name))
{
+ if($priority == 0) $priority = count($this->plugins) + 10;
$this->plugins[$name] = array();
$this->plugins[$name]["plugin"] = $plugin;
$this->plugins[$name]["version"] = $version;
+ $this->plugins[$name]["priority"] = $priority;
}
}
@@ -2713,7 +2720,7 @@ class YellowToolbox
}
}
}
- if($sort) natsort($entries);
+ if($sort) natcasesort($entries);
closedir($dirHandle);
}
return $entries;
diff --git a/system/plugins/update.php b/system/plugins/update.php
@@ -5,7 +5,7 @@
// Update plugin
class YellowUpdate
{
- const Version = "0.6.2";
+ const Version = "0.6.3";
var $yellow; //access to API
// Handle initialisation
@@ -38,7 +38,7 @@ class YellowUpdate
switch($command)
{
case "update": $statusCode = $this->updateCommand($args); break;
- default: $statusCode = 0;
+ default: $statusCode = $this->updateAutomaticCommand($args); break;
}
return $statusCode;
}
@@ -72,22 +72,45 @@ class YellowUpdate
}
return $statusCode;
}
+
+ // Update software automatically
+ function updateAutomaticCommand($args)
+ {
+ $statusCode = $this->update();
+ if($statusCode != 0)
+ {
+ if($statusCode == 500) echo "ERROR updating files: ".$this->yellow->page->getStatusCode(true)."\n";
+ echo "Yellow has ".($statusCode!=200 ? "not " : "")."been updated: Please run command again\n";
+ }
+ return $statusCode;
+ }
- // Update software
+ // Update downloaded software
function update()
{
$statusCode = 0;
- $path = $this->yellow->config->get("pluginDir");
- foreach($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry)
+ foreach($this->yellow->plugins->plugins as $key=>$value)
{
- if(defined("DEBUG") && DEBUG>=2) echo "YellowUpdate::update file:$entry<br/>\n";
- $statusCode = max($statusCode, $this->updateSoftwareArchive($entry));
+ if(method_exists($value["obj"], "onUpdate"))
+ {
+ $statusCode = $value["obj"]->onUpdate($this->yellow->getRequestHandler());
+ if($statusCode != 0) break;
+ }
}
- $path = $this->yellow->config->get("themeDir");
- foreach($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry)
+ if($statusCode == 0)
{
- if(defined("DEBUG") && DEBUG>=2) echo "YellowUpdate::update file:$entry<br/>\n";
- $statusCode = max($statusCode, $this->updateSoftwareArchive($entry));
+ $path = $this->yellow->config->get("pluginDir");
+ foreach($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry)
+ {
+ if(defined("DEBUG") && DEBUG>=2) echo "YellowUpdate::update file:$entry<br/>\n";
+ $statusCode = max($statusCode, $this->updateSoftwareArchive($entry));
+ }
+ $path = $this->yellow->config->get("themeDir");
+ foreach($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry)
+ {
+ if(defined("DEBUG") && DEBUG>=2) echo "YellowUpdate::update file:$entry<br/>\n";
+ $statusCode = max($statusCode, $this->updateSoftwareArchive($entry));
+ }
}
return $statusCode;
}
@@ -118,9 +141,10 @@ class YellowUpdate
if(!empty($software) && !empty($matches[1]) && !empty($matches[2]))
{
list($fileName, $flags) = explode(',', $matches[2], 2);
- $metaData = $zip->statName($pathBase.$fileName);
$rawData = $zip->getFromName($pathBase.$fileName);
- $statusCode = $this->updateSoftwareFile($matches[1], $metaData["mtime"], $rawData, $flags, $software);
+ $metaData = $zip->statName($pathBase.$fileName);
+ $modified = $metaData ? $metaData["mtime"] : 0;
+ $statusCode = $this->updateSoftwareFile($matches[1], $rawData, $modified, $flags, $software);
if($statusCode != 200) break;
}
}
@@ -129,25 +153,24 @@ class YellowUpdate
{
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't delete file '$path'!");
-
}
}
return $statusCode;
}
// Update software file
- function updateSoftwareFile($fileName, $modified, $rawData, $flags, $software)
+ function updateSoftwareFile($fileName, $rawData, $modified, $flags, $software)
{
$statusCode = 200;
$fileName = $this->yellow->toolbox->normaliseTokens($fileName);
if($this->yellow->lookup->isValidFile($fileName) && !empty($flags))
{
$create = $update = $delete = false;
- if(preg_match("/create/i", $flags) && !empty($rawData)) $create = true;
- if(preg_match("/update/i", $flags) && !empty($rawData)) $update = true;
- if(preg_match("/delete/i", $flags)) $delete = true;
+ if(preg_match("/create/i", $flags) && !is_file($fileName) && !empty($rawData)) $create = true;
+ if(preg_match("/update/i", $flags) && is_file($fileName) && !empty($rawData)) $update = true;
+ if(preg_match("/delete/i", $flags) && is_file($fileName)) $delete = true;
if(preg_match("/optional/i", $flags) && $this->isSoftware($software)) $create = $update = $delete = false;
- if($create && !is_file($fileName))
+ if($create)
{
if(!$this->yellow->toolbox->createFile($fileName, $rawData, true) ||
!$this->yellow->toolbox->modifyFile($fileName, $modified))
@@ -156,7 +179,7 @@ class YellowUpdate
$this->yellow->page->error($statusCode, "Can't create file '$fileName'!");
}
}
- if($update && is_file($fileName))
+ if($update)
{
if(!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->config->get("trashDir")) ||
!$this->yellow->toolbox->createFile($fileName, $rawData) ||
@@ -166,7 +189,7 @@ class YellowUpdate
$this->yellow->page->error($statusCode, "Can't update file '$fileName'!");
}
}
- if($delete && is_file($fileName))
+ if($delete)
{
if(!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->config->get("trashDir")))
{
@@ -179,7 +202,7 @@ class YellowUpdate
return $statusCode;
}
- // Process request to install updates
+ // Process request to update software
function processRequestUpdate($serverScheme, $serverName, $base, $location, $fileName)
{
$statusCode = 0;
@@ -388,5 +411,5 @@ class YellowUpdate
}
}
-$yellow->plugins->register("update", "YellowUpdate", YellowUpdate::Version);
+$yellow->plugins->register("update", "YellowUpdate", YellowUpdate::Version, 1);
?>
\ No newline at end of file
diff --git a/system/plugins/webinterface.php b/system/plugins/webinterface.php
@@ -125,9 +125,13 @@ class YellowWebinterface
function cleanCommand($args)
{
$statusCode = 0;
- $fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
- if(!$this->users->clean($fileNameUser)) $statusCode = 500;
- if($statusCode == 500) echo "ERROR cleaning configuration: Can't write file '$fileNameUser'!\n";
+ list($command, $path) = $args;
+ if($path == "all")
+ {
+ $fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
+ if(!$this->users->clean($fileNameUser)) $statusCode = 500;
+ if($statusCode == 500) echo "ERROR cleaning configuration: Can't write file '$fileNameUser'!\n";
+ }
return $statusCode;
}