Przeglądaj źródła

fixed charset in instance view for polish chars

Piotr Labudda 8 lat temu
rodzic
commit
73338f8131

+ 2 - 1
SE/schema/ant-object/default_db.IN7_DZIENNIK_KORESP/IN7_DZIENNIK_KORESP/IN7_DZIENNIK_KORESP.xsd

@@ -187,10 +187,11 @@
    </xs:simpleType>
    <xs:complexType name="IN7_DZIENNIK_KORESP">
       <xs:annotation>
-         <xs:documentation>Podstawowy obiekt korespondencji rozumiany jako dokument. 
+         <xs:documentation>Podstawowy obiekt korespondencji rozumiany jako dokument.
 TODO będzie musiał być rozbudowywany o elementy np. kto podpisał, stany podpisania , stany wysyłki/dostarczenia.
 Jest on w relacji w obiekcie default_object_types:KUWETA/SKOROSZYT</xs:documentation>
          <xs:appinfo>
+            <system_cache__appinfo:table_structure system_cache__appinfo:charset="latin2"/>
             <system_cache__appinfo:heritage>
                <system_cache__appinfo:inherit system_cache__appinfo:inherit_ref="default_db:IN7_DZIENNIK_KORESP"
                                               system_cache__appinfo:heritage_acl="true">

+ 9 - 15
SE/se-lib/Schema/SystemObjectFieldStorageAcl.php

@@ -62,7 +62,14 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
 		if (!$namespace) return;
 
 		DB::getPDO()->update($this->_rootTableName, 'objectNamespace', $namespace, ['isActive' => 0]);
-		DB::getPDO()->update("{$this->_enumRootTableName}", 'objectNamespace', $namespace, ['isActive' => 0]);
+		DB::getPDO()->execSql("
+			DELETE from `{$this->_enumRootTableName}`
+			where isActive = 0
+				and objectNamespace = :objectNamespace
+		", [
+			':objectNamespace' => $namespace,
+		]);
+		DB::getPDO()->update($this->_enumRootTableName, 'objectNamespace', $namespace, ['isActive' => 0]);
 		if (!$namespace) throw new Exception("Missing namespace '{$namespace}'");
 		$objectItem = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace);
 		DBG::nicePrint($objectItem, '$objectItem');
@@ -151,6 +158,7 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
 			'namespace' => $item['namespace'],
 			'isStructInstalled' => 1,
 			'primaryKey' => $xsdType['primaryKey'],
+			'appInfo' => json_encode($xsdType['appInfo']),
 		]);
 
 		DB::getPDO()->execSql("
@@ -173,20 +181,6 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
 			where t.objectNamespace = '{$item['namespace']}'
 		");
 		UI::alert('success', "Gotowe");
-
-		{// TODO: DBG
-			$schema = XML::readXmlFileToArray("{$antAclPath}/{$item['name']}.xsd");
-			DBG::nicePrint($schema, '$schema');
-			Lib::loadClass('Core_XmlWriter');
-			ob_start();
-			$xmlWriter = new Core_XmlWriter();
-			$xmlWriter->openUri('php://output');
-			$xmlWriter->setIndent(true);
-			$xmlWriter->startDocument('1.0','UTF-8');
-			$xmlWriter->h($schema[0], $schema[1], $schema[2]);
-			$xmlWriter->endDocument();
-			echo UI::h('pre', ['style' => 'max-height:400px; overflow:scroll'], htmlspecialchars(ob_get_clean()));
-		}
 	}
 	public function updateCacheStorageAcl($item) {
 		Lib::loadClass('SchemaFactory');

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

@@ -457,6 +457,7 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 			if ('isStructInstalled' == $fieldName) continue;
 			if ('isObjectActive' == $fieldName) continue;
 			if ('primaryKey' == $fieldName) continue;
+			if ('appInfo' == $fieldName) continue;
 			throw new Exception("Update field '{$fieldName}' not allowed for '{$this->_namespace}'");
 		}
 		return DB::getPDO()->update($this->_rootTableName, $pkField, $pk, $itemPatch);

+ 42 - 27
SE/se-lib/XML.php

@@ -290,7 +290,7 @@ class XML {
 						foreach ($c[2] as $cc) {
 							if ('appinfo' == XML::getTagName($cc[0])) {
 								foreach ($cc[2] as $appTag) {
-									$appInfo[ XML::getTagName($appTag[0]) ] = XML::readAppInfoRecurse($docArray, $appTag);
+									$appInfo[ XML::getTagName($appTag[0]) ] = XML::readAppInfoRecurse($appTag);
 								}
 							}
 						}
@@ -325,14 +325,16 @@ class XML {
 		}
 		return false;
 	}
+	static function isXsdNodeAnnotation($xsdNode) { return self::isXsdTag($xsdNode[0], 'annotation'); }
+	static function isXsdNodeAppInfo($xsdNode) { return self::isXsdTag($xsdNode[0], 'appinfo'); }
 
-	public static function readAppInfoRecurse($docArray, $nodeArray) {
+	public static function readAppInfoRecurse($nodeArray) {
 		$appInfo = [];
 		if (!empty($nodeArray[1])) foreach ($nodeArray[1] as $attrName => $attrVal) {
 			$appInfo['@' . XML::getTagName($attrName)] = $attrVal;
 		}
 		if (!empty($nodeArray[2])) foreach ($nodeArray[2] as $appTag) {
-			$appInfo[ XML::getTagName($appTag[0]) ] = XML::readAppInfoRecurse($docArray, $appTag);
+			$appInfo[ XML::getTagName($appTag[0]) ] = XML::readAppInfoRecurse($appTag);
 		}
 		// TODO: text nodes
 		return $appInfo;
@@ -448,32 +450,45 @@ class XML {
 		if (!$xsdType['nsUri']) throw new Exception("Missing schema root element namespace declaration = '{$name}'");
 		if ($xsdType['nsUri'] != $xsdType['targetNsUri']) throw new Exception("TODO: type ns is not the same as targetNamespace '{$name}'");// TODO
 
-		foreach ($schema[2] as $n) {
-			if (!XML::isXsdTag($n[0], 'complexType')) continue;
-			if ($xsdType['name'] != V::get('name', '', $n[1])) continue;
-			DBG::log($n, 'array', "find system_cache__appinfo:primaryKey from complexType");
-			if (array_key_exists('system_cache__appinfo:primaryKey', $n[1])) {
-				$xsdType['primaryKey'] = V::get('system_cache__appinfo:primaryKey', '', $n[1]);
-			}
-			// complexType/sequence/element
-			// complexType/complexContent/extension[base=...]/sequence/element
-			switch ($n[2][0][0]) {
-				case 'xs:sequence':
-				case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $n[2][0]); break;
-				case 'xs:complexContent':
-				case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $n[2][0]); break;
-				case 'xs:annotation':
-				case 'xsd:annotation': {
-					switch ($n[2][1][0]) {
-						case 'xs:sequence':
-						case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $n[2][1]); break;
-						case 'xs:complexContent':
-						case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $n[2][1]); break;
-					}
-				} break;
+		$foundComplexTypes = array_filter($schema[2], function ($n) use ($xsdType) {
+			return (XML::isXsdTag($n[0], 'complexType') && $xsdType['name'] === V::get('name', '', $n[1]));
+		});
+		if (empty($foundComplexTypes)) throw new Exception("Missing complexType node with name='{$xsdType['name']}'");
+		$nodeComplexType = reset($foundComplexTypes);
+
+		DBG::log($nodeComplexType, 'array', "found main complexType node");
+		if (array_key_exists('system_cache__appinfo:primaryKey', $nodeComplexType[1])) {
+			$xsdType['primaryKey'] = V::get('system_cache__appinfo:primaryKey', '', $nodeComplexType[1]);
+		}
+		$listAnnotations = array_filter($nodeComplexType[2], [ self, 'isXsdNodeAnnotation' ]);
+		if (!empty($listAnnotations)) {
+			// DBG::nicePrint($listAnnotations, "\$listAnnotations");
+			$nodeAnnotation = reset($listAnnotations);
+			$listAppInfo = array_filter($nodeAnnotation[2], [ self, 'isXsdNodeAppInfo' ]);
+			if (!empty($listAppInfo)) {
+				// DBG::nicePrint($listAppInfo, "\$listAppInfo");
+				$nodeAppInfo = reset($listAppInfo);
+				$xsdType['appInfo'] = XML::readAppInfoRecurse($nodeAppInfo);
 			}
-			// if ($n[2][0][0] != 'xsd:complexContent') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent'");
 		}
+		// complexType/sequence/element
+		// complexType/complexContent/extension[base=...]/sequence/element
+		switch ($nodeComplexType[2][0][0]) { // TODO: convert to loop
+			case 'xs:sequence':
+			case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $nodeComplexType[2][0]); break;
+			case 'xs:complexContent':
+			case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $nodeComplexType[2][0]); break;
+			case 'xs:annotation':
+			case 'xsd:annotation': {
+				switch ($nodeComplexType[2][1][0]) {
+					case 'xs:sequence':
+					case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $nodeComplexType[2][1]); break;
+					case 'xs:complexContent':
+					case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $nodeComplexType[2][1]); break;
+				}
+			} break;
+		}
+		// if ($n[2][0][0] != 'xsd:complexContent') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent'");
 		if (empty($xsdType['primaryKey'])) {
 			foreach ($xsdType['struct'] as $fieldName => $field) {
 				if ('ID' === strtoupper($fieldName)) {