[Fusionforge-commits] r11592 - in trunk/src: etc/config.ini.d plugins/mantisbt/common plugins/mantisbt/www

Franck VILLAUME nerville at libremir.placard.fr.eu.org
Sun Nov 21 20:46:06 CET 2010


Author: nerville
Date: 2010-11-21 20:46:06 +0100 (Sun, 21 Nov 2010)
New Revision: 11592

Modified:
   trunk/src/etc/config.ini.d/mantisbt.ini
   trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php
   trunk/src/plugins/mantisbt/www/index.php
Log:
cleanup & more object oriented

Modified: trunk/src/etc/config.ini.d/mantisbt.ini
===================================================================
--- trunk/src/etc/config.ini.d/mantisbt.ini	2010-11-21 19:43:46 UTC (rev 11591)
+++ trunk/src/etc/config.ini.d/mantisbt.ini	2010-11-21 19:46:06 UTC (rev 11592)
@@ -1,5 +1,5 @@
 [mantisbt]
 
-server = mantisbt
+server_url = http://localhost/mantis
 adminsoap_user = administrator
 adminsoap_passwd = root

Modified: trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php
===================================================================
--- trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php	2010-11-21 19:43:46 UTC (rev 11591)
+++ trunk/src/plugins/mantisbt/common/MantisBTPlugin.class.php	2010-11-21 19:46:06 UTC (rev 11592)
@@ -23,7 +23,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
-
 /*
  * @todo :	need a massive cleanup
  *		deal correctly with password (might need direct db access ?)
@@ -106,21 +105,22 @@
 				$group_id = $params['group'];
 				$group = group_get_object($group_id);
 				$use_mantisbtplugin = getIntFromRequest('use_mantisbtplugin');
+
 				if ( $use_mantisbtplugin == "1" ) {
 					if (! $group->usesPlugin($this->name)) {
 						// activation plugin
 						$group->setPluginUse($this->name, true);
 
 						// add project in mantis if does not exists
-						if (!isProjetMantisCreated($group->data_array['group_id'])){
-							addProjetMantis($group->data_array['group_id'],$group->data_array['group_name'],$group->data_array['is_public'], $group->data_array['short_description']);
+						if (!$this->isProjectMantisCreated($group->data_array['group_id'])){
+							$this->addProjectMantis($group->data_array['group_id'],$group->data_array['group_name'],$group->data_array['is_public'], $group->data_array['short_description']);
 						}
 						// update users and roles in mantis
 						$members = array ();
 						foreach($group->getMembers() as $member){
 							$members[] = $member->data_array['user_name'];
 						}
-						updateUsersProjetMantis($group->data_array['group_id'],$members);
+						$this->updateUsersProjetMantis($group->data_array['group_id'],$members);
 					}
 				} else if ( $use_mantisbtplugin == "0" ) {
 					$group->setPluginUse ( $this->name, false );
@@ -172,7 +172,7 @@
 			case "project_admin_plugins": {
 				// this displays the link in the project admin options page to it's  MantisBT administration
 				$group_id = $params['group_id'];
-				$group = &group_get_object($group_id);
+				$group = group_get_object($group_id);
 				if ( $group->usesPlugin ( $this->name ) ) {
 					echo util_make_link ("/plugins/mantisbt/index.php?id=$group_id&type=admin&pluginname=".$this->name,
 					_('View Admin MantisBT')
@@ -183,160 +183,162 @@
 			}
 			case "group_approved": {
 				$group_id=$params['group_id'];
-				$group = &group_get_object($group_id);
+				$group = group_get_object($group_id);
 				if ($group->usesPlugin($this->name)) {
 					// ajout du projet mantis s'il n'existe pas
-					if (!isProjetMantisCreated($group->data_array['group_id'])){
-						addProjetMantis($group->data_array['group_id'],$group->data_array['group_name'],$group->data_array['is_public'], $group->data_array['short_description']);
+					if (!$this->isProjetMantisCreated($group->data_array['group_id'])){
+						$this->addProjetMantis($group->data_array['group_id'],$group->data_array['group_name'],$group->data_array['is_public'], $group->data_array['short_description']);
 					}
 					// mise a jour des utilisateurs avec les roles
 					$members = array ();
 					foreach($group->getMembers() as $member){
 						$members[] = $member->data_array['user_name'];
 					}
-					updateUsersProjetMantis($group->data_array['group_id'],$members);
+					$this->updateUsersProjetMantis($group->data_array['group_id'],$members);
 				}
 				break;
 			}
 			case "change_cal_permission": {
 				// mise a jour des utilisateurs avec les roles
 				$group_id=$params[1];
-				$group = &group_get_object($group_id);
+				$group = group_get_object($group_id);
 				$members = array ();
 				foreach($group->getMembers() as $member){
 					$members[] = $member->data_array['user_name'];
 				}
-				//updateUsersProjetMantis($group->data_array['group_id'],$members);
+				$this->updateUsersProjetMantis($group->data_array['group_id'],$members);
 				break;
 			}
 			// mise a jour de l'adresse mail utilisateur
 			case "change_cal_mail": {
 				$user_id=$params[1];
-				updateUserInMantis($user_id);
+				$this->updateUserInMantis($user_id);
 				break;
 			}
 			case "add_cal_link_father":
 			case "del_cal_link_father": {
 				$sub_group_id = $params[0];
 				$group_id = $params[1];
-				refreshHierarchyMantisBt();
+				$this->refreshHierarchyMantisBt();
 				break;
 			}
 			case "group_delete": {
 				$group_id=$params['group_id'];
-				$group = &group_get_object($group_id);
+				$group = group_get_object($group_id);
 				if ($group->usesPlugin($this->name)) {
-					if (isProjetMantisCreated($group->data_array['group_id'])) {
-						removeProjetMantis($group->data_array['group_id']);
+					if ($this->isProjectMantisCreated($group->data_array['group_id'])) {
+						$this->removeProjectMantis($group->data_array['group_id']);
 					}
 				}
 				break;
 			}
 			case "group_update": {
 				$group_id=$params['group_id'];
-				$group = &group_get_object($group_id);
+				$group = group_get_object($group_id);
 				if ($group->usesPlugin($this->name)) {
-					if (isProjetMantisCreated($group_id)) {
-						updateProjetMantis($group_id, $params['group_name'], $group->data_array['is_public'], $group->data_array['short_description']);
+					if ($this->isProjectMantisCreated($group_id)) {
+						$this->updateProjectMantis($group_id, $params['group_name'], $group->data_array['is_public'], $group->data_array['short_description']);
 					}
 				}
 				break;
 			}
 		}
 	}
-}
 
-function addProjetMantis($idProjet, $nomProjet, $isPublic, $description) {
+	function addProjectMantis($idProjet, $nomProjet, $isPublic, $description) {
 
-	$projet = array();
-	$project['name'] = $nomProjet;
-	$project['status'] = "development";
+		$projet = array();
+		$project['name'] = $nomProjet;
+		$project['status'] = "development";
 	
-	if ($isPublic == "1"){
-		$project['view_state'] = 10;
-	}else{
-		$project['view_state'] = 50;
-	}
+		if ($isPublic == "1"){
+			$project['view_state'] = 10;
+		}else{
+			$project['view_state'] = 50;
+		}
 
-	$project['description'] = $description;
+		$project['description'] = $description;
 	
-	try {
-		$clientSOAP = new SoapClient("http://".forge_get_config('server','mantisbt')."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
-		$idProjetMantis = $clientSOAP->__soapCall('mc_project_add', array("username" => forge_get_config('adminsoap_user', 'mantisbt'), "password" => forge_get_config('adminsoap_password', 'mantisbt'), "project" => $project));
-	} catch (SoapFault $soapFault) {
-		echo $soapFault->faultstring;
-		exit;
-	}
-	if (!isset($idProjetMantis) || !is_int($idProjetMantis)){
-		echo "Error : Impossible de créer le projet dans mantis";
-		exit;
-	}else{
-		db_query_params('INSERT INTO group_mantisbt (id_group, id_mantisbt) VALUES ($1,$2)',
-				array($idProjet, $idProjetMantis));
-		echo db_error();
-	}
-}
-
-function removeProjetMantis($idProjet) {
-	
-	$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
-					array($idProjet));
-
-	echo db_error();
-	$row = db_fetch_array($resIdProjetMantis);
-
-	if ($row == null || count($row)>2) {
-		echo 'removeProjetMantis:: ' . _('No project found');
-	}else{
-		$idMantisbt = $row['id_mantisbt'];
 		try {
-			$clientSOAP = new SoapClient("http://".forge_get_config('server','mantisbt')."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
-			$delete = $clientSOAP->__soapCall('mc_project_delete', array("username" => forge_get_config('adminsoap_user','mantisbt'), "password" => forge_get_config('adminsoap_password','mantisbt'), "project_id" => $idMantisbt));
+			$clientSOAP = new SoapClient(forge_get_config('server_url','mantisbt')."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
+			$idProjetMantis = $clientSOAP->__soapCall('mc_project_add', array("username" => forge_get_config('adminsoap_user', 'mantisbt'), "password" => forge_get_config('adminsoap_passwd', 'mantisbt'), "project" => $project));
 		} catch (SoapFault $soapFault) {
 			echo $soapFault->faultstring;
+			return false;
 		}
-		if (!isset($delete)){
-			echo 'removeProjetMantis:: ' . _('No project found in MantisBT') . ' ' .$idProjet;
+		if (!isset($idProjetMantis) || !is_int($idProjetMantis)){
+			echo 'addProjetMantis::Error: ' . _('Unable to create project in Mantisbt');
+			return false;
 		}else{
-			db_query_params('DELETE FROM group_mantisbt WHERE group_mantisbt.id_mantisbt = $1',
-					array($idMantisbt));
-			echo db_error();
+			$res = db_query_params('INSERT INTO group_mantisbt (id_group, id_mantisbt) VALUES ($1,$2)',
+					array($idProjet, $idProjetMantis));
+			if (!$res) {
+				return false;
+			}
 		}
+		return true;
 	}
-}
 
-function updateProjetMantis($idProjet,$nomProjet,$isPublic, $description) {
+	function removeProjectMantis($idProjet) {
+	
+		$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
+						array($idProjet));
 
-	$projet = array();
-	$project['name'] = $nomProjet;
-	$project['status'] = "development";
+		echo db_error();
+		$row = db_fetch_array($resIdProjetMantis);
 
-	if ($isPublic == "1"){
-		$project['view_state'] = 10;
-	}else{
-		$project['view_state'] = 50;
+		if ($row == null || count($row)>2) {
+			echo 'removeProjetMantis:: ' . _('No project found');
+		}else{
+			$idMantisbt = $row['id_mantisbt'];
+			try {
+				$clientSOAP = new SoapClient(forge_get_config('server_url','mantisbt')."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
+				$delete = $clientSOAP->__soapCall('mc_project_delete', array("username" => forge_get_config('adminsoap_user','mantisbt'), "password" => forge_get_config('adminsoap_password','mantisbt'), "project_id" => $idMantisbt));
+			} catch (SoapFault $soapFault) {
+				echo $soapFault->faultstring;
+			}
+			if (!isset($delete)){
+				echo 'removeProjetMantis:: ' . _('No project found in MantisBT') . ' ' .$idProjet;
+			}else{
+				db_query_params('DELETE FROM group_mantisbt WHERE group_mantisbt.id_mantisbt = $1',
+						array($idMantisbt));
+				echo db_error();
+			}
+		}
 	}
 
-	$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
-					array($idProjet));
-	echo db_error();
-	$row = db_fetch_array($resIdProjetMantis);
-	if ($row == null || count($row)>2) {
-		echo 'updateProjetMantis:: ' . _('No project found');
-	}else{
-		$idMantisbt = $row['id_mantisbt'];
-		try {
-			$clientSOAP = new SoapClient("http://".forge_get_config('server','mantisbt')."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
-			$update = $clientSOAP->__soapCall('mc_project_update', array("username" => forge_get_config('adminsoap_user','mantisbt'), "password" => forge_get_config('adminsoap_password','mantisbt'), "project_id" => $idMantisbt, "project" => $project));;
-		} catch (SoapFault $soapFault) {
-			echo $soapFault->faultstring;
+	function updateProjectMantis($idProjet, $nomProjet, $isPublic, $description) {
+
+		$projet = array();
+		$project['name'] = $nomProjet;
+		$project['status'] = "development";
+
+		if ($isPublic == "1"){
+			$project['view_state'] = 10;
+		}else{
+			$project['view_state'] = 50;
 		}
-		if (!isset($update))
-			echo 'updateProjetMantis::Error ' . _('Update MantisBT project');
+
+		$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
+						array($idProjet));
+		echo db_error();
+		$row = db_fetch_array($resIdProjetMantis);
+		if ($row == null || count($row)>2) {
+			echo 'updateProjetMantis:: ' . _('No project found');
+		}else{
+			$idMantisbt = $row['id_mantisbt'];
+			try {
+				$clientSOAP = new SoapClient(forge_get_config('server_url','mantisbt')."/api/soap/mantisconnect.php?wsdl", array('trace'=>true, 'exceptions'=>true));
+				$update = $clientSOAP->__soapCall('mc_project_update', array("username" => forge_get_config('adminsoap_user','mantisbt'), "password" => forge_get_config('adminsoap_password','mantisbt'), "project_id" => $idMantisbt, "project" => $project));;
+			} catch (SoapFault $soapFault) {
+				echo $soapFault->faultstring;
+			}
+			if (!isset($update))
+				echo 'updateProjetMantis::Error ' . _('Update MantisBT project');
+		}
 	}
-}
 
-function isProjetMantisCreated($idProjet){
+	function isProjectMantisCreated($idProjet){
 
 	$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
 					array($idProjet));
@@ -350,22 +352,7 @@
 	}
 }
 
-function getIdProjetMantis($idProjet){
-
-	$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
-					array($idProjet));
-	echo db_error();
-	$row = db_fetch_array($resIdProjetMantis);
-
-	if ($row == null) {
-		return 0;
-	}else{
-		return $row['id_mantisbt'];
-	}
-	
-}
-
-function updateUserInMantis($user_id) {
+	function updateUserInMantis($user_id) {
 	global $sys_mantisbt_host, $sys_mantisbt_db_user, $sys_mantisbt_db_password, $sys_mantisbt_db_port, $sys_mantisbt_db_name;
 	// recuperation du nouveau mail
 	$resUser = db_query_params ('SELECT user_name, email FROM users WHERE user_id = $1',array($user_id));
@@ -382,7 +369,7 @@
 	}
 }
 
-function updateUsersProjetMantis($idProjet, $members) {
+	function updateUsersProjectMantis($idProjet, $members) {
 
 	global $role;
 	global $sys_mantisbt_host, $sys_mantisbt_db_user, $sys_mantisbt_db_password, $sys_mantisbt_db_port, $sys_mantisbt_db_name;
@@ -445,7 +432,7 @@
 	}
 }
 
-function refreshHierarchyMantisBt(){
+	function refreshHierarchyMantisBt(){
 	global $sys_mantisbt_host, $sys_mantisbt_db_user, $sys_mantisbt_db_password, $sys_mantisbt_db_port, $sys_mantisbt_db_name;
 
 	$hierarchies=db_query_params('SELECT project_id, sub_project_id FROM plugin_projects_hierarchy WHERE activated=true',array());
@@ -477,19 +464,22 @@
 	return true;
 }
 
-function getGroupIdByName($name){
+}
 
-	$child_query = db_query_params('select group_id from groups where group_name = $1', array($name));
+function getIdProjetMantis($idProjet){
+
+	$resIdProjetMantis = db_query_params('SELECT group_mantisbt.id_mantisbt FROM group_mantisbt WHERE group_mantisbt.id_group = $1',
+					array($idProjet));
 	echo db_error();
-	$row = db_fetch_array($child_query);
+	$row = db_fetch_array($resIdProjetMantis);
 
 	if ($row == null) {
 		return 0;
 	}else{
-		return $row['group_id'];
+		return $row['id_mantisbt'];
 	}
-}
 
+}
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"

Modified: trunk/src/plugins/mantisbt/www/index.php
===================================================================
--- trunk/src/plugins/mantisbt/www/index.php	2010-11-21 19:43:46 UTC (rev 11591)
+++ trunk/src/plugins/mantisbt/www/index.php	2010-11-21 19:46:06 UTC (rev 11592)
@@ -76,9 +76,9 @@
 $username = $user->getUnixName();
 
 if (!$type) {
-	exit_missing_params($_SERVER['HTTP_REFERER'], array('No TYPE specified'),'mantisbt');
+	exit_missing_params($_SERVER['HTTP_REFERER'], array('No TYPE specified'), 'mantisbt');
 } elseif (!$id) {
-	exit_missing_params($_SERVER['HTTP_REFERER'], array('No ID specified'),'mantisbt');
+	exit_missing_params($_SERVER['HTTP_REFERER'], array('No ID specified'), 'mantisbt');
 } else {
 	switch ($type) {
 		case 'group': {
@@ -86,12 +86,12 @@
 			if ( !$group) {
 				exit_no_group();
 			}
-			if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the MantisBT plugin active
-				exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginname),'home');
+			if ( ! ($group->usesPlugin( $pluginname )) ) {//check if the group has the MantisBT plugin active
+				exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'), $pluginname), 'home');
 			}
 			$userperm = $group->getPermission($user);//we'll check if the user belongs to the group (optional)
 			if ( !$userperm->IsMember()) {
-				exit_permission_denied(_('You are not a member of this project'),'home');
+				exit_permission_denied(_('You are not a member of this project'), 'home');
 			}
 
 			// URL analysis
@@ -120,7 +120,7 @@
 				exit_error(_('Impossible de récupérer les identifiants de connexions depuis le LDAP'),'home');
 			} else {
 				// do the job
-				mantisbt_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
+				mantisbt_Project_Header(array('title'=>$pluginname . ' Project Plugin!', 'pagename'=>"$pluginname", 'sectionvals'=>array(group_getname($id))));
 				include ('mantisbt/www/group/index.php');
 			}
 			break;
@@ -154,9 +154,9 @@
 
 			$format = "%07d";
 
-			if (!is_int($password)){
+			if (!is_int($password)) {
 				// do the job
-				mantisbt_User_Header(array('title'=>'My '.$pluginname,'pagename'=>"$pluginname",'sectionvals'=>array($realuser->getUnixName())));
+				mantisbt_User_Header(array('title'=>sprintf(_('My %s'),$pluginname),'pagename'=>"$pluginname",'sectionvals'=>array($realuser->getUnixName())));
 				include ('mantisbt/www/user/index.php');
 			} else {
 				exit_error(_('Impossible de récupérer les identifiants de connexions depuis le LDAP'),'home');




More information about the Fusionforge-commits mailing list