Fix #6661 - modify hooks to update timeshetet
[web.mtrack] / MTrackWeb / Hook / git.php
index 6029c08..ce00629 100755 (executable)
@@ -7,6 +7,18 @@
  *  #repo/hooks/post-receive
  *  /usr/bin/php {PATH TO APPLICATION}/index.php Hook/git post  >> /tmp/githooklog
  *
+ *
+ *
+ *
+ * to run this on old commits:
+ *
+  git rev-list --since="last month"    --pretty=format:"%H %P" refs/heads/master \
+        | grep -v commit  \
+        | awk -v q='"' '{ print "echo " q $NF " " $1 " refs/heads/master" q " | /usr/bin/php /home/gitlive/web.mtrack/roo.php Hook/git post " } '                  \
+        | sh
+
  *
  *
  */
@@ -25,6 +37,9 @@ require_once 'MTrackWeb.php';
 
 class MTrackWeb_Hook_git extends MTrackWeb
 {
+    
+    static $cli_desc = "Commit hook for git - see source for usage";
+    
     function getAuth()
     {
         if (!HTML_FlexyFramework::get()->cli) {
@@ -32,6 +47,9 @@ class MTrackWeb_Hook_git extends MTrackWeb
         }
         
     }
+    
+    
+    
      
     function get($action)
     {
@@ -55,7 +73,7 @@ class MTrackWeb_Hook_git extends MTrackWeb
             
             $who = $revs[0]->changebyToEmail();
             
-            $this->authUser = DB_DataObject::factory('Person');
+            $this->authUser = DB_DataObject::factory('core_person');
             $this->authUser->get('email', $who); 
             
             $cfg = HTML_FlexyFramework::get()->MTrackWeb;
@@ -71,7 +89,6 @@ class MTrackWeb_Hook_git extends MTrackWeb
                     'authUser' => $this->authUser,
             ));
              
-             
             switch ($action) {
                 
                 case 'pre':
@@ -83,14 +100,31 @@ class MTrackWeb_Hook_git extends MTrackWeb
                     
                     // at this point we have
                     // checker->no_ticket (contains commits without tickets
+                    // print_r($checker);exit;
                     
+                    //DB_DataObject::DebugLevel(1);
                     foreach($checker->no_ticket as $change_event) {
                         $cg = DB_DataObject::factory('mtrack_change');
-                        $cg->createFromCommit($change_event);
-                        
+                        $res= $cg->createFromCommit($change_event, $checker);
+                        if (!$res) {
+                            echo "Skip - commit already exists\n";
+                        }
                     }
                     
-                    print_r($checker);
+                    // in our system this happens when we merge normally.
+                    foreach($checker->deferred as $ticket=> $info) {
+                        foreach($info['changes'] as $ev) {
+                            $cg = DB_DataObject::factory('mtrack_change');
+                            $res=  $cg->createFromCommit($ev, $checker, $info['ticket']);
+                            if (!$res) {
+                                echo "Skip - commit already exists\n";
+                            }
+                            
+                        }
+                        
+                        
+                    }
+                    //print_r($checker);
                   
             }
             //_log("SUCCESS");