Przeglądaj źródła

Added support for long-term backwards compatibility

markseu 3 lat temu
rodzic
commit
070c97afa0

+ 2 - 2
system/extensions/install.php

@@ -2,7 +2,7 @@
 // Install extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/install
 
 class YellowInstall {
-    const VERSION = "0.8.72";
+    const VERSION = "0.8.73";
     const PRIORITY = "1";
     public $yellow;                 // access to API
     
@@ -98,7 +98,7 @@ class YellowInstall {
             $statusCode = $this->removeInstall();
             $this->yellow->log($statusCode==200 ? "info" : "error", "Uninstall extension 'Install ".YellowInstall::VERSION."'");
             if ($statusCode>=400) {
-                echo "ERROR updating files: ".$this->yellow->page->errorMessage."\n";
+                echo "ERROR installing files: ".$this->yellow->page->errorMessage."\n";
                 echo "Detected ZIP-files, 0 extensions installed. Please run command again.\n";
             }
         }

+ 4 - 4
system/extensions/update-current.ini

@@ -64,11 +64,11 @@ media/images/photo.jpg: photo.jpg, create, optional
 media/thumbnails/photo-100x40.jpg: photo-100x40.jpg, create, optional
 
 Extension: Install
-Version: 0.8.72
+Version: 0.8.73
 Description: Install a brand new, shiny website.
 DocumentationUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/install
 DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/install.zip
-Published: 2022-05-05 19:26:16
+Published: 2022-05-08 09:16:40
 Developer: Datenstrom
 Status: unlisted
 system/extensions/install.php: install.php, create
@@ -131,11 +131,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.77
+Version: 0.8.78
 Description: Keep your website up to date.
 DocumentationUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/update
 DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/update.zip
-Published: 2022-05-07 19:13:46
+Published: 2022-05-08 09:45:04
 Developer: Datenstrom
 Tag: feature
 system/extensions/update.php: update.php, create, update

+ 26 - 18
system/extensions/update.php

@@ -2,7 +2,7 @@
 // Update extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/update
 
 class YellowUpdate {
-    const VERSION = "0.8.77";
+    const VERSION = "0.8.78";
     const PRIORITY = "2";
     public $yellow;                 // access to API
     public $extensions;             // number of extensions
@@ -169,12 +169,11 @@ class YellowUpdate {
     // Process command for pending events
     public function processCommandPending() {
         $statusCode = 0;
+        $this->extensions = 0;
         $this->updatePatchPending();
         $this->updateEventPending();
-        if ($this->isExtensionPending()) {
-            $this->extensions = 0;
-            $statusCode = $this->updateExtensions("install");
-            if ($statusCode!=200) echo "ERROR installing files: ".$this->yellow->page->errorMessage."\n";
+        $statusCode = $this->updateExtensionPending();
+        if ($statusCode==303) {
             echo "Detected ZIP-file".($this->extensions!=1 ? "s" : "");
             echo ", $this->extensions extension".($this->extensions!=1 ? "s" : "")." installed. Please run command again.\n";
         }
@@ -187,12 +186,10 @@ class YellowUpdate {
         if ($this->yellow->lookup->isContentFile($fileName)) {
             $this->updatePatchPending();
             $this->updateEventPending();
-            if ($this->isExtensionPending()) {
-                $statusCode = $this->updateExtensions("install");
-                if ($statusCode==200) {
-                    $location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
-                    $statusCode = $this->yellow->sendStatus(303, $location);
-                }
+            $statusCode = $this->updateExtensionPending();
+            if ($statusCode==303) {
+                $location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
+                $statusCode = $this->yellow->sendStatus(303, $location);
             }
         }
         return $statusCode;
@@ -361,7 +358,7 @@ class YellowUpdate {
             if ($this->yellow->extension->isExisting("updatepatch")) {
                 $value = $this->yellow->extension->data["updatepatch"];
                 if (method_exists($value["object"], "onLoad")) $value["object"]->onLoad($this->yellow);
-                if (method_exists($value["object"], "onUpdate")) $value["object"]->onUpdate("update");
+                if (method_exists($value["object"], "onUpdate")) $value["object"]->onUpdate("patch");
             }
             unset($this->yellow->extension->data["updatepatch"]);
             if (function_exists("opcache_reset")) opcache_reset();
@@ -401,6 +398,23 @@ class YellowUpdate {
         }
     }
     
+    // Update pending extensions
+    public function updateExtensionPending() {
+        $statusCode = 0;
+        $path = $this->yellow->system->get("coreExtensionDirectory");
+        if (count($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", false, false))>0) {
+            $statusCode = $this->updateExtensions("install");
+            if ($statusCode==200) $statusCode = 303;
+            if ($statusCode>=400) {
+                $this->yellow->log("error", $this->yellow->page->errorMessage);
+                $this->yellow->page->statusCode = 0;
+                $this->yellow->page->errorMessage = "";
+                $statusCode = 303;
+            }
+        }
+        return $statusCode;
+    }
+    
     // Update system settings
     public function updateSystemSettings() {
         $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
@@ -817,10 +831,4 @@ class YellowUpdate {
         }
         return mktime(0, 0, 0) + 60*60*24 + $timeOffset;
     }
-
-    // Check if extension pending
-    public function isExtensionPending() {
-        $path = $this->yellow->system->get("coreExtensionDirectory");
-        return count($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", false, false))>0;
-    }
 }