4 * Extra field alias - Create aliases for the extra fields
6 * Copyright 2004 GForge, LLC
7 * http://fusionforge.org/
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with FusionForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
26 require_once dirname(__FILE__).'/../www/env.inc.php';
27 require_once $gfcommon.'include/pre.php';
29 // these names can't be assigned to an extra field's alias because they are already
30 // being used by the CLI
31 $reserved_alias = array(
40 // First of all, try to create the "alias" field if it doesn't exist
41 $res = db_query_params ('SELECT alias FROM artifact_extra_field_list',
44 if (!$res) { // error, the field doesn't exist
45 $res = db_query_params ('ALTER TABLE artifact_extra_field_list ADD COLUMN alias TEXT',
54 // Now fill all the data
55 db_query_params ('BEGIN WORK',
59 $res = db_query_params ('SELECT * FROM artifact_extra_field_list',
67 while ($row = db_fetch_array($res)) {
68 $name = $row["field_name"];
70 // for some weird reason the alias was already set... don't try to change it
71 if (array_key_exists("alias", $row) && !empty($row["alias"])) {
75 // Convert the original name to a valid alias (i.e., if the extra field is
76 // called "Quality test", make an alias called "quality_test").
77 // The alias can be seen as a "unix name" for this field
78 $alias = preg_replace("/ /", "_", $name);
79 $alias = preg_replace("/[^[:alpha:]_]/", "", $alias);
80 $alias = strtolower($alias);
82 // no alias is suitable... do nothing
83 if (strlen($alias) == 0) continue;
86 if (in_array($alias, $reserved_alias)) {
87 // prepend "extra_" to the alias (indicates it is an extra field)
88 $alias = "extra_".$alias;
91 // check for conflicting names
95 $previous_def = db_query_params ('SELECT * FROM artifact_extra_field_list WHERE group_artifact_id=$1 AND LOWER(alias)=$2 AND extra_field_id <> $3',
96 array ($row["group_artifact_id"],
98 $row["extra_field_id"])) ;
99 if (db_numrows($previous_def) > 0) { // alias exists...
101 $alias = $alias.$count; // do something like "alias1"
104 $conflict = false; // alias doesn't exists... we can use it
108 // at this point we can safely insert the alias
109 $update = db_query_params ('UPDATE artifact_extra_field_list SET alias=$1 WHERE extra_field_id=$2',
111 $row["extra_field_id"])) ;
124 // c-file-style: "bsd"