Parcourir la source

synced code from biall

Piotr Labudda il y a 8 ans
Parent
commit
37653a29ef

+ 9 - 1
SE/se-lib/ACL.php

@@ -557,7 +557,15 @@ class ACL {
 		}
 		if (!$objectItem['isStructInstalled']) throw new Exception("Object structure not installed '{$namespace}'");
 
-		if ($objectItem['idDatabase'] != DB::getPDO()->getZasobId()) throw new Exception("Only default_db supported"); // TODO: support more Sources
+		if ($objectItem['idDatabase'] != DB::getPDO()->getZasobId()) {
+			if ('StorageAcl' === $objectItem['_type']) {
+				DBG::log("getRootNamespace...");
+				return $objectItem['namespace'];
+			}
+			else {
+				throw new Exception("Only default_db supported"); // TODO: support more Sources
+			}
+		}
 
 		return "default_db/{$objectItem['_rootTableName']}";
 	}

+ 8 - 3
SE/se-lib/Core/Pdo.php

@@ -466,10 +466,15 @@ EOF_STRUCT_MYSQL;
 		return $sth->fetchAll();
 	}
 
-	public function fetchAllByKey($sql, $key = 'ID') {
-		DBG::log($sql, 'sql');
+	public function fetchAllByKey($sql, $key = 'ID', $values = []) {
 		$rowsByKey = array();
 		$sth = $this->prepare($sql);
+		if (!empty($values)) {
+			$this->bindValues($sth, $values);
+			DBG::log($this->getRawSql($sth), 'sql');
+		} else {
+			DBG::log($sql, 'sql');
+		}
 		$sth->execute();
 		$rows = $sth->fetchAll();
 		foreach ($rows as $row) {
@@ -519,7 +524,7 @@ EOF_STRUCT_MYSQL;
 			foreach ($params as $name => $val) {
 				$outValue = $val[0];
 				if (PDO::PARAM_STR == $val[1]) $outValue = "'{$outValue}'";
-				$sql = str_replace(":{$name}", $outValue, $sql);
+				$sql = str_replace((':' === $name[0] ? $name : ":{$name}"), $outValue, $sql);
 			}
 		}
 		return $sql;

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

@@ -1388,9 +1388,13 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 		}
 
 		$idZasobFound = 0;
+		if ('StorageAcl' === $objectItem['_type']) {
+			if (!$objectItem['idDatabase']) throw new Exception("Brak idDatabase dla '{$objectItem['namespace']}'");
+		}
 		switch ($objectItem['_type']) {
 			case 'TableAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['name']}' "); break;
 			case 'AntAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['namespace']}' "); break;
+			case 'StorageAcl': $idZasobFound = DB::getPDO()->fetchValue(" select ID from CRM_LISTA_ZASOBOW where PARENT_ID = {$objectItem['idDatabase']} and `DESC` = '{$objectItem['namespace']}' "); break;
 			default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'");
 		}
 
@@ -1438,6 +1442,14 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 					'DESC_PL' => $objectItem['name'],
 				];
 				break;
+			case 'StorageAcl':
+				$newZasobItem = [
+					'PARENT_ID' => $objectItem['idDatabase'],
+					'TYPE' => 'TABELA',
+					'DESC' => $objectItem['namespace'],
+					'DESC_PL' => $objectItem['name'],
+				];
+				break;
 			default: throw new Exception("Not implemented acl type '{$objectItem['_type']}'");
 		}
 

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

@@ -39,6 +39,7 @@ class Route_Storage_AclStruct extends RouteBase {
 			switch ($item['_type']) {
 				case 'TableAcl': $this->tableStructView($item, $item['name'], $item['idDatabase']); break;
 				case 'AntAcl': $this->objectStructView($item); break;
+				case 'StorageAcl': $this->objectStructView($item); break;
 				default: throw new Exception("Not implemented type"); break;
 			}
 		} catch (Exception $e) {

+ 59 - 0
SE/se-lib/Schema/SystemObjectFieldStorageAcl.php

@@ -95,6 +95,7 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
 		switch ($objectItem['_type']) {
 			case 'AntAcl': $this->updateCacheAntAcl($objectItem); break;
 			case 'TableAcl': $this->updateCacheTableAcl($objectItem); break;
+			case 'StorageAcl': $this->updateCacheStorageAcl($objectItem); break;
 			default: throw new Exception("TODO: Not Implemented type '{$objectItem['_type']}'");
 		}
 		// TODO: mv from methods: SchemaFactory::loadDefaultObject('SystemObject')->updateItem([
@@ -189,6 +190,64 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
 			echo UI::h('pre', ['style' => 'max-height:400px; overflow:scroll'], htmlspecialchars(ob_get_clean()));
 		}
 	}
+	public function updateCacheStorageAcl($item) {
+		Lib::loadClass('SchemaFactory');
+		$aclName = substr($item['namespace'], strlen('default_objects/'));
+		DBG::log($aclName, 'array', "\$aclName");
+		$fvAcl = SchemaFactory::loadDefaultObject($aclName);
+		DBG::log($fvAcl->getFields(), 'array', "\$fvAcl->getFields()");
+		foreach ($fvAcl->getFields() as $field) {
+			// 'name' => 'id',
+			// 'perms' => '',
+			// 'idZasob' => 10000,
+			// 'xsdType' => 'xsd:integer',
+			// 'label' => 'id',
+			$fieldName = $field['name'];
+			$xsdType = $field['xsdType'];
+			DB::getPDO()->insertOrUpdate($this->_rootTableName, [
+				'namespace' => "{$item['namespace']}/{$fieldName}",
+				'objectNamespace' => $item['namespace'],
+				'idDatabase' => $item['idDatabase'],
+				'_rootTableName' => $item['_rootTableName'],
+				'fieldNamespace' => $fieldName,
+				'xsdType' => $xsdType,
+				// 'xsdRestrictions' => '',
+				// 'appInfo' => '',
+				// 'minOccurs' => '',
+				// 'maxOccurs' => '',
+				'isActive' => 1
+			]);
+			$listEnum = [];
+			if (!empty($listEnum)) {
+				DBG::nicePrint($listEnum, '$listEnum');
+				foreach ($listEnum as $value => $label) {
+					DB::getPDO()->insertOrUpdate("{$this->_rootTableName}_enum", [
+						'namespace' => "{$item['namespace']}/{$fieldName}/@{$value}",
+						'fieldNamespace' => $fieldName,
+						'objectNamespace' => $item['namespace'],
+						'value' => $value,
+						'label' => $label,
+						'isActive' => 1
+					]);
+				}
+			}
+		}
+		SchemaFactory::loadDefaultObject('SystemObject')->updateItem([
+			'namespace' => $item['namespace'],
+			'isStructInstalled' => 1
+		]);
+		// $zasobTableName = substr($item['objectNamespace'], strlen('default_db/'));
+		// $zasobTableName = (false !== strpos($zasobTableName, '/'))
+		// ? $item['objectNamespace']
+		// : $zasobTableName;
+		// DB::getPDO()->execSql("
+		// 	update `{$this->_rootTableName}` t
+		// 	join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = {$item['idDatabase']} and zp.`DESC` = '{$zasobTableName}')
+		// 	join CRM_LISTA_ZASOBOW z on(z.PARENT_ID = zp.ID and z.`DESC` = t.fieldNamespace)
+		// 	set t.idZasob = z.ID
+		// 	where t.objectNamespace = '{$item['namespace']}'
+		// ");
+	}
 	public function updateCacheTableAcl($item) {
 		// TODO: xsdType - convert mysql type to xsdType, xsdRestrictions
 		$xsdInfo = [];

+ 10 - 2
SE/se-lib/Schema/SystemObjectStorageAcl.php

@@ -113,8 +113,15 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 		$sourceStorage = SchemaFactory::loadDefaultObject('SystemSource');
 		foreach ($sourceStorage->getItems([ 'f_hasConfig' => 1 ]) as $source) {
 			if ('default_objects' == $source['nsPrefix']) {
-				foreach (glob(APP_PATH_LIB . "/Schema/*StorageAcl.php", GLOB_NOSORT) as $file) {
-					$clsName = substr(basename($file), 0, -1 * strlen('StorageAcl.php'));
+				$clsFiles = array_map(function ($clsFile) {
+					return substr($clsFile, strlen(APP_PATH_LIB . "/Schema/"), -1 * strlen('StorageAcl.php'));
+					// return str_replace('/', '_', substr($clsFile, strlen(APP_PATH_LIB . "/Schema/"), -1 * strlen('StorageAcl.php')));
+				}, array_merge(
+					glob(APP_PATH_LIB . "/Schema/*StorageAcl.php", GLOB_NOSORT),
+					glob(APP_PATH_LIB . "/Schema/*/*StorageAcl.php", GLOB_NOSORT)
+				));
+				DBG::log($clsFiles, 'array', "DBG glob default_objects");
+				foreach ($clsFiles as $clsName) {
 					try {
 						$acl = SchemaFactory::loadDefaultObject($clsName);
 						$namespace = $acl->getNamespace();
@@ -122,6 +129,7 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 							'namespace' => $namespace,
 							'idDatabase' => $source['idZasob'],
 							'_type' => "StorageAcl",
+							'_rootTableName' => $acl->getRootTableName(),
 							'hasStruct' => 1
 						]);
 					} catch (Exception $e) {

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

@@ -52,7 +52,6 @@ class TableAcl extends Core_AclBase {
 		if (empty($this->_name)) return null;// throw new Exception("Table name not defined");
 		if ($this->_rootTableName) return $this->_rootTableName;
 		if (!$this->_db) return null;// throw new Exception("Database not defined in table {$this->_zasobID}");
-		DBG::simpleLog('auth', "TableAcl::getRootTableName(name: '{$this->_name}')");
 		$dbName = DB::getPDO($this->_db)->getDatabaseName();
 		$this->_rootTableName = DB::getPDO()->fetchValue("
 			select t.TABLE_NAME
@@ -61,6 +60,7 @@ class TableAcl extends Core_AclBase {
 				and t.TABLE_NAME LIKE '{$this->_name}'
 		");
 		if (!$this->_rootTableName) return null;// throw new Exception("Table '{$this->_name}' not exists!");
+		DBG::log("TableAcl({$this->_zasobID})->getRootTableName (\$this->_name='{$this->_name}', \$this->_rootTableName='{$this->_rootTableName}')");
 		if ($this->_rootTableName != $this->_name) {
 			if ($this->_zasobID) {
 				$affected = DB::getPDO()->update('CRM_LISTA_ZASOBOW', 'ID', $this->_zasobID, [

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

@@ -480,7 +480,7 @@ class UI {
 		$html->attrs['id'] = $fName;
 		$html->attrs['name'] = $fName;
 		$html->attrs['type'] = 'text';
-		$html->attrs['value'] = $fValue;// BUG htmlspecialchars($fValue); - convert " to "
+		$html->attrs['value'] = $fValue;// BUG htmlspecialchars($fValue); - convert chars in edit form (" to " and & to &)
 		if (isset($params['tabindex'])) {
 			$html->attrs['tabindex'] = $params['tabindex'];
 		}