$link[0]\n"; } } } echo "\n"; if (count($tracs)) { foreach ($tracs as $tname => $pname) { echo "Import trac $name -> $pname\n"; } } function usage($msg = '') { echo $msg, << $r) { $d = $r->getSCMMetaData(); printf(" %10s %s\n", $t, $d['name']); } echo "\n\n\n"; exit(1); } if (!is_dir($vardir)) { mkdir($vardir); chmod($vardir, 02777); } if (!is_dir("$vardir/attach")) { mkdir("$vardir/attach"); chmod("$vardir/attach", 02777); } putenv("MTRACK_CONFIG_FILE=" . $config_file_name); if (!file_exists($config_file_name)) { /* create a new config file */ $CFG = file_get_contents("config.ini.sample"); $CFG = str_replace("@VARDIR@", realpath($vardir), $CFG); if (count($projects)) { list($pname) = array_keys($projects); } else { $pname = "mtrack demo"; } $CFG = str_replace("@PROJECT@", $pname, $CFG); if ($DSN == null) { $DSN = "sqlite:@{core:dblocation}"; } $CFG = str_replace("@DSN@", "\"$DSN\"", $CFG); $tools_to_find = array('diff', 'diff3', 'php', 'svn', 'hg', 'git', 'svnserve', 'svnlook', 'svnadmin'); foreach ($SCMS as $S) { $m = $S->getSCMMetaData(); if (isset($m['tools'])) { foreach ($m['tools'] as $t) { $tools_to_find[] = $t; } } } /* find reasonable defaults for tools */ $tools = array(); foreach ($tools_to_find as $toolname) { foreach (explode(PATH_SEPARATOR, getenv('PATH')) as $pdir) { if (DIRECTORY_SEPARATOR == '\\' && file_exists($pdir . DIRECTORY_SEPARATOR . $toolname . '.exe')) { $tools[$toolname] = $pdir . DIRECTORY_SEPARATOR . $toolname . '.exe'; break; } else if (file_exists($pdir . DIRECTORY_SEPARATOR . $toolname)) { $tools[$toolname] = $pdir . DIRECTORY_SEPARATOR . $toolname; break; } } if (!isset($tools[$toolname])) { // let the system find it in the path at runtime $tools[$toolname] = $toolname; } } $toolscfg = ''; foreach ($tools as $toolname => $toolpath) { $toolscfg .= "$toolname = \"$toolpath\"\n"; } $CFG = str_replace("@TOOLS@", $toolscfg, $CFG); file_put_contents($config_file_name, $CFG); } unset($_GLOBALS['MTRACK_CONFIG_SKIP_BOOT']); MTrackConfig::$ini = null; MTrackDB::$db = null; MTrackTicket_CustomFields::$me = null; MTrackConfig::boot(); include dirname(__FILE__) . '/schema-tool.php'; if (file_exists("$vardir/mtrac.db")) { chmod("$vardir/mtrac.db", 0666); } $db = MTrackDB::get(); # if the config has custom fields, or the runtime config from an earlier # installation does, let's update the schema, if needed. MTrackTicket_CustomFields::getInstance()->save(); MTrackChangeset::$use_txn = false; $db->beginTransaction(); $CANON_USERS = array(); if ($aliasfile) { foreach (file($aliasfile) as $line) { if (preg_match('/^\s*([^=]+)\s*=\s*(.*)\s*$/', $line, $M)) { if (!strlen($M[1])) { continue; } $CANON_USERS[$M[1]] = $M[2]; } } } foreach ($CANON_USERS as $src => $dest) { MTrackDB::q('insert into useraliases (alias, userid) values (?, ?)', $src, strlen($dest) ? $dest : null); } if ($authorfile) { foreach (file($authorfile) as $line) { $author = explode(',', trim($line)); if (strlen($author[0])) { MTrackDB::q('insert into userinfo ( userid, fullname, email, active, timezone) values (?, ?, ?, ?, ?)', $author[0], $author[1], $author[2], ((int)$author[3]) ? 1 : 0, $author[4]); } } } /* set up initial ACL tree structure */ $rootobjects = array( 'Reports', 'Browser', 'Wiki', 'Timeline', 'Roadmap', 'Tickets', 'Enumerations', 'Components', 'Projects', 'User', 'Snippets', ); foreach ($rootobjects as $rootobj) { MTrackACL::addRootObjectAndRoles($rootobj); } # Add forking permissions $ents = MTrackACL::getACL('Browser', false); $ents[] = array('BrowserCreator', 'fork', true); $ents[] = array('BrowserForker', 'fork', true); $ents[] = array('BrowserForker', 'read', true); MTrackACL::setACL('Browser', false, $ents); $CS = MTrackChangeset::begin('~setup~', 'initial setup'); foreach ($projects as $pname) { $p = new MTrackProject; $p->shortname = $pname; $p->name = $pname; $p->save($CS); $projects[$pname] = $p; } foreach ($repos as $repo) { $r = new MTrack_Repo; $r->shortname = $repo[0]; $r->scmtype = $repo[1]; $r->repopath = $repo[2]; foreach ($links as $link) { list($pname, $rname, $loc) = $link; if ($rname == $r->shortname) { $p = $projects[$pname]; $r->addLink($p, $loc); } } $r->save($CS); $repos[$r->shortname] = $r; } if (!isset($repos['wiki'])) { // Set up the wiki repo (if they don't already have one named wiki) if ($wiki_repo_type === null) { $wiki_repo_type = MTrackConfig::get('tools', 'hg'); if (file_exists($wiki_repo_type)) { $wiki_repo_type = 'hg'; } else { $wiki_repo_type = 'svn'; } } $r = new MTrack_Repo; $r->shortname = 'wiki'; $r->scmtype = $wiki_repo_type; $r->repopath = realpath($vardir) . DIRECTORY_SEPARATOR . 'wiki'; $r->description = 'The mtrack wiki pages are stored here'; echo " ** Creating repo 'wiki' of type $r->scmtype to hold Wiki content at $r->repopath\n"; echo " ** (use --repo option to specify an alternate location)\n"; echo " ** (use --wiki-type option to specify an alternate type)\n"; $r->save($CS); $repos['wiki'] = $r; $r->reconcileRepoSettings(); } foreach (glob("defaults/wiki/*") as $filename) { $name = basename($filename); echo "wiki: $name\n"; $w = new MTrack_Wiki_Item($name); if ($name == 'WikiStart' && $w !== null) { /* skip existing WikiStart, as it may have been customized */ continue; } $w->content = file_get_contents($filename); $w->save($CS); } touch("$vardir/.initializing"); MTrackWikiItem::commitNow(); foreach (glob("defaults/reports/*") as $filename) { $name = basename($filename); echo "report: $name\n"; $rep = new MTrack_Report; $rep->summary = $name; list($sql, $wiki) = explode("\n\n", file_get_contents($filename), 2); $rep->description = $wiki; $rep->query = $sql; $rep->save($CS); } if (count($tracs) == 0) { // Default enumerations foreach (array('defect', 'enhancement', 'task') as $v => $c) { $cl = new MTrackClassification; $cl->name = $c; $cl->value = $v; $cl->save($CS); } foreach (array('fixed', 'invalid', 'wontfix', 'duplicate', 'worksforme') as $v => $c) { $cl = new MTrackResolution; $cl->name = $c; $cl->value = $v; $cl->save($CS); } foreach (array('blocker', 'critical', 'major', 'normal', 'minor', 'trivial') as $v => $c) { $cl = new MTrackSeverity; $cl->name = $c; $cl->value = $v; $cl->save($CS); } foreach (array('highest', 'high', 'normal', 'low', 'lowest') as $v => $c) { $cl = new MTrackPriority; $cl->name = $c; $cl->value = $v; $cl->save($CS); } foreach (array('new', 'open', 'closed', 'reopened') as $v => $c) { $cl = new MTrackTicketState; $cl->name = $c; $cl->value = $v; $cl->save($CS); } } $CS->commit(); $i = 0; foreach ($tracs as $tracdb => $pname) { import_from_trac($projects[$pname], $tracdb, $i++); } echo "Committing\n"; flush(); $db->commit(); echo "Done\n"; unlink("$vardir/.initializing");