4 * Copyright 2010 Roland Mas
6 * Thorsten Glaser <t.glaser@tarent.de>
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require (dirname(__FILE__).'/../www/env.inc.php');
25 require_once $gfcommon.'include/pre.php';
30 require_once 'common/include/Plugin.class.php';
31 require_once 'common/include/PluginManager.class.php';
33 setup_plugin_manager () ;
34 session_set_admin () ;
36 function usage($rc=1) {
38 echo "\t.../populate_template_project.php 5\n";
39 echo "\t.../populate_template_project.php new unixname groupname\n";
40 echo "The first syntax populates an existing group, with its ID given.\n";
41 echo "The second syntax creates a new template froup.\n";
45 function hasmailinglist($project, $listname) {
46 $mlFactory = new MailingListFactory($project);
47 if (!$mlFactory || !is_object($mlFactory) || $mlFactory->isError()) {
50 $mlArray = $mlFactory->getMailingLists();
51 if ($mlFactory->isError()) {
54 $listname = $project->getUnixName() . '-' . $listname;
55 foreach ($mlArray as $mlEntry) {
56 if ($mlEntry->getName() == $listname) {
63 function populateProject($project) {
65 $role = new Role($project);
66 $todo = array_keys($role->defaults);
67 for ($c=0; $c<count($todo); $c++) {
68 if (! ($role_id = $role->createDefault($todo[$c]))) {
69 $project->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
71 setup_gettext_from_context();
74 $role = new Role($project, $role_id);
75 if ($role->getVal('projectadmin',0)=='A') {
76 $role->setUser(session_get_user()->getID());
80 if (forge_get_config ('use_tracker')) {
81 $ats = new ArtifactTypes($project);
82 if (!$ats || !is_object($ats)) {
83 $project->setError(_('Error creating ArtifactTypes object'));
85 setup_gettext_from_context();
87 } elseif ($ats->isError()) {
88 $project->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
90 setup_gettext_from_context();
93 if (!$ats->createTrackers()) {
94 $project->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
96 setup_gettext_from_context();
101 if (forge_get_config ('use_forum')) {
102 $f1 = new Forum($project);
103 if (!$f1->create(_('Open-Discussion'),_('General Discussion'),1,'',1,0)) {
104 $project->setError(sprintf (_('F%d: %s'), 1, $f1->getErrorMessage()));
106 setup_gettext_from_context();
109 $f2 = new Forum($project);
110 if (!$f2->create(_('Help'),_('Get Public Help'),1,'',1,0)) {
111 $project->setError(sprintf (_('F%d: %s'), 2, $f2->getErrorMessage()));
113 setup_gettext_from_context();
116 $f3 = new Forum($project);
117 if (!$f3->create(_('Developers-Discussion'),_('Project Developer Discussion'),0,'',1,0)) {
118 $project->setError(sprintf (_('F%d: %s'), 3, $f3->getErrorMessage()));
120 setup_gettext_from_context();
125 if (forge_get_config('use_docman')) {
126 $dg = new DocumentGroup($project);
127 if (!$dg->create(_('Uncategorized Submissions'))) {
128 $project->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
130 setup_gettext_from_context();
135 if (forge_get_config ('use_frs')) {
136 $frs = new FRSPackage($project);
137 if (!$frs->create("UNIXNAME")) {
138 $project->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
140 setup_gettext_from_context();
145 if (forge_get_config ('use_pm')) {
146 $pg = new ProjectGroup($project);
147 if (!$pg->create(_('To Do'),_('Things We Have To Do'),1)) {
148 $project->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
150 setup_gettext_from_context();
153 $pg = new ProjectGroup($project);
154 if (!$pg->create(_('Next Release'),_('Items For Our Next Release'),1)) {
155 $project->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
157 setup_gettext_from_context();
162 $ra = RoleAnonymous::getInstance() ;
163 $rl = RoleLoggedIn::getInstance() ;
164 $ra->linkProject ($project) ;
165 $rl->linkProject ($project) ;
167 $ra->setSetting ('project_read', $project->getID(), 1) ;
168 $rl->setSetting ('project_read', $project->getID(), 1) ;
170 $ra->setSetting ('frs', $project->getID(), 1) ;
171 $rl->setSetting ('frs', $project->getID(), 1) ;
173 $ra->setSetting ('docman', $project->getID(), 1) ;
174 $rl->setSetting ('docman', $project->getID(), 1) ;
176 $ra->setSetting ('forum', $f1->getID(), 3) ;
177 $rl->setSetting ('forum', $f1->getID(), 3) ;
179 $ra->setSetting ('forum', $f2->getID(), 3) ;
180 $rl->setSetting ('forum', $f2->getID(), 3) ;
182 $pgf = new ProjectGroupFactory ($project) ;
183 foreach ($pgf->getAllProjectGroupIds() as $pgid) {
184 $pg = projectgroup_get_object ($pgid) ;
185 if ($pg->isPublic()) {
186 $ra->setSetting ('pm', $pgid, 1) ;
187 $rl->setSetting ('pm', $pgid, 1) ;
191 $atf = new ArtifactTypeFactory ($project) ;
192 foreach ($atf->getAllArtifactTypeIds() as $atid) {
193 $at = artifactType_get_object ($atid) ;
194 if ($at->isPublic()) {
195 $ra->setSetting ('tracker', $atid, 1) ;
196 $rl->setSetting ('tracker', $atid, 1) ;
200 if (forge_get_config('use_mail')) {
201 $mlist = new MailingList($project);
202 if (!hasmailinglist($project, 'commits') &&
203 !$mlist->create('commits',_('Commits'),1,session_get_user()->getID())) {
204 $project->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
206 setup_gettext_from_context();
210 $project->normalizeAllRoles () ;
217 if (count($argv) < 2) {
219 } elseif (in_array($argv[1], array('-h', '-?', '--help'))) {
221 } elseif (count($argv) == 2) {
222 if (!($gid = util_nat0($argv[1]))) {
225 if (!($project = group_get_object($gid))) {
226 printf("Group #%d not found!\n", $gid);
229 if (!populateProject($project)) {
230 printf("Error: could not populate new group: %s\n",
231 $project->getErrorMessage());
234 } elseif (count($argv) == 4 && $argv[1] == "new") {
236 $project = new Group();
237 $desc = sprintf("Template project %s (%s) populated on %s",
238 $argv[2], $argv[3], date("r"));
239 if (!$project->create(session_get_user(), $argv[3], $argv[2],
242 printf("Error: could not create group: %s\n",
243 $project->getErrorMessage());
246 if (!$project->setAsTemplate(true)) {
248 printf("Error: could not mark group as template: %s\n",
252 if (!populateProject($project)) {
253 printf("Error: could not populate new group: %s\n",
254 $project->getErrorMessage());
262 printf("Group #%d %s (%s) populated successfully.\n", $project->getID(),
263 $project->getUnixName(), $project->getPublicName());