3 require_once 'MTrack/DB.php';
4 require_once 'MTrack/Config.php';
5 //require_once 'MTrack/Changeset.php';
11 public $shortname = null;
12 public $notifyemail = null;
14 static function loadById($id) {
15 return new MTrackProject($id);
18 static function loadByName($name) {
19 list($row) = MTrackDB::q('select projid from projects where shortname = ?',
22 return self::loadById($row[0]);
27 function __construct($id = null) {
29 list($row) = MTrackDB::q(
30 'select * from projects where projid = ?',
33 $this->projid = $row['projid'];
34 $this->ordinal = $row['ordinal'];
35 $this->name = $row['name'];
36 $this->shortname = $row['shortname'];
37 $this->notifyemail = $row['notifyemail'];
40 throw new Exception("unable to find project with id = $id");
44 function save(MTrackChangeset $CS) {
46 list($row) = MTrackDB::q(
47 'select * from projects where projid = ?',
48 $this->projid)->fetchAll();
51 'update projects set ordinal = ?, name = ?, shortname = ?,
52 notifyemail = ? where projid = ?',
53 $this->ordinal, $this->name, $this->shortname,
54 $this->notifyemail, $this->projid);
56 MTrackDB::q('insert into projects (ordinal, name,
57 shortname, notifyemail) values (?, ?, ?, ?)',
58 $this->ordinal, $this->name, $this->shortname,
60 $this->projid = MTrackDB::lastInsertId('projects', 'projid');
63 $CS->add("project:" . $this->projid . ":name", $old['name'], $this->name);
64 $CS->add("project:" . $this->projid . ":ordinal", $old['ordinal'], $this->ordinal);
65 $CS->add("project:" . $this->projid . ":shortname", $old['shortname'], $this->shortname);
66 $CS->add("project:" . $this->projid . ":notifyemail", $old['notifyemail'], $this->notifyemail);
69 function _adjust_ticket_link($M) {
70 $tktlimit = MTrackConfig::get('trac_import', "max_ticket:$this->shortname");
71 if ($M[1] <= $tktlimit) {
72 return "#$this->shortname$M[1]";
77 function adjust_links($reason, $use_ticket_prefix)
79 if (!$use_ticket_prefix) {
83 $tktlimit = MTrackConfig::get('trac_import', "max_ticket:$this->shortname");
84 if ($tktlimit !== null) {
85 $reason = preg_replace_callback('/#(\d+)/',
86 array($this, '_adjust_ticket_link'), $reason);
88 // don't do this if the number is outside the valid ranges
89 // may need to be clever about this during trac imports
90 // $reason = preg_replace('/#(\d+)/', "#$this->shortname\$1", $reason);
92 // FIXME: this and the above need to be more intelligent
93 $reason = preg_replace('/\[(\d+)\]/', "[$this->shortname\$1]", $reason);