|
|
@@ -77,7 +77,7 @@ class Route_Storage_AclReinstall extends RouteBase {
|
|
|
public function printReinstallAntAclPreview($item) {
|
|
|
Lib::loadClass('Schema_SystemObjectFieldStorageAcl');
|
|
|
$antAclPath = Schema_SystemObjectFieldStorageAcl::getAntAclXsdBasePath($item['typeName']);
|
|
|
- if (!file_exists("{$antAclPath}/build.xml")) throw new Exception("Ant build file not exists ".$antAclPath);
|
|
|
+ if (!file_exists("{$antAclPath}/build.xml")) throw new Exception("Ant build file not exists " . str_replace(APP_PATH_ROOT, 'SE', $antAclPath));
|
|
|
|
|
|
Lib::loadClass('XML');
|
|
|
$xsdType = XML::getXsdTypeFromXsdSchema("{$antAclPath}/{$item['name']}.xsd", $namespace = $item['namespace'], $name = $item['name']);
|
|
|
@@ -275,6 +275,13 @@ class Route_Storage_AclReinstall extends RouteBase {
|
|
|
}
|
|
|
|
|
|
function reinstallAcl($namespace) {
|
|
|
+ try {
|
|
|
+ $this->_createOrUpdateTableStructure($namespace);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DBG::log($e);
|
|
|
+ UI::alert('danger', $e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
Lib::loadClass('Schema_SystemObjectFieldStorageAcl');
|
|
|
$objFieldAcl = new Schema_SystemObjectFieldStorageAcl();
|
|
|
$objFieldAcl->updateCache($namespace);
|
|
|
@@ -287,11 +294,10 @@ class Route_Storage_AclReinstall extends RouteBase {
|
|
|
];
|
|
|
DBG::nicePrint($dbgInfo, "dbg");
|
|
|
} catch (Exception $e) {
|
|
|
+ DBG::log($e);
|
|
|
UI::alert('warning', $e->getMessage());
|
|
|
}
|
|
|
|
|
|
- $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
|
|
|
-
|
|
|
$childRefList = RefConfig::getChildRefFullList($namespace);
|
|
|
DBG::nicePrint($childRefList, '$childRefList');
|
|
|
DBG::nicePrint($item, '$item');
|
|
|
@@ -361,4 +367,123 @@ class Route_Storage_AclReinstall extends RouteBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ function _createOrUpdateTableStructure($namespace) {
|
|
|
+ $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
|
|
|
+ DBG::nicePrint($item, 'DBG:_createOrUpdateTableStructure:$item');
|
|
|
+ $storagePdo = DB::getStorage($item['idDatabase']);
|
|
|
+ $tblStruct = [];
|
|
|
+ try {
|
|
|
+ $tblStruct = $storagePdo->getTableStruct($item['_rootTableName']);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ }
|
|
|
+ DBG::nicePrint($tblStruct, 'DBG:_createOrUpdateTableStructure:$tblStruct');
|
|
|
+
|
|
|
+ if (DB::getPDO()->getZasobId() != $item['idDatabase']) throw new Exception("Not imeplemented Create/Update table structure in non default database");
|
|
|
+
|
|
|
+ if (empty($tblStruct)) $this->_createTableStructure($item);
|
|
|
+ else $this->_updateTableStructure($item, $tblStruct);
|
|
|
+ }
|
|
|
+ // $item['idDatabase'] => int idDatabase
|
|
|
+ // $item['_rootTableName'] => string tableName
|
|
|
+ // $item['primaryKey'] => string primaryKey fieldName
|
|
|
+ // $item['field'] => []
|
|
|
+ // $item['field']['fieldNamespace'] => fieldName,
|
|
|
+ // $item['field']['xsdRestrictions'] => [] // TODO: handle restrictions like maxLength, etc.
|
|
|
+ // $item['field']['xsdType'] `select distinct xsdType from `CRM_#CACHE_ACL_OBJECT_FIELD` where xsdType not like 'ref:%'`: [
|
|
|
+ // default_db__x3A__BADANIA_W_TERENIE:A_STATUS_Type
|
|
|
+ // default_db__x3A__CRM_PROCES:TYPE_Simple
|
|
|
+ // gml:AbstractFeatureType
|
|
|
+ // gml:PolygonPropertyType
|
|
|
+ // p5:enum
|
|
|
+ // p5:price
|
|
|
+ // p5:www_link
|
|
|
+ // p5Type:date
|
|
|
+ // p5Type:dateTime
|
|
|
+ // p5Type:decimal
|
|
|
+ // p5Type:integer
|
|
|
+ // p5Type:lineString
|
|
|
+ // p5Type:point
|
|
|
+ // p5Type:polygon
|
|
|
+ // p5Type:string
|
|
|
+ // p5Type:text
|
|
|
+ // xsd:date
|
|
|
+ // xsd:dateTime
|
|
|
+ // xsd:decimal
|
|
|
+ // xsd:double
|
|
|
+ // xsd:float
|
|
|
+ // xsd:gYear
|
|
|
+ // xsd:hexBinary
|
|
|
+ // xsd:int
|
|
|
+ // xsd:integer
|
|
|
+ // xsd:long
|
|
|
+ // xsd:positiveInteger
|
|
|
+ // xsd:short
|
|
|
+ // xsd:string
|
|
|
+ // xsd:time
|
|
|
+ // xsd:token
|
|
|
+ // ]
|
|
|
+ function _createTableStructure($item) {
|
|
|
+ $tryConvertFields = array_map(function ($fieldInfo) {
|
|
|
+ if ('ref:' === substr($fieldInfo['xsdType'], 0, 4)) return "Skipped create ref field '{$fieldInfo['xsdType']}'";
|
|
|
+ switch ($fieldInfo['xsdType']) {
|
|
|
+ case 'xsd:integer':
|
|
|
+ case 'p5Type:integer':
|
|
|
+ case 'xsd:positiveInteger':
|
|
|
+ case 'xsd:int': return [ 'name' => $fieldInfo['fieldNamespace'], 'raw_storage_type' => "int(11)" ];
|
|
|
+ case 'xsd:float': return [ 'name' => $fieldInfo['fieldNamespace'], 'raw_storage_type' => "float" ];
|
|
|
+ case 'xsd:double': return [ 'name' => $fieldInfo['fieldNamespace'], 'raw_storage_type' => "double" ];
|
|
|
+ case 'xsd:date': return [ 'name' => $fieldInfo['fieldNamespace'], 'raw_storage_type' => "date" ];
|
|
|
+ case 'xsd:datetime': return [ 'name' => $fieldInfo['fieldNamespace'], 'raw_storage_type' => "datetime" ];
|
|
|
+ case 'xsd:string':
|
|
|
+ case 'p5Type:string': return [ 'name' => $fieldInfo['fieldNamespace'], 'raw_storage_type' => "varchar(255)" ];
|
|
|
+ // TODO: implement more xsd types:
|
|
|
+ // case 'p5Type:decimal':
|
|
|
+ // case 'xsd:decimal': return [ 'name' => $fieldInfo['fieldNamespace'], 'raw_storage_type' => "decimal" ];
|
|
|
+ // default_db__x3A__BADANIA_W_TERENIE:A_STATUS_Type
|
|
|
+ // default_db__x3A__CRM_PROCES:TYPE_Simple
|
|
|
+ // gml:AbstractFeatureType
|
|
|
+ // gml:PolygonPropertyType
|
|
|
+ // p5:enum
|
|
|
+ // p5:price
|
|
|
+ // p5:www_link
|
|
|
+ // p5Type:date
|
|
|
+ // p5Type:dateTime
|
|
|
+ // p5Type:decimal
|
|
|
+ // p5Type:lineString
|
|
|
+ // p5Type:point
|
|
|
+ // p5Type:polygon
|
|
|
+ // p5Type:text
|
|
|
+ // xsd:decimal
|
|
|
+ // xsd:gYear
|
|
|
+ // xsd:hexBinary
|
|
|
+ // xsd:long
|
|
|
+ // xsd:short
|
|
|
+ // xsd:time
|
|
|
+ // xsd:token
|
|
|
+ default: return "Not implemented type '{$fieldInfo['xsdType']}'";
|
|
|
+ }
|
|
|
+ }, $item['field']);
|
|
|
+ DBG::nicePrint($tryConvertFields, "DBG:create table struct:\$tryConvertFields");
|
|
|
+ $toCreateFields = array_filter($tryConvertFields, function ($fieldInfo) { return is_array($fieldInfo); });
|
|
|
+ DBG::nicePrint($toCreateFields, "DBG:create table struct:\$toCreateFields");
|
|
|
+
|
|
|
+ $tblStruct = array_combine(
|
|
|
+ array_map(V::makePick('name'), $toCreateFields),
|
|
|
+ array_values($toCreateFields)
|
|
|
+ );
|
|
|
+ DBG::nicePrint($tblStruct, "DBG:create table struct:\$tblStruct");
|
|
|
+ if (!array_key_exists($item['primaryKey'], $tblStruct)) throw new Exception("BUG: primaryKey field definition not exists");
|
|
|
+ $tblStruct[$item['primaryKey']]['extra'] = "auto_increment";
|
|
|
+
|
|
|
+ DB::getStorage($item['idDatabase'])->createTableStructure([
|
|
|
+ 'tableName' => $item['_rootTableName'],
|
|
|
+ 'fields' => $tblStruct,
|
|
|
+ 'primaryKey' => $item['primaryKey'],
|
|
|
+ 'keys' => [],
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ function _updateTableStructure($item, $tblStruct) {
|
|
|
+ throw new Exception("Not imeplemented Update table structure in non default database");
|
|
|
+ }
|
|
|
+
|
|
|
}
|