commit 78df7a9482268ef0ba9c68ee0f4b0a7489aba399
parent 1613ce5d3648c3d9e22c783173e7c6035ce4a244
Author: markseu <mark2011@mayberg.se>
Date: Mon, 17 Apr 2023 00:17:40 +0200
Updated API, logging
Diffstat:
7 files changed, 63 insertions(+), 59 deletions(-)
diff --git a/system/extensions/core.php b/system/extensions/core.php
@@ -2,7 +2,7 @@
// Core extension, https://github.com/annaesvensson/yellow-core
class YellowCore {
- const VERSION = "0.8.107";
+ const VERSION = "0.8.108";
const RELEASE = "0.8.22";
public $content; // content files
public $media; // media files
@@ -165,11 +165,11 @@ class YellowCore {
if (!is_null($error) && isset($error["type"]) && ($error["type"]==E_ERROR || $error["type"]==E_PARSE)) {
$fileNameAbsolute = isset($error["file"]) ? $error["file"] : "";
$fileName = substru($fileNameAbsolute, strlenu($this->system->get("coreServerInstallDirectory")));
- $this->log("error", "Can't parse file '$fileName'!");
+ $this->toolbox->log("error", "Can't parse file '$fileName'!");
$this->toolbox->sendHttpHeader($this->toolbox->getHttpStatusFormatted(500));
$troubleshooting = PHP_SAPI!="cli" ?
"<a href=\"".$this->getTroubleshootingUrl()."\">See troubleshooting</a>." : "See ".$this->getTroubleshootingUrl();
- echo "<br/>\nCheck the log file. Activate the debug mode for more information. $troubleshooting\n";
+ echo "<br/>\nDatenstrom Yellow stopped with fatal error. Activate the debug mode for more information. $troubleshooting\n";
}
}
@@ -299,22 +299,6 @@ class YellowCore {
}
}
- // Write information to log file
- public function log($action, $message) {
- $statusCode = 0;
- foreach ($this->extension->data as $key=>$value) {
- if (method_exists($value["object"], "onLog")) {
- $statusCode = $value["object"]->onLog($action, $message);
- if ($statusCode!=0) break;
- }
- }
- if ($statusCode==0) {
- $line = date("Y-m-d H:i:s")." ".trim($action)." ".trim($message)."\n";
- $this->toolbox->appendFile($this->system->get("coreServerInstallDirectory").
- $this->system->get("coreExtensionDirectory").$this->system->get("coreWebsiteFile"), $line);
- }
- }
-
// Include layout
public function layout($name, $arguments = null) {
$this->lookup->layoutArguments = func_get_args();
@@ -398,6 +382,9 @@ class YellowCore {
public function isLoaded() {
return isset($this->extension->data);
}
+
+ // TODO: remove later, for backwards compatibility
+ public function log($action, $message) { $this->toolbox->log($action, $message); }
}
class YellowContent {
@@ -2781,6 +2768,23 @@ class YellowToolbox {
return $value;
}
+ // Write information to log file
+ public function log($action, $message) {
+ $statusCode = 0;
+ foreach ($this->yellow->extension->data as $key=>$value) {
+ if (method_exists($value["object"], "onLog")) {
+ $statusCode = $value["object"]->onLog($action, $message);
+ if ($statusCode!=0) break;
+ }
+ }
+ if ($statusCode==0) {
+ $line = date("Y-m-d H:i:s")." ".trim($action)." ".trim($message)."\n";
+ $this->appendFile($this->yellow->system->get("coreServerInstallDirectory").
+ $this->yellow->system->get("coreExtensionDirectory").
+ $this->yellow->system->get("coreWebsiteFile"), $line);
+ }
+ }
+
// Start timer
public function timerStart(&$time) {
$time = microtime(true);
diff --git a/system/extensions/edit.php b/system/extensions/edit.php
@@ -2,7 +2,7 @@
// Edit extension, https://github.com/annaesvensson/yellow-edit
class YellowEdit {
- const VERSION = "0.8.71";
+ const VERSION = "0.8.72";
public $yellow; // access to API
public $response; // web response
public $merge; // text merge
@@ -50,7 +50,7 @@ class YellowEdit {
}
$fileDataNew = rtrim($fileDataNew)."\n";
if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileNameUser, $fileDataNew)) {
- $this->yellow->log("error", "Can't write file '$fileNameUser'!");
+ $this->yellow->toolbox->log("error", "Can't write file '$fileNameUser'!");
}
}
}
@@ -189,7 +189,7 @@ class YellowEdit {
"status" => "active");
$status = $this->yellow->user->save($fileNameUser, $email, $settings) ? "ok" : "error";
if ($status=="error") echo "ERROR updating settings: Can't write file '$fileNameUser'!\n";
- $this->yellow->log($status=="ok" ? "info" : "error", "Add user '".strtok($name, " ")."'");
+ $this->yellow->toolbox->log($status=="ok" ? "info" : "error", "Add user '".strtok($name, " ")."'");
}
if ($status=="ok") {
$algorithm = $this->yellow->system->get("editUserHashAlgorithm");
@@ -244,7 +244,7 @@ class YellowEdit {
$fileNameUser = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreUserFile");
$status = $this->yellow->user->remove($fileNameUser, $email) ? "ok" : "error";
if ($status=="error") echo "ERROR updating settings: Can't write file '$fileNameUser'!\n";
- $this->yellow->log($status=="ok" ? "info" : "error", "Remove user '".strtok($name, " ")."'");
+ $this->yellow->toolbox->log($status=="ok" ? "info" : "error", "Remove user '".strtok($name, " ")."'");
}
$statusCode = $status=="ok" ? 200 : 500;
echo "Yellow $command: User account ".($statusCode!=200 ? "not " : "")."removed\n";
@@ -421,7 +421,7 @@ class YellowEdit {
$settings = array("failed" => "0", "modified" => date("Y-m-d H:i:s", time()), "status" => "active");
$this->response->status = $this->yellow->user->save($fileNameUser, $email, $settings) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
- $this->yellow->log($this->response->status=="ok" ? "info" : "error", "Add user '".strtok($name, " ")."'");
+ $this->yellow->toolbox->log($this->response->status=="ok" ? "info" : "error", "Add user '".strtok($name, " ")."'");
}
if ($this->response->status=="ok") {
$this->response->status = $this->response->sendMail($scheme, $address, $base, $email, "welcome") ? "done" : "error";
@@ -574,7 +574,7 @@ class YellowEdit {
$settings = array("failed" => "0", "modified" => date("Y-m-d H:i:s", time()), "status" => "removed");
$this->response->status = $this->yellow->user->save($fileNameUser, $email, $settings) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
- $this->yellow->log($this->response->status=="ok" ? "info" : "error", "Remove user '".strtok($name, " ")."'");
+ $this->yellow->toolbox->log($this->response->status=="ok" ? "info" : "error", "Remove user '".strtok($name, " ")."'");
}
if ($this->response->status=="ok") {
$this->response->status = $this->response->sendMail($scheme, $address, $base, $email, "goodbye") ? "ok" : "error";
diff --git a/system/extensions/image.php b/system/extensions/image.php
@@ -2,7 +2,7 @@
// Image extension, https://github.com/annaesvensson/yellow-image
class YellowImage {
- const VERSION = "0.8.18";
+ const VERSION = "0.8.19";
public $yellow; // access to API
// Handle initialisation
@@ -22,7 +22,7 @@ class YellowImage {
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", false, false) as $entry) {
if (!$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500;
}
- if ($statusCode==500) $this->yellow->log("error", "Can't delete files in directory '$path'!");
+ if ($statusCode==500) $this->yellow->toolbox->log("error", "Can't delete files in directory '$path'!");
}
}
diff --git a/system/extensions/install.php b/system/extensions/install.php
@@ -2,7 +2,7 @@
// Install extension, https://github.com/annaesvensson/yellow-install
class YellowInstall {
- const VERSION = "0.8.87";
+ const VERSION = "0.8.88";
const PRIORITY = "1";
public $yellow; // access to API
@@ -111,10 +111,10 @@ class YellowInstall {
if (!is_file($fileName)) {
list($name, $version, $os) = $this->yellow->toolbox->detectServerInformation();
$product = "Datenstrom Yellow ".YellowCore::RELEASE;
- $this->yellow->log("info", "Install $product, PHP ".PHP_VERSION.", $name $version, $os");
+ $this->yellow->toolbox->log("info", "Install $product, PHP ".PHP_VERSION.", $name $version, $os");
foreach ($this->yellow->extension->data as $key=>$value) {
if ($key=="install") continue;
- $this->yellow->log("info", "Install extension '".ucfirst($key)." $value[version]'");
+ $this->yellow->toolbox->log("info", "Install extension '".ucfirst($key)." $value[version]'");
}
if (!is_file($fileName)) {
$statusCode = 500;
@@ -163,7 +163,7 @@ class YellowInstall {
$statusCode = max($statusCode, $this->yellow->extension->get("update")->updateExtensionSettings($extension, $action, $settings));
$statusCode = max($statusCode, $this->yellow->extension->get("update")->updateExtensionFile(
$fileNamePhp, $fileDataPhp, $modified, 0, 0, "create", $extension));
- $this->yellow->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'");
+ $this->yellow->toolbox->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'");
}
}
return $statusCode;
@@ -201,7 +201,7 @@ class YellowInstall {
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't write file '$fileNameUser'!");
}
- $this->yellow->log($statusCode==200 ? "info" : "error", "Add user '".strtok($name, " ")."'");
+ $this->yellow->toolbox->log($statusCode==200 ? "info" : "error", "Add user '".strtok($name, " ")."'");
}
return $statusCode;
}
@@ -284,7 +284,7 @@ class YellowInstall {
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
}
- if ($log) $this->yellow->log($statusCode==200 ? "info" : "error", "Uninstall extension 'Install ".YellowInstall::VERSION."'");
+ if ($log) $this->yellow->toolbox->log($statusCode==200 ? "info" : "error", "Uninstall extension 'Install ".YellowInstall::VERSION."'");
return $statusCode;
}
diff --git a/system/extensions/static.php b/system/extensions/static.php
@@ -2,7 +2,7 @@
// Static extension, https://github.com/annaesvensson/static-command
class YellowStatic {
- const VERSION = "0.8.47";
+ const VERSION = "0.8.48";
public $yellow; // access to API
public $files; // number of files
public $links; // number of links
@@ -30,9 +30,9 @@ class YellowStatic {
"staticDefaultFile" => $this->yellow->system->get("commandStaticDefaultFile"),
"staticErrorFile" => $this->yellow->system->get("commandStaticErrorFile"));
if (!$this->yellow->system->save($fileName, $settings)) {
- $this->yellow->log("error", "Can't write file '$fileName'!");
+ $this->yellow->toolbox->log("error", "Can't write file '$fileName'!");
}
- $this->yellow->log("info", "Import settings for 'Static ".YellowStatic::VERSION."'");
+ $this->yellow->toolbox->log("info", "Import settings for 'Static ".YellowStatic::VERSION."'");
}
}
}
diff --git a/system/extensions/update-current.ini b/system/extensions/update-current.ini
@@ -1,11 +1,11 @@
# Datenstrom Yellow update settings
Extension: Core
-Version: 0.8.107
+Version: 0.8.108
Description: Core functionality of the website.
DocumentationUrl: https://github.com/annaesvensson/yellow-core
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/core.zip
-Published: 2023-04-07 20:00:15
+Published: 2023-04-16 23:48:53
Developer: Mark Seuffert, David Fehrmann
Tag: feature
system/extensions/core.php: core.php, create, update
@@ -17,11 +17,11 @@ system/layouts/navigation.html: navigation.html, create, update, careful
system/layouts/pagination.html: pagination.html, create, update, careful
Extension: Edit
-Version: 0.8.71
+Version: 0.8.72
Description: Edit your website in a web browser.
DocumentationUrl: https://github.com/annaesvensson/yellow-edit
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/edit.zip
-Published: 2022-11-16 11:12:49
+Published: 2023-04-16 23:56:20
Developer: Anna Svensson
Tag: feature
system/extensions/edit.php: edit.php, create, update
@@ -32,11 +32,11 @@ system/extensions/edit.woff: edit.woff, delete
content/shared/page-new-default.md: page-new-default.md, create, optional
Extension: Image
-Version: 0.8.18
+Version: 0.8.19
Description: Images and thumbnails.
DocumentationUrl: https://github.com/annaesvensson/yellow-image
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/image.zip
-Published: 2022-11-03 18:17:42
+Published: 2023-04-16 23:50:53
Developer: Anna Svensson
Tag: feature
system/extensions/image.php: image.php, create, update
@@ -44,11 +44,11 @@ media/images/photo.jpg: photo.jpg, create, optional
media/thumbnails/photo-100x40.jpg: photo-100x40.jpg, create, optional
Extension: Install
-Version: 0.8.87
+Version: 0.8.88
Description: Install a brand new, shiny website.
DocumentationUrl: https://github.com/annaesvensson/yellow-install
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/install.zip
-Published: 2023-04-13 22:34:54
+Published: 2023-04-16 23:55:50
Developer: Anna Svensson
Status: unlisted
system/extensions/install.php: install.php, create
@@ -86,11 +86,11 @@ Tag: feature
system/extensions/meta.php: meta.php, create, update
Extension: Static
-Version: 0.8.47
+Version: 0.8.48
Description: Build a static website.
DocumentationUrl: https://github.com/annaesvensson/yellow-static
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/static.zip
-Published: 2023-04-14 10:46:36
+Published: 2023-04-16 23:50:49
Developer: Anna Svensson
Tag: feature
system/extensions/static.php: static.php, create, update
@@ -121,11 +121,11 @@ system/themes/stockholm-opensans-light.woff: stockholm-opensans-light.woff, crea
system/themes/stockholm-opensans-regular.woff: stockholm-opensans-regular.woff, create, update, careful
Extension: Update
-Version: 0.8.92
+Version: 0.8.93
Description: Keep your website up to date.
DocumentationUrl: https://github.com/annaesvensson/yellow-update
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/update.zip
-Published: 2023-03-17 23:25:10
+Published: 2023-04-16 23:51:15
Developer: Anna Svensson
Tag: feature
system/extensions/update.php: update.php, create, update
diff --git a/system/extensions/update.php b/system/extensions/update.php
@@ -2,7 +2,7 @@
// Update extension, https://github.com/annaesvensson/yellow-update
class YellowUpdate {
- const VERSION = "0.8.92";
+ const VERSION = "0.8.93";
const PRIORITY = "2";
public $yellow; // access to API
public $extensions; // number of extensions
@@ -28,7 +28,7 @@ class YellowUpdate {
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.download$/", false, false) as $entry) {
if (!$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500;
}
- if ($statusCode==500) $this->yellow->log("error", "Can't delete files in directory '$path'!");
+ if ($statusCode==500) $this->yellow->toolbox->log("error", "Can't delete files in directory '$path'!");
$statusCode = 200;
$path = $this->yellow->system->get("coreTrashDirectory");
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", false, false) as $entry) {
@@ -39,7 +39,7 @@ class YellowUpdate {
$expire = $this->yellow->toolbox->getFileDeleted($entry) + $this->yellow->system->get("updateTrashTimeout");
if ($expire<=time() && !$this->yellow->toolbox->deleteDirectory($entry)) $statusCode = 500;
}
- if ($statusCode==500) $this->yellow->log("error", "Can't delete files in directory '$path'!");
+ if ($statusCode==500) $this->yellow->toolbox->log("error", "Can't delete files in directory '$path'!");
}
}
@@ -300,7 +300,7 @@ class YellowUpdate {
}
}
$statusCode = max($statusCode, $this->updateExtensionNotification($extension, $action));
- $this->yellow->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'");
+ $this->yellow->toolbox->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'");
++$this->extensions;
} else {
$statusCode = 500;
@@ -372,7 +372,7 @@ class YellowUpdate {
unset($this->yellow->extension->data["updatepatch"]);
if (function_exists("opcache_reset")) opcache_reset();
if (!$this->yellow->toolbox->deleteFile($fileName)) {
- $this->yellow->log("error", "Can't delete file '$fileName'!");
+ $this->yellow->toolbox->log("error", "Can't delete file '$fileName'!");
}
}
}
@@ -383,11 +383,11 @@ class YellowUpdate {
if ($this->yellow->system->get("updateCurrentRelease")!=YellowCore::RELEASE) {
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
if (!$this->yellow->system->save($fileName, array("updateCurrentRelease" => YellowCore::RELEASE))) {
- $this->yellow->log("error", "Can't write file '$fileName'!");
+ $this->yellow->toolbox->log("error", "Can't write file '$fileName'!");
} else {
list($name, $version, $os) = $this->yellow->toolbox->detectServerInformation();
$product = "Datenstrom Yellow ".YellowCore::RELEASE;
- $this->yellow->log("info", "Update $product, PHP ".PHP_VERSION.", $name $version, $os");
+ $this->yellow->toolbox->log("info", "Update $product, PHP ".PHP_VERSION.", $name $version, $os");
}
}
if ($this->yellow->system->get("updateEventPending")!="none") {
@@ -402,7 +402,7 @@ class YellowUpdate {
$this->updateLanguageSettings("all", $action);
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
if (!$this->yellow->system->save($fileName, array("updateEventPending" => "none"))) {
- $this->yellow->log("error", "Can't write file '$fileName'!");
+ $this->yellow->toolbox->log("error", "Can't write file '$fileName'!");
}
}
if ($this->yellow->system->get("updateEventDaily")<=time()) {
@@ -411,7 +411,7 @@ class YellowUpdate {
}
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
if (!$this->yellow->system->save($fileName, array("updateEventDaily" => $this->getTimestampDaily()))) {
- $this->yellow->log("error", "Can't write file '$fileName'!");
+ $this->yellow->toolbox->log("error", "Can't write file '$fileName'!");
}
}
}
@@ -425,7 +425,7 @@ class YellowUpdate {
$statusCode = $this->updateExtensions("install");
if ($statusCode==200) $statusCode = 303;
if ($statusCode>=400) {
- $this->yellow->log("error", $this->yellow->page->errorMessage);
+ $this->yellow->toolbox->log("error", $this->yellow->page->errorMessage);
$this->yellow->page->statusCode = 0;
$this->yellow->page->errorMessage = "";
$statusCode = 303;
@@ -618,7 +618,7 @@ class YellowUpdate {
$statusCode = max($statusCode, $this->updateLanguageSettings($extension, $action));
}
$version = $settings->get("version");
- $this->yellow->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'");
+ $this->yellow->toolbox->log($statusCode==200 ? "info" : "error", ucfirst($action)." extension '".ucfirst($extension)." $version'");
++$this->extensions;
} else {
$statusCode = 500;