[Mapbender-commits] r10265 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Sep 20 05:37:31 PDT 2019


Author: armin11
Date: 2019-09-20 05:37:31 -0700 (Fri, 20 Sep 2019)
New Revision: 10265

Modified:
   trunk/mapbender/http/php/mod_syncCkan_server.php
Log:
Fix for ckan 2.8+ - set id to update user

Modified: trunk/mapbender/http/php/mod_syncCkan_server.php
===================================================================
--- trunk/mapbender/http/php/mod_syncCkan_server.php	2019-09-18 14:35:16 UTC (rev 10264)
+++ trunk/mapbender/http/php/mod_syncCkan_server.php	2019-09-20 12:37:31 UTC (rev 10265)
@@ -268,8 +268,6 @@
 if (isset($orgaId)){
 	$sql4 .= " AND mb_group_id = ".$orgaId."";
 } 
-
-
 	switch ($showOnlyDatasetMetadata) {
 		case "true":
 			if ($showOnlyUnlinkedOrganizations == "true") {
@@ -321,12 +319,13 @@
 				//try to read orga
 				$ckanResult = $syncCkanClass->getRemoteCkanOrga($requestPostJson);
 				$ckanResultObject = json_decode($ckanResult);
+				$e = new mb_notice("php/mod_syncCkan_server.php: check for existing orga in external ckan instance: ".$requestPostJson);
 				if ($ckanResultObject->success == true) {
 					//give back ckan id of organization
-$e = new mb_exception("orga found!");
+					$e = new mb_notice("php/mod_syncCkan_server.php: identical orga found in ckan");
 					//get revision_list of organization to get last change date!
 					$ckanResultOrgaRevList = $syncCkanClass->getRemoteCkanOrgaRevList($requestPostJson);
-$e = new mb_exception("orga rev list: ".$ckanResultOrgaRevList);
+//$e = new mb_exception("orga rev list: ".$ckanResultOrgaRevList);
 					//extract last timestamp:
 					$ckanResultOrgaRevListObject = json_decode($ckanResultOrgaRevList);
 					//check for update if needed!
@@ -337,30 +336,33 @@
 					}
 					//$dateTimeCkanOrga = new DateTime($ckanResultObject->result->created);
                                 	$dateTimeMapbenderOrga = new DateTime($orga->updated);
-
-$e = new mb_exception("datetime ckan: ".$dateTimeCkanOrga->format('Y-m-d H:i:s')." - datetime mapbender: ".$dateTimeMapbenderOrga->format('Y-m-d H:i:s'));
+					$e = new mb_notice("php/mod_syncCkan_server.php: compare timestamp of organizations: datetime ckan: ".$dateTimeCkanOrga->format('Y-m-d H:i:s')." - datetime mapbender: ".$dateTimeMapbenderOrga->format('Y-m-d H:i:s'));
     					if (($dateTimeCkanOrga < $dateTimeMapbenderOrga) || $ckanResultObject->result->state == "deleted") {
 						$ckanOrgaRepresentation = $syncCkanClass->getInternalOrgaAsCkan($orga->serialId);
 						$ckanResult = $syncCkanClass->updateRemoteCkanOrga($ckanOrgaRepresentation);
-$e = new mb_exception("update organization ! ".$ckanResult); //id needed!!!!
+						$e = new mb_notice("php/mod_syncCkan_server.php: update organization! ".$ckanResult); //id needed!!!!
     					} else {
-$e = new mb_exception("no update required!");
+						$e = new mb_notice("php/mod_syncCkan_server.php: no update of organization required!");
 					}
 				} else {
-$e = new mb_exception("organization not found - try to create it!");
+					$e = new mb_notice("php/mod_syncCkan_server.php: organization not found in ckan - try to create it!");
     					//try to create it
+					//forgotten to initialize a new group, when the uuid is alread available, but 
+					$ckanOrgaRepresentation = $syncCkanClass->getInternalOrgaAsCkan($orga->serialId);
+//$e = new mb_exception("php/mod_syncCkan_server.php: try to create group id: ".$orga->serialId." ".$ckanOrgaRepresentation);
     					$ckanResult = $syncCkanClass->createRemoteCkanOrga($ckanOrgaRepresentation);
-$e = new mb_exception("result of creation: ". $ckanResult);
+//$e = new mb_exception("php/mod_syncCkan_server.php: result of creation: ". $ckanResult);
     					$ckanResultObject = json_decode($ckanResult);
     					if ($ckanResultObject->success == true) {
-$e = new mb_exception("organization successfully created!: ");
+						$e = new mb_notice("php/mod_syncCkan_server.php: organization successfully created!");
     					} else {
-						$e = new mb_exception("an error occured when trying to create organization via ckan api! ");
+						$e = new mb_notice("php/mod_syncCkan_server.php: an error occured when trying to create organization via ckan api!");
     					}
 				}	
 			} else {
-				//read ckan representation of internal group from registry
+				//read ckan representation of internal group from registry - sync all ckan orgas with mapbender!!!!
 				$ckanOrgaRepresentation = $syncCkanClass->getInternalOrgaAsCkan($orga->serialId);
+				//$e = new mb_exception("php/mod_syncCkan_server.php: returned ckan orga from mapbender: ".$ckanOrgaRepresentation);
 				$ckanOrgaRepresentationObject = json_decode($ckanOrgaRepresentation);
 				$ckanOrgaPreferredName = $ckanOrgaRepresentationObject->name;
 				$requestPost = new stdClass();
@@ -368,16 +370,16 @@
 				$requestPostJson = json_encode($requestPost);
 				//check if already exists and/or state is "deleted"- than update and set to active
 				$ckanResult = $syncCkanClass->getRemoteCkanOrga($requestPostJson);
-$e = new mb_exception("remote ckan organization: ".$ckanResult);
+//$e = new mb_exception("php/mod_syncCkan_server.php: remote ckan organization: ".$ckanResult);
 				$ckanResultObject = json_decode($ckanResult);
 				if ($ckanResultObject->success == false) {
-$e = new mb_exception("organization not found - try to create it!");
+					$e = new mb_notice("php/mod_syncCkan_server.php: organization not found - try to create it!");
     					//try to create it
     					$ckanResult = $syncCkanClass->createRemoteCkanOrga($ckanOrgaRepresentation);
-$e = new mb_exception("result of creation: ". $ckanResult);
+//$e = new mb_exception("php/mod_syncCkan_server.php: result of creation: ". $ckanResult);
     					$ckanResultObject = json_decode($ckanResult);
     					if ($ckanResultObject->success == true) {
-$e = new mb_exception("organization successfully created!: ");
+//$e = new mb_exception("php/mod_syncCkan_server.php: organization successfully created!: ");
 						//store uuid of external created ckan organization into mapbender database as foreign key
 						$sql = "UPDATE mb_group SET mb_group_ckan_uuid = $1 WHERE mb_group_id = $2";
 						$v = array($ckanResultObject->result->id, $orga->serialId);		
@@ -408,7 +410,7 @@
 					$ckanOrgaRepresentationObject->id = $ckanResultObject->result->id;
 					$ckanOrgaRepresentation = json_encode($ckanOrgaRepresentationObject);
 					$ckanResultOrgaRevList = $syncCkanClass->getRemoteCkanOrgaRevList($requestPostJson);
-$e = new mb_exception("orga rev list: ".$ckanResultOrgaRevList);
+//$e = new mb_exception("orga rev list: ".$ckanResultOrgaRevList);
 					//extract last timestamp:
 					$ckanResultOrgaRevListObject = json_decode($ckanResultOrgaRevList);
 					//check for update if needed!
@@ -423,7 +425,7 @@
                                 	$dateTimeMapbenderOrga = new DateTime($orga->updated);
     					if (($dateTimeCkanOrga < $dateTimeMapbenderOrga) || $ckanResultObject->result->state == "deleted") {
 						$ckanResult = $syncCkanClass->updateRemoteCkanOrga($ckanOrgaRepresentation);
-$e = new mb_exception("update organization ! ".$ckanResult); //id needed!!!!
+						//$e = new mb_exception("update organization ! ".$ckanResult); //id needed!!!!
     					}
 				}
 			}
@@ -435,13 +437,13 @@
 			$requestPost->{'id'} = $editingUserName;
 			$requestPostJson = json_encode($requestPost);
 			$ckanResultUser = $syncCkanClass->getRemoteCkanUser($requestPostJson);
-$e = new mb_exception("get user:  ".$ckanResultUser); //id needed!!!!
-			$ckanResultUserObject = json_decode($ckanResultUser);
-		
+			$ckanResultUserObject = json_decode($ckanResultUser);	
 			if ($ckanResultUserObject->success == true) {
 				//check if user has already editor role in organization
 			        //update user
 				$requestPost = new stdClass();
+				//get id from user if already exists - is needed for update since ckan 2.8+!
+				$requestPost->{'id'} = $ckanResultUserObject->result->id;
 				$requestPost->{'name'} = $editingUserName;
 				$requestPost->{'email'} = "kontakt at geoportal.rlp.de";
 				$requestPost->{'password'} = "1234".$editingUserName."5678";
@@ -450,7 +452,6 @@
 				//$requestPost->groups[1]->name = "opendata";
 				$requestPostJson = json_encode($requestPost);
 				$ckanResultUser = $syncCkanClass->updateRemoteCkanUser($requestPostJson);
-$e = new mb_exception("update user:  ".$ckanResultUser);
 				$ckanResultUserObject = json_decode($ckanResultUser);
 			} else {
 				//create user
@@ -460,7 +461,7 @@
 				$requestPost->{'password'} = "1234".$editingUserName."5678";
 				$requestPostJson = json_encode($requestPost);
 				$ckanResultUser = $syncCkanClass->createRemoteCkanUser($requestPostJson);
-$e = new mb_exception("get user:  ".$ckanResultUser);
+//$e = new mb_exception("get user:  ".$ckanResultUser);
 				$ckanResultUserObject = json_decode($ckanResultUser);
 
 			}
@@ -486,9 +487,9 @@
 			$requestPost->{'capacity'} = "editor";
 			$requestPostJson = json_encode($requestPost);
 			$ckanResultMember = $syncCkanClass->getRemoteCkanMember($requestPostJson);
-$e = new mb_exception("get member:  ".$ckanResultMember);
+//$e = new mb_exception("get member:  ".$ckanResultMember);
 			$ckanResultMemberObject = json_decode($ckanResultMember);
-$e = new mb_exception("number of editors:  ".count($ckanResultMemberObject->result));
+//$e = new mb_exception("number of editors:  ".count($ckanResultMemberObject->result));
 			if (count($ckanResultMemberObject->result == 0)) {
 				//add membership for editor
 				$requestPost = new stdClass();
@@ -498,27 +499,22 @@
 				$requestPost->{'capacity'} = "editor";
 				$requestPostJson = json_encode($requestPost);
 				$ckanResultMember = $syncCkanClass->createRemoteCkanMember($requestPostJson);
-$e = new mb_exception("get member after creating:  ".$ckanResultMember);
+//$e = new mb_exception("get member after creating:  ".$ckanResultMember);
 			}
 			//add user with role editor to groups "transparenzgesetz" and "opendata"
 			//add membership for editor
+			if (defined("CKAN_EDITOR_DEFAULT_GROUPS") && is_array(CKAN_EDITOR_DEFAULT_GROUPS)) {
+			    foreach(CKAN_EDITOR_DEFAULT_GROUPS as $ckanGroup) {
 			$requestPost = new stdClass();
-			$requestPost->{'id'} = "transparenzgesetz";
+			$requestPost->{'id'} = $ckanGroup;
 			$requestPost->{'object'} = $userId;
 			$requestPost->{'object_type'} = "user";
 			$requestPost->{'capacity'} = "editor";
 			$requestPostJson = json_encode($requestPost);
 			$ckanResultMember = $syncCkanClass->createRemoteCkanMember($requestPostJson);
-$e = new mb_exception("get member after creating:  ".$ckanResultMember);
-			$requestPost = new stdClass();
-			$requestPost->{'id'} = "opendata";
-			$requestPost->{'object'} = $userId;
-			$requestPost->{'object_type'} = "user";
-			$requestPost->{'capacity'} = "editor";
-			$requestPostJson = json_encode($requestPost);
-			$ckanResultMember = $syncCkanClass->createRemoteCkanMember($requestPostJson);
-$e = new mb_exception("get member after creating:  ".$ckanResultMember);		
-		//}
+//$e = new mb_exception("get member after creating:  ".$ckanResultMember);
+			    }
+			}		
 	}
 	header('Content-Type: application/json; charset='.CHARSET);
 	echo json_encode($returnObject, JSON_NUMERIC_CHECK);



More information about the Mapbender_commits mailing list