fixed branch view
authorpk910 <philipp@zoelle1.de>
Sun, 6 Oct 2013 10:01:58 +0000 (12:01 +0200)
committerpk910 <philipp@zoelle1.de>
Sun, 6 Oct 2013 10:01:58 +0000 (12:01 +0200)
GITManagedWebpage.class.php

index 2c429f96ed1a047e76a7f5c0f42739f078984cd9..6b6d903b57f095fdda048aa9b4fc9e6e52ce3e7b 100644 (file)
@@ -103,6 +103,16 @@ class GITManagedWebpage {
         $this->config_changed = true;
     }
     
         $this->config_changed = true;
     }
     
+    private function checkConfigIntegrity() {
+        foreach($this->config as $key => $value) {
+            if(substr($key, 0, strlen('branch_')) == 'branch_') {
+                if(!file_exists($this->workdir.$key)) {
+                    unset($this->config['key']);
+                }
+            }
+        }
+    }
+    
     /* private function getConfig($name)
     * get an option from the configuration
     */
     /* private function getConfig($name)
     * get an option from the configuration
     */
@@ -113,6 +123,7 @@ class GITManagedWebpage {
             if(file_exists($this->workdir."config.txt")) {
                 $config_txt = @file_get_contents($this->workdir."config.txt");
                 $this->config = unserialize($config_txt);
             if(file_exists($this->workdir."config.txt")) {
                 $config_txt = @file_get_contents($this->workdir."config.txt");
                 $this->config = unserialize($config_txt);
+                $this->checkConfigIntegrity();
             } else {
                 $this->config = array();
                 return null;
             } else {
                 $this->config = array();
                 return null;
@@ -228,7 +239,7 @@ class GITManagedWebpage {
             return false;
     }
     
             return false;
     }
     
-    private function updateBranch($branch, $path) {
+    private function updateBranch($branch, $path, $force = false) {
         if(substr($path, -1) != '/')
             $path .= '/';
         $current_branch = str_replace(array("\r", "\n"), array("", ""), $this->gitcmd("rev-parse", "--abbrev-ref", "HEAD"));
         if(substr($path, -1) != '/')
             $path .= '/';
         $current_branch = str_replace(array("\r", "\n"), array("", ""), $this->gitcmd("rev-parse", "--abbrev-ref", "HEAD"));
@@ -241,7 +252,7 @@ class GITManagedWebpage {
         
         $deleted_files = array();
         if(($current_version = $this->getConfig('version_'.$branch))) {
         
         $deleted_files = array();
         if(($current_version = $this->getConfig('version_'.$branch))) {
-            if($current_version == $newest_version)
+            if($current_version == $newest_version && !$force)
                 return;
             else {
                 $override_all = true;
                 return;
             else {
                 $override_all = true;
@@ -298,7 +309,7 @@ class GITManagedWebpage {
         
         if(!$this->localBranchPath($branch)) {
             $dir = $this->localBranchPath($branch, true);
         
         if(!$this->localBranchPath($branch)) {
             $dir = $this->localBranchPath($branch, true);
-            $this->updateBranch($branch, $dir);
+            $this->updateBranch($branch, $dir, true);
         }
     }
     
         }
     }
     
@@ -317,11 +328,14 @@ class GITManagedWebpage {
         if($active_branch != $default_branch) {
             if(!($dir = $this->localBranchPath($branch))) {
                 $dir = $this->localBranchPath($active_branch, true);
         if($active_branch != $default_branch) {
             if(!($dir = $this->localBranchPath($branch))) {
                 $dir = $this->localBranchPath($active_branch, true);
-                $this->updateBranch($active_branch, $dir);
+                $this->updateBranch($active_branch, $dir, true);
             }
             }
+            chdir($dir);
             include_once($dir.$file);
             include_once($dir.$file);
-            die();
+        } else {
+            include($file); //possible loop!
         }
         }
+        die();
     }
     
 }
     }
     
 }