From f1dae944ea75829ce962dfeaeb09d132192b564a Mon Sep 17 00:00:00 2001
From: Axel Hahn <axel.hahn@iml.unibe.ch>
Date: Mon, 20 Apr 2015 14:50:21 +0200
Subject: [PATCH] - added cronjob to cache branches and tags

---
 .../deployment/classes/cache.class_config.php |  2 +-
 .../deployment/classes/vcs.git.class.php      |  8 +++--
 shellscripts/cron_cache_gitbranches.php       | 33 +++++++++++++++++++
 3 files changed, 39 insertions(+), 4 deletions(-)
 create mode 100644 shellscripts/cron_cache_gitbranches.php

diff --git a/public_html/deployment/classes/cache.class_config.php b/public_html/deployment/classes/cache.class_config.php
index eac68221..db12e25c 100644
--- a/public_html/deployment/classes/cache.class_config.php
+++ b/public_html/deployment/classes/cache.class_config.php
@@ -4,7 +4,7 @@
  */
 
 // set a custom cache direcory
-// $this->_sCacheDir="/tmp/ahcache";
+$this->_sCacheDir="/var/tmp/ahcache";
 
 // if you have a large number of items to cache:
 // you can limit the files per cache subdir in an indirect way
diff --git a/public_html/deployment/classes/vcs.git.class.php b/public_html/deployment/classes/vcs.git.class.php
index c6f57fce..b7bb0bca 100644
--- a/public_html/deployment/classes/vcs.git.class.php
+++ b/public_html/deployment/classes/vcs.git.class.php
@@ -311,9 +311,11 @@ class vcs implements iVcs {
         }
         // try to get infos from the cache
         if (
-                (array_key_exists($sBranch, $this->_aRemoteBranches) && $sVerifyRevision && $this->_aRemoteBranches[$sBranch]['revision'] == $sVerifyRevision
-                ) ||
-                (array_key_exists($sBranch, $this->_aRemoteBranches) && !$sVerifyRevision
+                is_array($this->_aRemoteBranches)
+                && (
+                   array_key_exists($sBranch, $this->_aRemoteBranches) && $sVerifyRevision && $this->_aRemoteBranches[$sBranch]['revision'] == $sVerifyRevision
+                   ||
+                   array_key_exists($sBranch, $this->_aRemoteBranches) && !$sVerifyRevision
                 )
         ) {
             // it is up to date - doing nothing
diff --git a/shellscripts/cron_cache_gitbranches.php b/shellscripts/cron_cache_gitbranches.php
new file mode 100644
index 00000000..837efb1d
--- /dev/null
+++ b/shellscripts/cron_cache_gitbranches.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * 
+ * CRONJOB
+ * cache all git branches
+ * 
+ */
+
+// http://iml:deployment@ci.iml.unibe.ch/deployment/?prj=ci&action=deploy&par3=preview&confirm=1
+
+$sDocroot = (dirname(__dir__)) . "/public_html";
+
+require_once("$sDocroot/deployment/classes/logger.class.php");
+global $oCLog;
+$oCLog = new logger();
+
+require_once("$sDocroot/../config/inc_projects_config.php");
+require_once("$sDocroot/deployment/inc_functions.php");
+require_once("$sDocroot/deployment/classes/project.class.php");
+
+$oPrj1 = new project();
+
+echo "<h1>===== IMLDEPLOYMENT - cache git branches =====</h1>\n";
+foreach ($oPrj1->getProjects() as $sPrj) {
+    $oPrj = new project($sPrj);
+    
+    echo "----- $sPrj:\n";
+    foreach($oPrj->getRemoteBranches() as $aBranch){
+        echo $aBranch['revision']." ".$aBranch['label'] . "<br>\n";
+    }
+    echo "<br>\n";
+}
+echo "done\n";
-- 
GitLab