DataObjects/Mtrack_repos_branch.php
authorAlan Knowles <alan@roojs.com>
Tue, 15 Jan 2019 10:09:52 +0000 (18:09 +0800)
committerAlan Knowles <alan@roojs.com>
Tue, 15 Jan 2019 10:09:52 +0000 (18:09 +0800)
DataObjects/Mtrack_repos_branch.php

index e69de29..4d7c67c 100644 (file)
@@ -0,0 +1,93 @@
+<?php
+/**
+ * Table Definition for mtrack_repos
+ */
+class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
+
+class Pman_MTrack_DataObjects_Mtrack_repos extends DB_DataObject 
+{
+    ###START_AUTOCODE
+    /* the code below is auto generated do not remove the above tag */
+
+    public $__table = 'mtrack_repos';                    // table name
+    public $id;                              // int(11)  not_null primary_key auto_increment
+    public $name;                       // string(64)  not_null
+    public $repo_id;                         // string(16)  not_null
+     
+     
+    function repo()
+    {
+        $r = DB_DataObject::factory('mtrack_repo');
+        $r->get($this->repo_id);
+        return $r;
+    }
+
+    function notifyENDOFDAYMAIL($rcpt, $last_sent_date, $notify, $force)
+    {
+        // fisrst use history to show a list of changes between the dates.
+        //die("building end of day mail");
+        // var_dump($notify->act_start );
+        $start = date('Y-m-d H:i:s', strtotime($notify->act_start . ' - 1 DAY'));
+        $end = date('Y-m-d H:i:s', strtotime($notify->act_start));
+        
+        $object = null;
+        $branch = null;
+        if ($this->impl()->shortname == 'greengarden') {
+            $object = 'branch';
+            $branch = 'roojs';
+        }
+        
+        //$this->impl()->debug=1;
+        //print_r(array('since'=> '{'.$start.'}' , 'before' => '{'.$end .'}'));
+        $res = $this->impl()->history('.', array('since'=> '{'.$start.'}' , 'before' => '{'.$end .'}'), 'rev', '--all');
+        
+        $branches = array();
+        foreach($res as $r) {
+            if (!preg_match('#^refs/heads/.*$#', $r->branch)) {
+                continue;
+            }
+            $br = preg_replace('#^refs/heads/.*$#', $r->branch, '');
+            $branches[$br] = 1;
+                
+        }
+        $objs = array();
+        foreach($branches as $branch=>$one) {
+            
+            
+            $res = $this->impl()->history('.', array('since'=> '{'.$start.'}' , 'before' => '{'.$end .'}'), $object, $branch);
+             
+            // find the last rev the day before...
+            
+            
+             
+            $obj = $this->historyToSummary($res, $notify->act_start);
+            if (!$obj) {
+               // echo "History returned nothing";
+                return true;
+            }
+            $obj->from_dt = $start;
+            $obj->to_dt = $end;
+            $obj->branch = $br;
+            //print_r($obj);exit; 
+         
+            $objs[] = $obj;
+        }
+        $ret =   $rcpt->buildMail('repo_daily_changes', array('branches' => $obj));
+        
+        return $ret;
+        
+        
+        //$rcpt->sendTemplate('repo_daily_changes', $obj);
+        
+        //echo '<PRE>'.htmlspecialchars(print_r($mr,true));
+        
+        //exit;
+         
+        
+        
+        
+    }
+     
+    
+}
\ No newline at end of file