Prechádzať zdrojové kódy

added support for Update by xlink

Piotr Labudda 9 rokov pred
rodič
commit
7def7c7c27

+ 66 - 4
SE/se-lib/Core/AclBase.php

@@ -326,8 +326,13 @@ class Core_AclBase {
         if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " F.".__FUNCTION__." validate fields loop({$idx}) loop({$fieldName}) \$fieldType({$fieldType})"."\n";}
         if ('gml:' == substr($fieldType, 0, 4)) {
           $tagValue['value'] = $this->convertGmlTagsToWkt($fieldType, $tagValue['tags']);
+        } else if ('ref:' == substr($fieldType, 0, 4)) {
+          if (1 == count($tagValue['tags'])) {
+            $tagValue['value'] = $tagValue['tags'][0]['attributes']['xlink:href'];// https://biuro.biall-net.pl/wfs/default_objects#AccessGroupRead.27
+          } else {
+            throw new Exception("Error Processing Update Request - wrong Value tag format for field '{$fieldName}' (Update/Property[{$idx}])");
+          }
         } else {
-          // TODO: return $fields[$fieldName][] = array('type'=>'open', 'typeName'=>$fieldType, 'tags'=>...
           throw new Exception("Error Processing Update Request - wrong Value tag format for field '{$fieldName}' (Update/Property[{$idx}])");
         }
       } else if ('complete' == $tagValue['type']) {
@@ -626,6 +631,15 @@ class Core_AclBase {
     ");
   }
 
+  public function _cleanRefs($childName, $pk) {// TODO: $idTransaction
+    $refTable = $this->createRefTable($childName);
+    $sqlPk = DB::getPDO()->quote($pk, PDO::PARAM_STR);
+    DB::getPDO()->exec("
+      update `{$refTable}` set `A_STATUS` = 'DELETED'
+      where `PRIMARY_KEY` = {$sqlPk}
+    ");
+  }
+
   public function createRefTable($childName) {// TODO: $idTransaction
     static $cacheRefTables = array();
     $objectName = $this->getName();
@@ -635,11 +649,23 @@ class Core_AclBase {
       CREATE TABLE IF NOT EXISTS `{$refTable}` (
         `PRIMARY_KEY` int(11) NOT NULL,
         `REMOTE_PRIMARY_KEY` int(11) NOT NULL,
+        `A_STATUS` enum('WAITING', 'NORMAL', 'DELETED') NOT NULL DEFAULT 'WAITING',
+        `A_RECORD_UPDATE_DATE` timestamp ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
         -- TODO `TRANACTION_ID` int(11) NOT NULL
         KEY `PRIMARY_KEY` (`PRIMARY_KEY`),
         KEY `REMOTE_PRIMARY_KEY` (`REMOTE_PRIMARY_KEY`)
       ) ENGINE=MyISAM DEFAULT CHARSET=latin2;
     ");
+    try {
+      DB::getPDO()->exec(" ALTER TABLE `{$refTable}` ADD `A_STATUS` enum('WAITING', 'NORMAL', 'DELETED') NOT NULL DEFAULT 'WAITING' ");
+    } catch (Exception $e) {
+      // echo 'C.'.get_class($this).' L.' . __LINE__ . " Error:";print_r($e->getMessage());echo "\n";
+    }
+    try {
+      DB::getPDO()->exec(" ALTER TABLE `{$refTable}` ADD `A_RECORD_UPDATE_DATE` timestamp ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ");
+    } catch (Exception $e) {
+      // echo 'C.'.get_class($this).' L.' . __LINE__ . " Error:";print_r($e->getMessage());echo "\n";
+    }
     $cacheRefTables[] = $refTable;
     return $refTable;
   }
@@ -653,18 +679,54 @@ class Core_AclBase {
     if (empty($action['fields'])) throw new Exception("Error Processing Request - missing Property for type '{$action['typeName']}'", 500);
     // TODO: check acl user to update record ID = $action['Filter']
     $itemPatch = array();
+    $refPatch = array();
     foreach ($action['fields'] as $fieldName => $childFields) {
+      $fieldType = $this->getXsdFieldType($fieldName);
+if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " \$fieldType:";print_r($fieldType);echo "\n";}// ref:default_objects:AccessGroupRead
       foreach ($childFields as $idx => $field) {
         if ('complete' != $field['type']) continue;// skip child nodes, REF
         $value = $field['value'];
         if ($this->isGeomField($fieldName)) $value = "GeomFromText('{$value}')";
-        $itemPatch[$fieldName] = $value;
+        if ('ref:' == substr($fieldType, 0, 4)) {
+          $refPatch[$fieldName][$idx] = $value;
+        } else {
+          $itemPatch[$fieldName] = $value;
+        }
+      }
+    }
+    $id = $itemPatch[$this->getPrimaryKeyField()] = $action['Filter'];
+    if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " updateXml action \$itemPatch({$id}):";print_r($itemPatch);echo "\n";}
+    if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " updateXml action \$refPatch:";print_r($refPatch);echo "\n";}
+
+    {
+      foreach ($refPatch as $fieldName => $childValues) {
+        $this->_cleanRefs($fieldName, $id);
+        foreach ($childValues as $idx => $value) {
+          list($nsUrl, $featureId) = explode('#', $value, 2);// https://biuro.biall-net.pl/wfs/default_objects#AccessGroupRead.27
+          list($featureName, $primaryKey) = explode('.', $featureId, 2);
+if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " \$featureId: ";print_r($featureId);echo "\n";}// AccessGroupRead.27
+if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " \$featureName: ";print_r($featureName);echo "\n";}// AccessGroupRead
+if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " \$primaryKey: ";print_r($primaryKey);echo "\n";}// 27
+if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " \$nsUrl: ";print_r($nsUrl);echo "\n";}// https://biuro.biall-net.pl/wfs/default_objects
+          $refAcl = Core_AclHelper::getAclByNamespace("{$nsUrl}/{$featureName}");
+if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " \$refAcl: ";print_r($refAcl);echo "\n";}
+          $remoteItem = $refAcl->getItem($primaryKey);
+          if (!$remoteItem) throw new Exception("Brak dostępu do obiektu: {$value}");
+if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " \$remoteItem: ";print_r($remoteItem);echo "\n";}
+          // TODO: validate
+          $this->_insertRef($fieldName, $id, $primaryKey);
+        }
       }
     }
-    $itemPatch[$this->getPrimaryKeyField()] = $action['Filter'];
-    if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " updateXml action \$itemPatch:";print_r($itemPatch);echo "\n";}
+
+if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " updateXml action \$refPatch:";print_r($refPatch);echo "\n";}
+if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " updateXml action \$itemPatch:";print_r($itemPatch);echo "\n";}
+if($DBG){die();}
+
     $affected = $this->updateItem($itemPatch);
+
     // TODO: update/insert child nodes, REF
+
     return $affected;
   }
 

+ 1 - 0
SE/se-lib/Schema/TestPermsStorageAcl.php

@@ -127,6 +127,7 @@ class Schema_TestPermsStorageAcl extends Core_AclBase {
         select r.*
         from `{$refTableName}` r
         where r.PRIMARY_KEY in({$sqlPk})
+          and r.A_STATUS != 'DELETED'
       ", $key = 'PRIMARY_KEY');
       if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";}
     }