[Mapbender-commits] r9891 - trunk/mapbender/http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Mar 26 06:47:37 PDT 2018
Author: armin11
Date: 2018-03-26 06:47:37 -0700 (Mon, 26 Mar 2018)
New Revision: 9891
Modified:
trunk/mapbender/http/php/syncCkanRoot.php
Log:
Possibility to sync the metadata of all organizations at once with root account
Modified: trunk/mapbender/http/php/syncCkanRoot.php
===================================================================
--- trunk/mapbender/http/php/syncCkanRoot.php 2018-03-26 12:30:47 UTC (rev 9890)
+++ trunk/mapbender/http/php/syncCkanRoot.php 2018-03-26 13:47:37 UTC (rev 9891)
@@ -23,18 +23,32 @@
//fix
if (isset($_REQUEST["syncDepartment"]) && $_REQUEST["syncDepartment"] !== "" && $_REQUEST["syncDepartment"] !== null) {
$testMatch = $_REQUEST["syncDepartment"];
- $pattern = '/^[0-9]*$/';
+ //$pattern = '/^[0-9]*$/';
+ $pattern = '/^[\d,]*$/';
if (!preg_match($pattern,$testMatch)){
- $resultObject->error->message = 'Parameter syncDepartment is not valid (integer).';
+ $resultObject->error->message = 'Parameter syncDepartment is not valid (integer or csv integer list).';
echo json_encode($resultObject);
die();
}
- $syncDepartment = (integer)$testMatch;
+ $syncDepartment = $testMatch;
$testMatch = NULL;
} else {
- $resultObject->error->message = 'Parameter syncDepartment not set!!!';
- echo json_encode($resultObject);
- die();
+ //try to read csv list from localhost webservice
+ if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '') {
+ $mapbenderUrl = MAPBENDER_PATH;
+ } else {
+ $mapbenderUrl = "http://www.geoportal.rlp.de/mapbender";
+ }
+ $orgaConnector = new Connector($mapbenderUrl.'/php/mod_showOpenDataOrganizations.php');
+ $orgaList = json_decode($orgaConnector->file);
+ $orgaArray = array();
+ foreach ($orgaList as $orgaEntry) {
+ if (isset($orgaEntry->id)) {
+ $orgaArray[] = $orgaEntry->serialId;
+ }
+ }
+ //$coupledOrgaList
+ $syncDepartment = implode(',', $orgaArray);
}
if (isset($_REQUEST["userId"]) & $_REQUEST["userId"] != "") {
@@ -65,71 +79,69 @@
die();
}
-//$syncDepartment = 35;
-//echo "test";
-//get user which may sync the requested department
-$sql = "SELECT fkey_mb_user_id FROM mb_user_mb_group WHERE fkey_mb_group_id = $1 AND mb_user_mb_group_type IN (2,3) ORDER BY mb_user_mb_group_type DESC LIMIT 1";
-$v = array($syncDepartment);
-$t = array('i');
-$res = db_prep_query($sql, $v, $t);
-
-$e = new mb_exception("sync department: ".$syncDepartment);
-
-$e = new mb_exception("res: ".json_encode($res));
-
-
-if (!$res || is_null($res) || empty($res)) {
- $resultObject->error->message = 'No user for publishing department data found!';
- echo json_encode($resultObject);
- die();
+//$e = new mb_exception($syncDepartment);
+//Test for csv or single value
+if (strpos($syncDepartment, ',') === false) {
+ $syncDepartmentArray = array($syncDepartment);
+ //$e = new mb_exception($syncDepartmentArray[0]);
} else {
- while($row = db_fetch_array($res)){
- $syncUserId = $row['fkey_mb_user_id'];
-
- $e = new mb_exception("syncuser: ".$syncUserId);
+ $syncDepartmentArray = explode(',', $syncDepartment);
+}
+//$e = new mb_exception(count($syncDepartmentArray));
+//result
+$syncResultArray = array();
-//***************************************************************
-$syncCkanClass = new SyncCkan();
-$syncCkanClass->mapbenderUserId = $syncUserId;
-$syncCkanClass->compareTimestamps = $compareTimestamps;
-
-$departmentsArray = $syncCkanClass->getMapbenderOrganizations();
-
-//second parameter is listAllMetadataInJson ( = true) - it is needed if we want to sync afterwards. The syncList includes all necessary information about one organization
-
-$syncListJson = $syncCkanClass->getSyncListJson($departmentsArray, true);
-
-//$syncDepartment = (string)$syncDepartment;
-$syncCkanClass->syncOrgaId = $syncDepartment;
-$syncList = json_decode($syncListJson);
-if ($syncList->success = true) {
- foreach ($syncList->result->geoportal_organization as $orga) {
- $e = new mb_exception($orga->id);
- $e = new mb_exception(gettype($orga->id));
- $e = new mb_exception($syncDepartment);
- $e = new mb_exception(gettype($syncDepartment));
- //try to sync single orga - the class has already set the syncOrgaId if wished!
- if ($syncDepartment == $orga->id) {
- //overwrite result with result from sync process
- //$syncList = json_decode($syncCkanClass->syncSingleOrga(json_encode($orga)));
- $syncList = json_decode($syncCkanClass->syncSingleDataSource(json_encode($orga), "mapbender", true));
+foreach($syncDepartmentArray as $syncDepartmentId) {
+ $syncDepartmentId = (integer)$syncDepartmentId;
+ //$syncDepartment = 35;
+ //echo "test";
+ //get user which may sync the requested department
+ $sql = "SELECT fkey_mb_user_id FROM mb_user_mb_group WHERE fkey_mb_group_id = $1 AND mb_user_mb_group_type IN (2,3) ORDER BY mb_user_mb_group_type DESC LIMIT 1";
+ $v = array($syncDepartmentId);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+ //$e = new mb_exception("sync department: ".$syncDepartmentId);
+ //$e = new mb_exception("res: ".json_encode($res));
+ if (!$res || is_null($res) || empty($res)) {
+ $resultObject->error->message = 'No user for publishing department data found!';
+ echo json_encode($resultObject);
+ die();
+ } else {
+ while($row = db_fetch_array($res)){
+ $syncUserId = $row['fkey_mb_user_id'];
+ $e = new mb_exception("syncuser: ".$syncUserId);
+ //***************************************************************
+ $syncCkanClass = new SyncCkan();
+ $syncCkanClass->mapbenderUserId = $syncUserId;
+ $syncCkanClass->compareTimestamps = $compareTimestamps;
+ $departmentsArray = $syncCkanClass->getMapbenderOrganizations();
+ //second parameter is listAllMetadataInJson ( = true) - it is needed if we want to sync afterwards. The syncList includes all necessary information about one organization
+ $syncListJson = $syncCkanClass->getSyncListJson($departmentsArray, true);
+ //$syncDepartmentId = (string)$syncDepartmentId;
+ $syncCkanClass->syncOrgaId = $syncDepartmentId;
+ $syncList = json_decode($syncListJson);
+ if ($syncList->success = true) {
+ foreach ($syncList->result->geoportal_organization as $orga) {
+ /*$e = new mb_exception($orga->id);
+ $e = new mb_exception(gettype($orga->id));
+ $e = new mb_exception($syncDepartmentId);
+ $e = new mb_exception(gettype($syncDepartmentId));*/
+ //try to sync single orga - the class has already set the syncOrgaId if wished!
+ if ($syncDepartmentId == $orga->id) {
+ //overwrite result with result from sync process
+ //$syncList = json_decode($syncCkanClass->syncSingleOrga(json_encode($orga)));
+ $syncList = json_decode($syncCkanClass->syncSingleDataSource(json_encode($orga), "mapbender", true));
+ }
+ }
+ }
+ //add new syncListJson
+ $syncResultArray[] = $syncList;
+ //$syncListJson = json_encode($syncList);
+ //***************************************************************
+ }
}
- }
}
-//create new syncListJson
-$syncListJson = json_encode($syncList);
+$syncListJson = json_encode($syncResultArray);
header('Content-type:application/json;charset=utf-8');
echo $syncListJson;
-//***************************************************************
-
-
-
-
-
-
- }
-}
-
-
-
?>
More information about the Mapbender_commits
mailing list