From 18c38db5323ea4481dc9519f73e9242f57f8f0be Mon Sep 17 00:00:00 2001
From: hahn <axel.hahn@iml.unibe.ch>
Date: Tue, 27 Feb 2018 14:26:23 +0100
Subject: [PATCH] Bug #1797: Falsche Revision-Hashes im Deployment Tool

---
 .../deployment/classes/project.class.php      | 14 +++++--------
 .../deployment/classes/vcs.git.class.php      | 21 +++++++++++++------
 .../deployment/classes/vcs.interface.php      |  5 +++--
 public_html/deployment/main.css               |  9 +++++---
 public_html/deployment/pages/act_build.php    |  2 +-
 5 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php
index cc1ef3aa..16dfd0dd 100644
--- a/public_html/deployment/classes/project.class.php
+++ b/public_html/deployment/classes/project.class.php
@@ -1251,23 +1251,18 @@ class project extends base {
 
     /**
      * get current revision and log message from remote repo
+     * @param boolean  $bRefresh  optional: refresh data; default: use cache
      * @return array
      */
     public function getRepoRevision($bRefresh = false) {
         $this->log(__FUNCTION__ . " start");
-        // $sReturn = "";
-        if (
-                array_key_exists("source", $this->_aData["phases"]) && $this->_aData["phases"]["source"] && $bRefresh == false
-        ) {
-            return $this->_aData["phases"]["source"];
-        }
 
         if (!$this->_aPrjConfig["build"]["type"]) {
             $this->_aData["phases"]["source"] = array("error" => t("class-project-error-repo-type-not-set"),);
         } else {
             $this->_initVcs();
             if ($this->_oVcs) {
-                $this->_aData["phases"]["source"] = $this->_oVcs->getRepoRevision();
+                $this->_aData["phases"]["source"] = $this->_oVcs->getRepoRevision($bRefresh);
             } else {
                 $this->_aData["phases"]["source"] = array(
                     "error" => sprintf(t("class-project-error-repo-type-not-supported"), $this->_aPrjConfig["build"]["type"]),
@@ -2905,15 +2900,16 @@ class project extends base {
 
     /**
      * return html code for the installed version in the repository
+     * @param boolean  $bRefresh  optional: refresh flag; default: use cached information
      * @return string
      */
-    public function renderRepoInfo() {
+    public function renderRepoInfo($bRefresh=false) {
         $oHtml = new htmlguielements();
         $sReturn = "";
         switch ($this->_aPrjConfig["build"]["type"]) {
             case "git":
 
-                $aRepodata = $this->getRepoRevision();
+                $aRepodata = $this->getRepoRevision($bRefresh);
                 if (array_key_exists("revision", $aRepodata)) {
                     $sReturn.=$this->_getChecksumDiv($aRepodata["revision"],
                         $oHtml->getIconByType('branch') . t('branch') . ': ' . (array_key_exists("branch", $aRepodata) ? $aRepodata["branch"] : '-') . '<br>'
diff --git a/public_html/deployment/classes/vcs.git.class.php b/public_html/deployment/classes/vcs.git.class.php
index 7012be83..0a4fad78 100644
--- a/public_html/deployment/classes/vcs.git.class.php
+++ b/public_html/deployment/classes/vcs.git.class.php
@@ -113,7 +113,8 @@ class vcs implements iVcs {
             $sGitCmd.='git init >/dev/null && ';
             $sGitCmd.='git remote add origin "' . $this->getUrl() . '" 2>&1 ';
             // $sGitCmd='time ('.$sGitCmd.')';
-            exec($sGitCmd, $aOutput, $iRc);
+            // exec($sGitCmd, $aOutput, $iRc);
+            exec($sGitCmd);
         }
         return $this->_sTempDir;
     }
@@ -210,6 +211,8 @@ class vcs implements iVcs {
         $iTtl = 300; // cache for 5 min
         require_once 'cache.class.php';
         $oCache = new AhCache($this->_getNameOfCacheModule(), "RemoteBranches");
+        $aOutput=false; 
+        $iRc=false;
 
         // list of cached branch keys
         if ($oCache->isExpired() || $bForceNoCache) {
@@ -280,11 +283,12 @@ class vcs implements iVcs {
     /**
      * get current revision and commit message from remote repository
      * @see $this::getRevision
+     * @param boolean  $bRefresh  optional: refresh data; default: use cache
      * @return array
      */
-    public function getRepoRevision() {
-        $this->log(__FUNCTION__." start");
-        $sMessage = $this->getCommitmessageByBranch();
+    public function getRepoRevision($bRefresh=false) {
+        $this->log(__FUNCTION__."($bRefresh) start");
+        $sMessage = $this->getCommitmessageByBranch(false, $bRefresh ? 'dummy_to_force_refresh' : false);
         if ($sMessage) {
             $aReturn = array(
                 'branch' => $this->_sCurrentBranch,
@@ -300,11 +304,11 @@ class vcs implements iVcs {
     /**
      * get a commit message of a given branch
      * @param string  $sBranch          name of a branch
-     * @param string  $sVerifyRevision  optional: verify if this revision is the newsest
+     * @param string  $sVerifyRevision  optional: revision to verify if it is the newsest
      * @return string
      */
     public function getCommitmessageByBranch($sBranch = false, $sVerifyRevision = false) {
-        $this->log(__FUNCTION__." start");
+        $this->log(__FUNCTION__."($sBranch, $sVerifyRevision) start");
         if (!$sBranch) {
             $sBranch = $this->_sCurrentBranch;
         }
@@ -318,9 +322,11 @@ class vcs implements iVcs {
                 )
         ) {
             // it is up to date - doing nothing
+            $this->log(__FUNCTION__." return cached data");
             return $this->_aRemoteBranches[$sBranch]['message'];
         }
         // ok, then I need to read it
+        $this->log(__FUNCTION__." return fresh data");
         if ($this->_sCurrentBranch != $sBranch) {
             $sSaveBranch = $this->_sCurrentBranch;
             $this->setCurrentBranch($sBranch);
@@ -398,6 +404,7 @@ class vcs implements iVcs {
 
         // parse revision
         $sRevision = false;
+        $aRev=array();
         if (preg_match('#commit\ (.*)#', $sLoginfo, $aRev)) {
             $sRevision = $aRev[1];
         }
@@ -444,6 +451,8 @@ class vcs implements iVcs {
         $sBranchname = str_replace("origin/", "", $this->_sCurrentBranch);
 
         $sGitCmd = 'export GIT_SSH="' . $this->_sWrapper . '" ; export PKEY="' . $this->_sKeyfile . '" ; ';
+        $sReturn=false;
+        $iRc=false;
         
         // this does not checkout tags in git v1.7 - only branches:
         // $sGitCmd .= 'echo git clone --depth 1 --recursive --branch "' . $sBranchname . '" "' . $this->getUrl() . '" "' . $sWorkDir . '" ; ';
diff --git a/public_html/deployment/classes/vcs.interface.php b/public_html/deployment/classes/vcs.interface.php
index e618f7cb..4ced62ba 100644
--- a/public_html/deployment/classes/vcs.interface.php
+++ b/public_html/deployment/classes/vcs.interface.php
@@ -37,10 +37,11 @@ interface iVcs {
     public function cleanupWorkdir($sWorkDir);
     
     /**
-     * get current revision and log message from remote repo
+     * get current revision and commit message from remote repository
+     * @param boolean  $bRefresh  optional: refresh data; default: use cache
      * @return array
      */
-    public function getRepoRevision();
+    public function getRepoRevision($bRefresh=false);
     
     /**
      * get current revision and log message from given directory
diff --git a/public_html/deployment/main.css b/public_html/deployment/main.css
index 447a410e..ea60e8bb 100644
--- a/public_html/deployment/main.css
+++ b/public_html/deployment/main.css
@@ -132,7 +132,7 @@ tr:hover{background:#ddd; background: linear-gradient(#f0f0f0,#fff,#f0f0f0);}
 .trproject:hover a.btn{opacity: 1;}
 
 .trproject{border-left:3px solid #fff;}
-tr.progressinprogress{border-left:0.5em solid #aec;}
+tr.progressinprogress{border-left:0.5em solid #8db;}
 div.progressinprogress{color: #6a9;}
 tr.progresshasqueue{border-left:0.5em solid #f81;}
 div.progresshasqueue{color: #d61;}
@@ -140,8 +140,11 @@ div.progresshasqueue{color: #d61;}
 td.preview{}
 td.stage{}
 td.live{}
-td{transition: ease-in 0.5s}
-td.highlight{background:rgba(255,220,50,0.5) !important;}
+td{}
+td.highlight{animation: blinker 1.5s linear infinite;}
+@keyframes blinker {  
+  30% { background:rgba(255,220,50,0.3) }
+}
 .td-place-onhold{color:#d61;}
 .td-place-ready2install{}
 
diff --git a/public_html/deployment/pages/act_build.php b/public_html/deployment/pages/act_build.php
index 996de19f..95d306fd 100644
--- a/public_html/deployment/pages/act_build.php
+++ b/public_html/deployment/pages/act_build.php
@@ -39,7 +39,7 @@ if (!array_key_exists("confirm", $aParams)) {
     $sOut.='<p>' . sprintf(t("page-build-info"), $sNext, $sNext) . '</p>';
 
     $sRevison = false;
-    $aRepodata = $oPrj->getRepoRevision();
+    $aRepodata = $oPrj->getRepoRevision(true);
     if (array_key_exists("revision", $aRepodata)) {
         $sRevison = $aRepodata["revision"];
         if (
-- 
GitLab