[Fusionforge-commits] r8558 - trunk/gforge/common/pm

Alain Peyrat aljeux at libremir.placard.fr.eu.org
Thu Dec 17 18:41:19 CET 2009


Author: aljeux
Date: 2009-12-17 18:41:19 +0100 (Thu, 17 Dec 2009)
New Revision: 8558

Modified:
   trunk/gforge/common/pm/import_utils.php
Log:
Task/Import: Allow category to be given as text instead of category_id

Modified: trunk/gforge/common/pm/import_utils.php
===================================================================
--- trunk/gforge/common/pm/import_utils.php	2009-12-17 17:41:13 UTC (rev 8557)
+++ trunk/gforge/common/pm/import_utils.php	2009-12-17 17:41:19 UTC (rev 8558)
@@ -149,6 +149,25 @@
 						} elseif ($percent_complete > 100) {
 							$percent_complete=100;
 						}
+
+						// Convert category name to category_id if given.
+						if (isset($tasks[$i]['category'])) {
+							if ($tasks[$i]['category'] == 'None') {
+								$category_id = 100;
+							} else {
+								$res = db_query_params('SELECT category_id FROM project_category WHERE group_project_id=$1 AND category_name=$2',
+									array($group_project_id, $tasks[$i]['category']));
+								$category_id = db_result($res, 0, 'category_id');
+								if (!$category_id) {
+									$was_error=true;
+									$array['errormessage']='Error No category named : '.$tasks[$i]['category'];
+									break;
+								}
+							}
+						} else {
+							$category_id = $pt->getCategoryID();
+						}
+
 						if (!$pt->create(
 							addslashes($tasks[$i]['name']),
 							addslashes($tasks[$i]['notes']),
@@ -156,7 +175,7 @@
 							$hours,
 							strtotime($tasks[$i]['start_date']),
 							strtotime($tasks[$i]['end_date']),
-							100,
+							$category_id,
 							$percent_complete,
 							$assignees,
 							$deps = array(),
@@ -216,6 +235,25 @@
 						} elseif ($percent_complete > 100) {
 							$percent_complete=100;
 						}
+
+						// Convert category name to category_id if given.
+						if (isset($tasks[$i]['category'])) {
+							if ($tasks[$i]['category'] == 'None') {
+								$category_id = 100;
+							} else {
+								$res = db_query_params('SELECT category_id FROM project_category WHERE group_project_id=$1 AND category_name=$2',
+									array($group_project_id, $tasks[$i]['category']));
+								$category_id = db_result($res, 0, 'category_id');
+								if (!$category_id) {
+									$was_error=true;
+									$array['errormessage']='Error No category named : '.$tasks[$i]['category'];
+									break;
+								}
+							}
+						} else {
+							$category_id = $pt->getCategoryID();
+						}
+
 						if (!$pt->update(
 							addslashes($tasks[$i]['name']),
 							addslashes($tasks[$i]['notes']),
@@ -224,7 +262,7 @@
 							strtotime($tasks[$i]['start_date']),
 							strtotime($tasks[$i]['end_date']),
 							$pt->getStatusID(),
-							$pt->getCategoryID(),
+							$category_id,
 							$percent_complete,
 							$assignees,
 							$pt->getDependentOn(),




More information about the Fusionforge-commits mailing list