Ver Fonte

added foreign key in Storage xsd

Piotr Labudda há 8 anos atrás
pai
commit
6648f13dee
2 ficheiros alterados com 57 adições e 0 exclusões
  1. 51 0
      SE/se-lib/Route/Storage.php
  2. 6 0
      SE/se-lib/Route/Storage/AclStruct.php

+ 51 - 0
SE/se-lib/Route/Storage.php

@@ -1025,6 +1025,41 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 		$xmlWriter->startElement('xs:complexType');
 		$xmlWriter->writeAttribute('name', $typeName);
 		$xmlWriter->startElement('xs:sequence');
+
+		$foreignKeys = [];
+		{
+			$dbName = DB::getPDO($idStorage)->getDatabaseName();
+			if ('mysql' === DB::getPDO($idStorage)->getType) {
+				$foreignKeys = DB::getPDO($idStorage)->fetchAll("
+					SELECT i.TABLE_SCHEMA, i.TABLE_NAME, i.CONSTRAINT_TYPE, i.CONSTRAINT_NAME, k.COLUMN_NAME, k.REFERENCED_TABLE_NAME, k.REFERENCED_COLUMN_NAME
+					FROM information_schema.TABLE_CONSTRAINTS i
+					LEFT JOIN information_schema.KEY_COLUMN_USAGE k ON i.CONSTRAINT_NAME = k.CONSTRAINT_NAME
+					WHERE i.TABLE_SCHEMA = :db_name
+						and i.TABLE_NAME = :tbl_name
+						and i.CONSTRAINT_TYPE = 'FOREIGN KEY'
+					ORDER BY i.TABLE_NAME
+				", [
+					':db_name' => $dbName,
+					':tbl_name' => $tblName,
+				]);
+				// if ('CRM_WSKAZNIK' === $tblName) { // @example: CRM_WSKAZNIK.ID_ZASOB => CRM_LISTA_ZASOBOW.ID
+				// 	$foreignKeys = [
+				// 		[	'TABLE_SCHEMA' => "SES_USERS2"
+				// 		,	'TABLE_NAME' => "CRM_WSKAZNIK"
+				// 		,	'CONSTRAINT_TYPE' => "FOREIGN KEY"
+				// 		,	'CONSTRAINT_NAME' => "zasob"
+				// 		,	'COLUMN_NAME' => "ID_ZASOB"
+				// 		,	'REFERENCED_TABLE_NAME' => "CRM_LISTA_ZASOBOW"
+				// 		,	'REFERENCED_COLUMN_NAME' => "ID"
+				// 		]
+				// 	];
+				// }
+				// $xmlWriter->writeComment("\$foreignKeys: " . var_export($foreignKeys, true));
+				// TABLE_SCHEMA, TABLE_NAME, CONSTRAINT_TYPE, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
+				// *	*	FOREIGN KEY	*	*	*	*
+			}
+		}
+
 		foreach ($struct as $field) {
 			$xmlWriter->startElement('xs:element');
 			$xmlWriter->writeAttribute('name', $field['name']);
@@ -1058,6 +1093,22 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 			}
 			$xmlWriter->endElement();// xs:element
 		}
+		if (!empty($foreignKeys)) {
+			foreach ($foreignKeys as $key) {
+				$xmlWriter->startElement('xs:element');
+				$refPrefix = (DB::getPDO()->getZasobId() === $idStorage) ? 'p5_default_db' : "p5_zasob_{$idStorage}";
+				$xmlWriter->writeAttribute('ref', "{$refPrefix}:{$key['REFERENCED_TABLE_NAME']}");
+					$xmlWriter->startElement('xs:annotation');
+						$xmlWriter->startElement('xs:appinfo');
+							$xmlWriter->startElement('system_cache__appinfo:flat_relation_cache');
+							$xmlWriter->writeAttribute("system_cache__appinfo:name", $key['COLUMN_NAME']);
+							$xmlWriter->writeAttribute("system_cache__appinfo:xpath", "{$refPrefix}:{$key['REFERENCED_TABLE_NAME']}/{$key['REFERENCED_COLUMN_NAME']}");
+							$xmlWriter->endElement();// system_cache__appinfo:flat_relation_cache
+						$xmlWriter->endElement();// xs:appinfo
+					$xmlWriter->endElement();// xs:annotation
+				$xmlWriter->endElement();// xs:element
+			}
+		}
 		$xmlWriter->endElement();// xs:sequence
 		$xmlWriter->endElement();// xs:complexType
 		return;

+ 6 - 0
SE/se-lib/Route/Storage/AclStruct.php

@@ -230,6 +230,12 @@ class Route_Storage_AclStruct extends RouteBase {
 					'class' => "btn btn-md btn-link",
 					'title' => "Uprawnienia - analiza użycia komórek w procesach"
 				], "Uprawnienia (analiza użycia)"),
+				UI::h('a', [
+					// $idStorage = V::get('idStorage', '', $_GET);
+					// $tblName = V::get('table', '', $_GET, 'word');
+					'href' => Router::getRoute('Storage')->getLink('tableXsd', [ 'idStorage' => $idStorage, 'table' => "{$tblName}" ]),
+					'class' => "btn btn-md btn-link",
+				], "xsd"),
 			]),
 			'cols_label' => [
 				'sort' => UI::h('nobr', [