1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
4 if (!file_exists("bin/init.php")) {
5 echo "You must run me from the top-level mtrack dir\n";
9 /* People doing this are not necessarily sane, make sure we have PDO and
11 if (!extension_loaded('PDO') || !extension_loaded('pdo_sqlite')) {
12 echo "Mtrack requires PDO and pdo_sqlite to function\n";
20 $config_file_name = 'config.ini';
24 while (count($argv)) {
25 $arg = array_shift($argv);
27 if ($arg == '--config-file') {
28 if (count($argv) < 1) {
29 usage("Missing argument to --config-file");
31 $config_file_name = array_shift($argv);
34 if ($arg == '--trac') {
35 if (count($argv) < 2) {
36 usage("Missing arguments to --trac");
38 $pname = array_shift($argv);
39 $tracdb = array_shift($argv);
41 if (!file_exists($tracdb)) {
42 usage("Tracdb path must be a sqlite database");
44 $tracs[$tracdb] = $pname;
45 $projects[$pname] = $pname;
48 if ($arg == '--repo') {
49 if (count($argv) < 3) {
50 usage("Missing arguments to --repo");
52 $rname = array_shift($argv);
53 $rtype = array_shift($argv);
54 $rpath = array_shift($argv);
58 if (!is_dir("$rpath/.hg")) {
59 usage("Repo path must be an hg repo dir");
63 if (!file_exists("$rpath/format")) {
64 usage("Repo path must be a svn repo");
68 usage("Invalid repo type $rtype");
71 $repos[$rname] = array($rname, $rtype, $rpath);
75 if ($arg == '--link') {
76 if (count($argv) < 3) {
77 usage("Missing arguments to --link");
79 $pname = array_shift($argv);
80 $rname = array_shift($argv);
81 $rloc = array_shift($argv);
83 $links[] = array($pname, $rname, $rloc);
84 $projects[$pname] = $pname;
92 usage("Unhandled arguments");
95 putenv("MTRACK_CONFIG_FILE=" . $config_file_name);
97 require_once 'inc/common.php';
98 include 'bin/import-trac.php';
100 MTrackACL::$batch = true;
101 MTrackSearchDB::setBatchMode();
103 $db = MTrackDB::get();
104 MTrackChangeset::$use_txn = false;
105 $db->beginTransaction();
107 $CS = MTrackChangeset::begin('~modify~', 'setup modified');
109 foreach ($projects as $pname) {
110 $p = MTrackProject::loadByName($pname);
112 $p = new MTrackProject;
113 $p->shortname = $pname;
117 $projects[$pname] = $p;
120 foreach ($repos as $repo) {
122 $r->shortname = $repo[0];
123 $r->scmtype = $repo[1];
124 $r->repopath = $repo[2];
126 foreach ($links as $link) {
127 list($pname, $rname, $loc) = $link;
128 if ($rname == $r->shortname) {
129 $p = $projects[$pname];
130 $r->addLink($p, $loc);
135 $repos[$r->shortname] = $r;
141 foreach ($tracs as $tracdb => $pname) {
142 import_from_trac($projects[$pname], $tracdb, true);
144 echo "Updating ACL tree\n"; flush();
145 MTrackACL::applyBatch();
146 echo "Committing\n"; flush();
148 MTrackSearchDB::optimize();
151 function usage($msg = '')
153 require_once 'inc/common.php';
157 --repo {name} {type} {repopath}
158 define a repo named {name} of {type} at {repopath}
159 --link {project} {repo} {location}
160 link a repo location to a project
161 --trac {project} {tracenv}
162 import data from a trac environment at {tracenv}
163 and associate with project {project}
165 --config-file {filename} Where to find the configuration file.
166 defaults to config.ini in the current directory.
169 Supported repo types:
174 foreach (MTrackRepo::getAvailableSCMs() as $t => $r) {
175 $d = $r->getSCMMetaData();
176 printf(" %10s %s\n", $t, $d['name']);