3 * Table Definition for changes
5 * -- it stores any change to tickets/commits etc...
7 * We now store rev ids in here..
8 * and the extra data (like file etc. in change_audit
10 * Which will make timeline alot easier to work with..
12 * Need to decide - this stores a commit as changes on a ticket, when it's flagged as such..
13 * -> in theory we can ignore this...
14 * -> fetch of ticket changes will have to pull in changes based on the rev id...
18 * ... just list scmid's since a certain time.. - then fetch them from here...
21 * indexes : object, rev (for looup)
22 * indexes : object, rev, changedate (for last rev)
25 require_once 'DB/DataObject.php';
27 class MTrackWeb_DataObjects_Changes extends DB_DataObject
30 /* the code below is auto generated do not remove the above tag */
32 public $__table = 'changes'; // table name
33 public $cid; // int(11) not_null primary_key auto_increment
34 public $who; // username
35 public $object; // ticket:xxxx or rep:1 etc.
36 public $changedate; // datetime(19) not_null binary
37 public $reason; // description (includes changeset name etc.
38 public $rev; // md5 has of commit id...
41 function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('MTrackWeb_DataObjects_Changes',$k,$v); }
43 /* the code above is auto generated do not remove the tag below */
46 function getCommit($repo, $hash, $runhistory=true)
48 $this->object = $repo->toIdString(); // should be repo:1
50 if ($this->find(true)) {
55 throw new Exception("Can not find revision");
57 $this->refreshHistory($repo);
58 if ( $this->find(true)) {
61 }; /// yes I know we say you should not run this twice...
65 * scans repo history and imports it... ??? does not know about branches yet...
67 function refreshHistory($repo)
69 $c = DB_DataObject::factory('changes');
70 $c->object = $repo->toIdString();
71 $c->orderBy('changedate DESC');
72 $c->whereAdd("rev != ''");
77 // history returns an array of scmEvents... - should actually return an array of this object...
78 $recs = $repo->history('', null, $last ? 'rev' : null, $last ? $last :null);
80 foreach($recs as $r) {
81 // see if we have a copy of it already.
82 $c = DB_DataObject::factory('changes');
83 $c->object = $repo->toIdString();
84 $c->changedate != $r->ctime;
86 $c->whereAdd("rev != ''");
87 if (!$c->find(true)) {
88 // not found, create a new one..
93 $cr->reason = $r->changelog;
94 $cr->who = $r->changeby;
96 foreach($cr->files as $f) {
97 // we could do with adding 'X' lines changed on this
98 $ca = DB_DataObject::factory('change_audit');
100 $ca->fieldname = $cr->object. ':file';
101 $ca->action = $f->status . ($f->added ? ' +' . $f->added : '') . ($f->removed ? ' -' . $f->removed : '') ;
102 $ca->value = $f->name;