commit 80ca9f57e7c20ac1996600636b0e497844e15ee2
parent 615bd5507a909710eef5c0abb04481ee8d41d0d1
Author: markseu <mark2011@mayberg.se>
Date: Wed, 15 Oct 2025 23:45:00 +0200
Updated log file display
Diffstat:
3 files changed, 88 insertions(+), 22 deletions(-)
diff --git a/system/extensions/update-available.ini b/system/extensions/update-available.ini
@@ -753,14 +753,14 @@ Status: available
system/workers/turkish.php: turkish.php, create, update
Extension: Update
-Version: 0.9.5
+Version: 0.9.6
Description: Keep your website up to date.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-update/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-update
DocumentationLanguage: en, de, sv
-Published: 2025-09-03 12:18:10
+Published: 2025-10-15 23:33:25
Status: available
system/workers/update.php: update.php, create, update
system/workers/updatepatch.bin: updatepatch.php, create, additional
diff --git a/system/extensions/update-installed.ini b/system/extensions/update-installed.ini
@@ -128,14 +128,14 @@ 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.9.5
+Version: 0.9.6
Description: Keep your website up to date.
Developer: Anna Svensson
Tag: feature
DownloadUrl: https://github.com/annaesvensson/yellow-update/archive/refs/heads/main.zip
DocumentationUrl: https://github.com/annaesvensson/yellow-update
DocumentationLanguage: en, de, sv
-Published: 2025-09-03 12:18:10
+Published: 2025-10-15 23:33:25
Status: available
system/workers/update.php: update.php, create, update
system/workers/updatepatch.bin: updatepatch.php, create, additional
diff --git a/system/workers/update.php b/system/workers/update.php
@@ -2,7 +2,7 @@
// Update extension, https://github.com/annaesvensson/yellow-update
class YellowUpdate {
- const VERSION = "0.9.5";
+ const VERSION = "0.9.6";
const PRIORITY = "2";
public $yellow; // access to API
public $extensions; // number of extensions
@@ -17,6 +17,7 @@ class YellowUpdate {
$this->yellow->system->setDefault("updateExtensionFile", "extension.ini");
$this->yellow->system->setDefault("updateEventPending", "none");
$this->yellow->system->setDefault("updateEventDaily", "0");
+ $this->yellow->system->setDefault("updateLogEntries", "20");
$this->yellow->system->setDefault("updateTrashTimeout", "7776660");
}
@@ -54,6 +55,7 @@ class YellowUpdate {
if ($statusCode==0) {
switch ($command) {
case "about": $statusCode = $this->processCommandAbout($command, $text); break;
+ case "log": $statusCode = $this->processCommandLog($command, $text); break;
case "install": $statusCode = $this->processCommandInstall($command, $text); break;
case "uninstall": $statusCode = $this->processCommandUninstall($command, $text); break;
case "update": $statusCode = $this->processCommandUpdate($command, $text); break;
@@ -65,7 +67,7 @@ class YellowUpdate {
// Handle command help
public function onCommandHelp() {
- return array("about [extension]", "install [extension]", "uninstall [extension]", "update [extension]");
+ return array("about [extension]", "log [filter]", "install [extension]", "uninstall [extension]", "update [extension]");
}
// Handle page content element
@@ -79,24 +81,11 @@ class YellowUpdate {
$output .= ucfirst($key)." ".$value->get("version")."<br />\n";
}
}
- if ($text=="release") $output = "Datenstrom Yellow ".YellowCore::RELEASE;
if ($text=="log") {
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreWebsiteFile");
- $fileHandle = @fopen($fileName, "rb");
- if ($fileHandle) {
- clearstatcache(true, $fileName);
- if (flock($fileHandle, LOCK_SH)) {
- $dataBufferSize = 1024;
- fseek($fileHandle, max(0, filesize($fileName) - $dataBufferSize));
- $dataBuffer = fread($fileHandle, $dataBufferSize);
- if (strlenb($dataBuffer)==$dataBufferSize) {
- $dataBuffer = ($pos = strposu($dataBuffer, "\n")) ? substru($dataBuffer, $pos+1) : $dataBuffer;
- }
- flock($fileHandle, LOCK_UN);
- }
- fclose($fileHandle);
- }
- $output = str_replace("\n", "<br />\n", htmlspecialchars($dataBuffer));
+ $output = htmlspecialchars($this->getFileData($fileName, $this->yellow->system->get("updateLogEntries")));
+ $output = str_replace("\n", "<br />\n", $output);
+ if (is_string_empty($output)) $output = "No entries in log file\n";
}
}
return $output;
@@ -124,6 +113,16 @@ class YellowUpdate {
}
return $statusCode;
}
+
+ // Process command to show log file
+ public function processCommandLog($command, $text) {
+ $statusCode = 200;
+ $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreWebsiteFile");
+ $fileData = $this->getFileData($fileName, $this->yellow->system->get("updateLogEntries"), $text);
+ echo $fileData;
+ if (is_string_empty($fileData)) echo "Yellow $command: No entries in log file\n";
+ return $statusCode;
+ }
// Process command to install extensions
public function processCommandInstall($command, $text) {
@@ -942,4 +941,71 @@ class YellowUpdate {
}
return mktime(0, 0, 0) + 60*60*24 + $timeOffset;
}
+
+ // Return entries in log file
+ public function getFileData($fileName, $entriesMax = 0, $filter = "") {
+ $fileData = "";
+ $fileHandle = @fopen($fileName, "rb");
+ if ($fileHandle) {
+ clearstatcache(true, $fileName);
+ if (flock($fileHandle, LOCK_SH)) {
+ $entriesFound = 0;
+ $filter = strtoloweru($filter);
+ $filePos = filesize($fileName)-1;
+ $fileTop = -1;
+ while (($line = $this->getFileLinePrevious($fileHandle, $filePos, $fileTop, $dataBuffer))!==false) {
+ if (is_string_empty($filter) || strposu(strtoloweru($line), $filter)!==false) {
+ $fileData = $line.$fileData;
+ ++$entriesFound;
+ if ($entriesFound==$entriesMax) break;
+ }
+ }
+ flock($fileHandle, LOCK_UN);
+ }
+ fclose($fileHandle);
+ }
+ return $fileData;
+ }
+
+ // Return previous text line from file, false if not found
+ public function getFileLinePrevious($fileHandle, &$filePos, &$fileTop, &$dataBuffer) {
+ if ($filePos>=0) {
+ $line = "";
+ $lineEndingSearch = false;
+ $this->getFileLineBuffer($fileHandle, $filePos, $fileTop, $dataBuffer);
+ $endPos = $filePos - $fileTop;
+ for (;$filePos>=0; --$filePos) {
+ $currentPos = $filePos - $fileTop;
+ if ($dataBuffer===false) {
+ $line = false;
+ break;
+ }
+ if ($dataBuffer[$currentPos]=="\n" && $lineEndingSearch) {
+ $line = substru($dataBuffer, $currentPos+1, $endPos-$currentPos).$line;
+ break;
+ }
+ if ($currentPos==0) {
+ $line = substru($dataBuffer, $currentPos, $endPos-$currentPos+1).$line;
+ $this->getFileLineBuffer($fileHandle, $filePos-1, $fileTop, $dataBuffer);
+ $endPos = $filePos-1 - $fileTop;
+ }
+ $lineEndingSearch = true;
+ }
+ } else {
+ $line = false;
+ }
+ return $line;
+ }
+
+ // Update text line buffer
+ public function getFileLineBuffer($fileHandle, $filePos, &$fileTop, &$dataBuffer) {
+ if ($filePos>=0) {
+ $top = intval($filePos/4096) * 4096;
+ if ($fileTop!=$top) {
+ $fileTop = $top;
+ fseek($fileHandle, $fileTop);
+ $dataBuffer = fread($fileHandle, 4096);
+ }
+ }
+ }
}