Piotr Labudda 9 лет назад
Родитель
Сommit
eebb1e203f
4 измененных файлов с 48 добавлено и 5 удалено
  1. 26 3
      SE/se-lib/Api/WfsServerBase.php
  2. 5 1
      SE/se-lib/FileStorage.php
  3. 16 0
      SE/se-lib/FileStorageAcl.php
  4. 1 1
      SE/se-lib/UserAcl.php

+ 26 - 3
SE/se-lib/Api/WfsServerBase.php

@@ -401,6 +401,7 @@ class Api_WfsServerBase {
 			$tblName = $tblAcl->getName();
 			$usrObjList[] = array($dataSourceName, $tblName);
 		}
+		$usrObjList[] = array('objects', 'File');
 		return $usrObjList;
 	}
 
@@ -740,7 +741,7 @@ if($DBG){echo 'L.' . __LINE__ . ' $convertedTransaction:';print_r($convertedTran
 		//			{"tag":"PARENT_ID","type":"complete","level":3,"value":"0"},
 		//	{"tag":"Update","type":"close","level":2},
 		//	{"tag":"Transaction","type":"close","level":1}]
-		if($DBG){echo "\nTODO: tags L." . __LINE__ . ":\n"; print_r($tags);echo "\n";}
+		if($DBG){echo "\ntags L." . __LINE__ . ":\n"; print_r($tags);echo "\n";}
 		$actionTag = null;
 		$prevTagName = '';
 		$theGeomField = 'the_geom';// TODO: get the geom field name from acl
@@ -755,11 +756,19 @@ if($DBG){echo 'L.' . __LINE__ . ' $convertedTransaction:';print_r($convertedTran
 					if ('open' == $tag['type'] // Insert, Update
 						|| 'complete' == $tag['type'] // Delete
 						) {
+						if($DBG){echo "\ntags loop 1 - tag: L." . __LINE__ . ":\n"; print_r($tag);echo "\n";}
 						$actionTag = array();
 						$actionTag['tag'] = substr($tag['tag'], 0, 6);
 						$actionTag['typeName'] = $tag['attributes']['typeName'];
 						if ('Insert' == substr($tag['tag'], 0, 6)) {
-							$actionTag['typeName'] = "p5_default_db:{$actionTag['typeName']}";
+							$typeNsPrefix = 'p5_default_db';
+							if (!empty($tag['attributes']['typeNsUri'])) {
+								$baseNsUri = $this->getBaseNamespaceUri();
+								if ("{$baseNsUri}/objects" == $tag['attributes']['typeNsUri']) {
+									$typeNsPrefix = 'p5_objects';
+								}
+							}
+							$actionTag['typeName'] = "{$typeNsPrefix}:{$tag['attributes']['typeName']}";
 						}
 						$featureEx = explode('.', $tag['attributes']['featureId'], 2);
 						$actionTag['featureId'] = $featureEx[1];
@@ -782,6 +791,7 @@ if($DBG){echo 'L.' . __LINE__ . ' $convertedTransaction:';print_r($convertedTran
 					}
 					break;
 				default: {// fields
+						if($DBG){echo "\ntags loop 2 - tag: L." . __LINE__ . ":\n"; print_r($tag);echo "\n";}
 						if (3 != $tag['level'] && 'close' == $tag['type']) {
 							$actionTag = null;
 						}
@@ -814,7 +824,7 @@ if($DBG){echo 'L.' . __LINE__ . ' $convertedTransaction:';print_r($convertedTran
 		$changesList = array();
 		if (!empty($itemPatchs)) {
 			foreach ($itemPatchs as $itemPatchInfo) {
-				if($DBG){echo "L." . __LINE__ . " itemPatchInfo['itemPatch']:\n";print_r($itemPatchInfo['itemPatch']);}
+				if($DBG){echo "L." . __LINE__ . " itemPatchInfo: {typeName:'{$itemPatchInfo['typeName']}'}:\n";print_r($itemPatchInfo);}
 				$acl = $this->getAclFromTypeName($itemPatchInfo['typeName']);
 				if ('Delete' == $itemPatchInfo['tag']) {
 					$itemPatch = array();
@@ -933,6 +943,7 @@ if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n
 			// <Update>
 			$theGeomField = 'the_geom';// TODO: get from fields list
 			$typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
+			if($DBG){echo 'L.' . __LINE__ . ' typeName:';print_r($typeName);echo "\n";}
 			$updateElementName = "UpdateNs{$nsInd}";
 			$geomCoordsUpdateXpath = "//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
 			$geomCoordsInsertXpath = "//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
@@ -978,6 +989,7 @@ EOF;
 					<xsl:when test="local-name() = '{$typeName}'">
 						<xsl:element name="{$insertElementName}">
 							<xsl:attribute name="typeName"><xsl:value-of select="local-name()" /></xsl:attribute>
+							<xsl:attribute name="typeNsUri"><xsl:value-of select="namespace-uri()" /></xsl:attribute>
 							<xsl:for-each select="*">
 								<xsl:element name="{local-name()}">
 									<xsl:choose>
@@ -1161,6 +1173,7 @@ if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n
 			$transactionTypesList[] = 'Insert';
 			foreach ($transactionTypesList as $transactionType) {
 				$typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
+				if($DBG){echo 'L.' . __LINE__ . ' TODO: get acl typeName:';print_r($typeName);echo "\n";}
 				$acl = $this->getAclFromTypeName($typeName);
 				$updateElementName = "{$transactionType}Ns{$nsInd}";
 				$updateElementType = "{$transactionType}Ns{$nsInd}ElementType";
@@ -1227,6 +1240,9 @@ if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n
 								$elNode->appendChild($simpleTypeNode);
 								// continue;// TODO: ? below added nillable = true, minOccurs = 0, type = $fldType
 							}
+							else if ($acl->isBinaryField($fldName)) {
+								$fldType = 'xsd:base64Binary';
+							}
 							else {
 								$fldType = 'xsd:string';
 							}
@@ -1291,6 +1307,13 @@ if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n
 				$attrNode->setAttribute('type', 'xsd:token');
 				$attrNode->setAttribute('use', 'required');
 
+				if ($transactionType == 'Insert') {
+					$attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
+					$updateTypeNode->appendChild($attrNode);
+					$attrNode->setAttribute('name', 'typeNsUri');
+					$attrNode->setAttribute('type', 'xsd:anyURI');
+					$attrNode->setAttribute('use', 'required');
+				}
 				if ($transactionType == 'Update') {
 					$attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
 					$updateTypeNode->appendChild($attrNode);

+ 5 - 1
SE/se-lib/FileStorage.php

@@ -3,6 +3,10 @@
 
 Lib::loadClass('Http');
 
+/**
+ * @example: FileStorage::addFile($binaryContent, $name);
+ */
+
 /*
 # FileStorage:
 - [x] create CRM_FILES - sql at the end of file
@@ -112,7 +116,7 @@ class FileStorage {
 		@chmod($dirPath, $mode = 0777);
 
 		$fp = fopen($absFilePath, 'w');
-		fwrite($fp, $fileContent);
+		fwrite($fp, $content);
 		fclose($fp);
 
 		if (!file_exists($absFilePath)) throw new Exception("Cannot save file");

+ 16 - 0
SE/se-lib/FileStorageAcl.php

@@ -11,6 +11,7 @@ class FileStorageAcl {
 
   public function init($force = false) {}
   public function isInitialized() { return true; }
+  public function getName() { return 'File'; }
   public function getRealFieldListByIdZasob($force = false) {
     $cols = array();// FileStorage::getFileById()
     $cols[1] = 'id';
@@ -111,7 +112,22 @@ class FileStorageAcl {
     }
     return $items;
   }
+  public function addItem($itemTodo) {
+    if (is_object($itemTodo)) {
+			$itemTodo = (array)$itemTodo;
+		}
+    if (!is_array($itemTodo)) throw new HttpException('Item is not array', 400);
+		if (empty($itemTodo)) {
+			DBG::_('DBG_DS', '>2', "Item patch is empty", null, __CLASS__, __FUNCTION__, __LINE__);
+			return 0;// nothing to insert
+		}
+    if (empty($itemTodo['content'])) throw new Exception("Empty file content");
+    $fileName = V::get('name', '', $itemTodo);
+    $binaryContent = base64_decode($itemTodo['content']);
+    return FileStorage::addFile($binaryContent, $fileName);
+  }
 
+  public function getGeomFieldType() { return null; }
   public function getPrimaryKeyField() { return 'id'; }
   public function getID() { return 0; }
   public function getAttributesFromZasoby() {

+ 1 - 1
SE/se-lib/UserAcl.php

@@ -158,7 +158,7 @@ class UserAcl {
 	public function getObjectAcl($sourceName, $objName) {
 		if ('default_db' == $sourceName) {
 			$zasobTblInfo = ProcesHelper::getZasobTableInfoByUri("{$sourceName}/{$objName}");
-			if (!$zasobTblInfo) throw new HttpException("Object not Found", 404);
+			if (!$zasobTblInfo) throw new HttpException("Object not Found '{$objName}'", 404);
 			if ($this->hasTableAcl($zasobTblInfo->ID)) {
 				return $this->getTableAcl($zasobTblInfo->ID);
 			}