diff --git a/system/extensions/core.php b/system/extensions/core.php
new file mode 100644
index 0000000..312ed50
--- /dev/null
+++ b/system/extensions/core.php
@@ -0,0 +1,91 @@
+processCoreUpdate();
+ if ($statusCode==303) {
+ header("HTTP/1.0 303 Reload please");
+ header("Location: ".$_SERVER["REQUEST_URI"]);
+ header("Cache-Control: no-cache, no-store");
+ }
+ return $statusCode;
+ }
+
+ // Handle command from command line
+ public function command($line = "") {
+ $statusCode = $this->processCoreUpdate();
+ if ($statusCode==303) {
+ echo "Flux capacitor has reached 1.21 gigawatts. Please run command again.\n";
+ }
+ return $statusCode<400 ? 0 : 1;
+ }
+
+ // Update core for new release
+ public function processCoreUpdate() {
+ $statusCode = 303;
+ if (is_file("system/extensions/core.php") && is_file("system/workers/core.php")) {
+ $fileName = "yellow.php";
+ $fileData = $fileDataNew = $this->readFile($fileName);
+ $fileDataNew = str_replace("system/extensions/core.php", "system/workers/core.php", $fileDataNew);
+ if ($fileData!=$fileDataNew && !$this->createFile($fileName, $fileDataNew)) {
+ $statusCode = 500;
+ header("HTTP/1.0 500 Server error");
+ echo "Something went wrong during core update: Can't write file '$fileName'!
\n";
+ echo "Datenstrom Yellow stopped with fatal error. Activate the debug mode for more information. ";
+ echo "See https://datenstrom.se/yellow/help/troubleshooting
\n";
+ }
+ if (function_exists("opcache_reset")) opcache_reset();
+ }
+ return $statusCode;
+ }
+
+ // Read file, empty string if not found
+ public function readFile($fileName, $sizeMax = 0) {
+ $fileData = "";
+ $fileHandle = @fopen($fileName, "rb");
+ if ($fileHandle) {
+ clearstatcache(true, $fileName);
+ if (flock($fileHandle, LOCK_SH)) {
+ $fileSize = $sizeMax ? $sizeMax : filesize($fileName);
+ if ($fileSize) $fileData = fread($fileHandle, $fileSize);
+ flock($fileHandle, LOCK_UN);
+ }
+ fclose($fileHandle);
+ }
+ return $fileData;
+ }
+
+ // Create file
+ public function createFile($fileName, $fileData, $mkdir = false) {
+ $ok = false;
+ if ($mkdir) {
+ $path = dirname($fileName);
+ if (!is_string_empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
+ }
+ $fileHandle = @fopen($fileName, "cb");
+ if ($fileHandle) {
+ clearstatcache(true, $fileName);
+ if (flock($fileHandle, LOCK_EX)) {
+ ftruncate($fileHandle, 0);
+ fwrite($fileHandle, $fileData);
+ flock($fileHandle, LOCK_UN);
+ }
+ fclose($fileHandle);
+ $ok = true;
+ }
+ return $ok;
+ }
+}
diff --git a/system/extensions/update-available.ini b/system/extensions/update-available.ini
index f94a78d..1a11bd5 100644
--- a/system/extensions/update-available.ini
+++ b/system/extensions/update-available.ini
@@ -158,7 +158,7 @@ DocumentationLanguage: en, de, sv
Published: 2024-04-04 14:38:12
Status: available
system/workers/core.php: core.php, create, update
-system/extensions/core.php: coreupdate.txt, create, additional
+system/extensions/core.php: coreupdate.txt, update
system/layouts/default.html: default.html, create, update, careful
system/layouts/error.html: error.html, create, update, careful
system/layouts/header.html: header.html, create, update, careful
diff --git a/system/extensions/yellow-extension.ini b/system/extensions/yellow-extension.ini
index a2cc5df..2f23022 100755
--- a/system/extensions/yellow-extension.ini
+++ b/system/extensions/yellow-extension.ini
@@ -11,7 +11,7 @@ DocumentationLanguage: en, de, sv
Published: 2024-04-04 14:38:12
Status: available
system/workers/core.php: core.php, create, update
-system/extensions/core.php: coreupdate.txt, create, additional
+system/extensions/core.php: coreupdate.txt, update
system/layouts/default.html: default.html, create, update, careful
system/layouts/error.html: error.html, create, update, careful
system/layouts/header.html: header.html, create, update, careful