final move of files
[web.mtrack] / MTrack / DBSchema / Table.php
1 <?php
2
3 class MTrackDBSchema_Table {
4   var $name;
5   var $fields;
6   var $keys;
7   var $triggers;
8
9   /* compares two tables; returns true if they are identical,
10    * false if the definitions are altered */
11   function sameAs(MTrackDBSchema_Table $other) {
12     if ($this->name != $other->name) {
13       throw new Exception("can only compare tables with the same name!");
14     }
15     foreach (array('fields', 'keys', 'triggers') as $propname) {
16       if (!is_array($this->{$propname})) continue;
17       foreach ($this->{$propname} as $f) {
18         if (!isset($other->{$propname}[$f->name])) {
19 #          echo "$propname $f->name is new\n";
20           return false;
21         }
22         $o = clone $other->{$propname}[$f->name];
23         $f = clone $f;
24         unset($o->comment);
25         unset($f->comment);
26         if ($f != $o) {
27 #          echo "$propname $f->name are not equal\n";
28 #          var_dump($f);
29 #          var_dump($o);
30           return false;
31         }
32       }
33       if (!is_array($other->{$propname})) continue;
34       foreach ($other->{$propname} as $f) {
35         if (!isset($this->{$propname}[$f->name])) {
36 #          echo "$propname $f->name was deleted\n";
37           return false;
38         }
39       }
40     }
41
42     return true;
43   }
44 }