fetchAll(); if (isset($row[0])) { return self::loadById($row[0]); } return null; } function __construct($id = null) { if ($id !== null) { list($row) = MTrackDB::q( 'select * from projects where projid = ?', $id)->fetchAll(); if (isset($row[0])) { $this->projid = $row['projid']; $this->ordinal = $row['ordinal']; $this->name = $row['name']; $this->shortname = $row['shortname']; $this->notifyemail = $row['notifyemail']; return; } throw new Exception("unable to find project with id = $id"); } } function save(MTrackChangeset $CS) { if ($this->projid) { list($row) = MTrackDB::q( 'select * from projects where projid = ?', $this->projid)->fetchAll(); $old = $row; MTrackDB::q( 'update projects set ordinal = ?, name = ?, shortname = ?, notifyemail = ? where projid = ?', $this->ordinal, $this->name, $this->shortname, $this->notifyemail, $this->projid); } else { MTrackDB::q('insert into projects (ordinal, name, shortname, notifyemail) values (?, ?, ?, ?)', $this->ordinal, $this->name, $this->shortname, $this->notifyemail); $this->projid = MTrackDB::lastInsertId('projects', 'projid'); $old = null; } $CS->add("project:" . $this->projid . ":name", $old['name'], $this->name); $CS->add("project:" . $this->projid . ":ordinal", $old['ordinal'], $this->ordinal); $CS->add("project:" . $this->projid . ":shortname", $old['shortname'], $this->shortname); $CS->add("project:" . $this->projid . ":notifyemail", $old['notifyemail'], $this->notifyemail); } function _adjust_ticket_link($M) { $tktlimit = MTrackConfig::get('trac_import', "max_ticket:$this->shortname"); if ($M[1] <= $tktlimit) { return "#$this->shortname$M[1]"; } return $M[0]; } function adjust_links($reason, $use_ticket_prefix) { if (!$use_ticket_prefix) { return $reason; } $tktlimit = MTrackConfig::get('trac_import', "max_ticket:$this->shortname"); if ($tktlimit !== null) { $reason = preg_replace_callback('/#(\d+)/', array($this, '_adjust_ticket_link'), $reason); } else { // don't do this if the number is outside the valid ranges // may need to be clever about this during trac imports // $reason = preg_replace('/#(\d+)/', "#$this->shortname\$1", $reason); } // FIXME: this and the above need to be more intelligent $reason = preg_replace('/\[(\d+)\]/', "[$this->shortname\$1]", $reason); return $reason; } }