|
|
@@ -33,7 +33,73 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
// public $_rootTableName = 'CRM_LISTA_ZASOBOW';
|
|
|
public $_rootTableName = 'CRM_#CACHE_ACL_OBJECT_FIELD';
|
|
|
public $_enumRootTableName = 'CRM_#CACHE_ACL_OBJECT_FIELD_enum';
|
|
|
- public $_version = '1';
|
|
|
+ public $_version = '2';
|
|
|
+
|
|
|
+ public function __construct($simpleSchema = null) {
|
|
|
+ parent::__construct($simpleSchema);
|
|
|
+ $version = (int)DB::getPDO()->fetchValue(" select CONF_VAL from CRM_CONFIG where CONF_KEY='Schema_SystemObjectFieldStorageAcl__version' ");
|
|
|
+ if ($version < $this->_version) {
|
|
|
+ DBG::log("UPDATE Schema_SystemObjectFieldStorageAcl__version");
|
|
|
+ DB::getPDO()->execSql("
|
|
|
+ create table if not exists `{$this->_rootTableName}` (
|
|
|
+ `namespace` varchar(255) DEFAULT '',
|
|
|
+ `fieldNamespace` varchar(255) DEFAULT '',
|
|
|
+ `idZasob` int(11) DEFAULT NULL,
|
|
|
+ `idDatabase` int(11) NOT NULL,
|
|
|
+ `_rootTableName` varchar(255) DEFAULT '',
|
|
|
+ `objectNamespace` varchar(255) DEFAULT '',
|
|
|
+ `xsdType` varchar(255) DEFAULT '',
|
|
|
+ `xsdRestrictions` varchar(1000) DEFAULT '',
|
|
|
+ `appInfo` varchar(1000) DEFAULT '',
|
|
|
+ `minOccurs` int(11) DEFAULT '0',
|
|
|
+ `maxOccurs` varchar(11) DEFAULT '1' COMMENT '0..unbounded',
|
|
|
+ `isActive` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'installed',
|
|
|
+ `description` varchar(255) DEFAULT '',
|
|
|
+ `isLocal` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is in _rootTableName',
|
|
|
+ UNIQUE KEY `idZasob` (idZasob),
|
|
|
+ PRIMARY KEY (`namespace`),
|
|
|
+ KEY `isActive` (isActive)
|
|
|
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin2
|
|
|
+ ");
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql(" ALTER TABLE `{$this->_rootTableName}` ADD `appInfo` VARCHAR(1000) NOT NULL DEFAULT '' AFTER `xsdRestrictions` ");
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DBG::log($e);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql(" ALTER TABLE `{$this->_rootTableName}` ADD `isLocal` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is in _rootTableName' AFTER `description` ");
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DBG::log($e);
|
|
|
+ }
|
|
|
+ DB::getPDO()->execSql("
|
|
|
+ create table if not exists `{$this->_enumRootTableName}` (
|
|
|
+ `namespace` varchar(255) DEFAULT '' COMMENT 'concat obj ns / field ns / value',
|
|
|
+ `fieldNamespace` varchar(255) DEFAULT '',
|
|
|
+ `objectNamespace` varchar(255) DEFAULT '',
|
|
|
+ `value` varchar(255) DEFAULT '',
|
|
|
+ `label` varchar(255) DEFAULT '',
|
|
|
+ `isActive` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'installed',
|
|
|
+ `sortPrio` tinyint NOT NULL DEFAULT 0,
|
|
|
+ KEY `objectNamespace` (`objectNamespace`),
|
|
|
+ KEY `fieldNamespace` (`fieldNamespace`),
|
|
|
+ KEY `isActive` (isActive),
|
|
|
+ UNIQUE `enum_uniq_value` (`objectNamespace`, `fieldNamespace`, `value`, `isActive`)
|
|
|
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin2
|
|
|
+ ");
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql(" DELETE from `{$this->_enumRootTableName}` where isActive = 0 ");
|
|
|
+ DB::getPDO()->execSql(" ALTER TABLE `{$this->_enumRootTableName}` ADD UNIQUE `enum_uniq_value` (`objectNamespace`, `fieldNamespace`, `value`, `isActive`) ");
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DBG::log($e);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ DB::getPDO()->execSql(" ALTER TABLE `{$this->_enumRootTableName}` ADD `sortPrio` tinyint NOT NULL DEFAULT 0 ");
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DBG::log($e);
|
|
|
+ }
|
|
|
+ DB::getPDO()->execSql(" REPLACE INTO CRM_CONFIG (`CONF_KEY`,`CONF_VAL`) VALUES ('Schema_SystemObjectFieldStorageAcl__version', '{$this->_version}') ");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public static function getAntAclXsdBasePath($typeName) {
|
|
|
if (!$typeName) throw new Exception("Missing typeName");
|
|
|
@@ -51,50 +117,6 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
}
|
|
|
public function updateCache($namespace = null) {
|
|
|
DBG::log("SystemObjectField::updateCache({$namespace})...");
|
|
|
- DB::getPDO()->execSql("
|
|
|
- create table if not exists `{$this->_rootTableName}` (
|
|
|
- `namespace` varchar(255) DEFAULT '',
|
|
|
- `fieldNamespace` varchar(255) DEFAULT '',
|
|
|
- `idZasob` int(11) DEFAULT NULL,
|
|
|
- `idDatabase` int(11) NOT NULL,
|
|
|
- `_rootTableName` varchar(255) DEFAULT '',
|
|
|
- `objectNamespace` varchar(255) DEFAULT '',
|
|
|
- `xsdType` varchar(255) DEFAULT '',
|
|
|
- `xsdRestrictions` varchar(1000) DEFAULT '',
|
|
|
- `appInfo` varchar(1000) DEFAULT '',
|
|
|
- `minOccurs` int(11) DEFAULT '0',
|
|
|
- `maxOccurs` varchar(11) DEFAULT '1' COMMENT '0..unbounded',
|
|
|
- `isActive` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'installed',
|
|
|
- `description` varchar(255) DEFAULT '',
|
|
|
- `isLocal` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is in _rootTableName',
|
|
|
- UNIQUE KEY `idZasob` (idZasob),
|
|
|
- PRIMARY KEY (`namespace`),
|
|
|
- KEY `isActive` (isActive)
|
|
|
- ) ENGINE=MyISAM DEFAULT CHARSET=latin2
|
|
|
- ");
|
|
|
- try {
|
|
|
- DB::getPDO()->execSql(" ALTER TABLE `{$this->_rootTableName}` ADD `appInfo` VARCHAR(1000) NOT NULL DEFAULT '' AFTER `xsdRestrictions` ");
|
|
|
- } catch (Exception $e) {
|
|
|
- DBG::log($e);
|
|
|
- }
|
|
|
- try {
|
|
|
- DB::getPDO()->execSql(" ALTER TABLE `{$this->_rootTableName}` ADD `isLocal` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is in _rootTableName' AFTER `description` ");
|
|
|
- } catch (Exception $e) {
|
|
|
- DBG::log($e);
|
|
|
- }
|
|
|
- DB::getPDO()->execSql("
|
|
|
- create table if not exists `{$this->_enumRootTableName}` (
|
|
|
- `namespace` varchar(255) DEFAULT '' COMMENT 'concat obj ns / field ns / value',
|
|
|
- `fieldNamespace` varchar(255) DEFAULT '',
|
|
|
- `objectNamespace` varchar(255) DEFAULT '',
|
|
|
- `value` varchar(255) DEFAULT '',
|
|
|
- `label` varchar(255) DEFAULT '',
|
|
|
- `isActive` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'installed',
|
|
|
- KEY `objectNamespace` (`objectNamespace`),
|
|
|
- KEY `fieldNamespace` (`fieldNamespace`),
|
|
|
- KEY `isActive` (isActive)
|
|
|
- ) ENGINE=MyISAM DEFAULT CHARSET=latin2
|
|
|
- ");
|
|
|
|
|
|
if (!$namespace) return;
|
|
|
|
|
|
@@ -163,6 +185,7 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
]);
|
|
|
if (!empty($listEnum)) {
|
|
|
DBG::nicePrint($listEnum, '$listEnum');
|
|
|
+ $sortPrio = count($listEnum);
|
|
|
foreach ($listEnum as $value => $label) {
|
|
|
DB::getPDO()->insertOrUpdate("{$this->_enumRootTableName}", [
|
|
|
'namespace' => "{$item['namespace']}/{$fieldName}/@{$value}",
|
|
|
@@ -170,7 +193,8 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
'objectNamespace' => $item['namespace'],
|
|
|
'value' => $value,
|
|
|
'label' => $label,
|
|
|
- 'isActive' => 1
|
|
|
+ 'isActive' => 1,
|
|
|
+ 'sortPrio' => $sortPrio--
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
@@ -180,6 +204,15 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
'isStructInstalled' => 1,
|
|
|
'primaryKey' => $xsdType['primaryKey'],
|
|
|
]);
|
|
|
+
|
|
|
+ DB::getPDO()->execSql("
|
|
|
+ DELETE from `{$this->_enumRootTableName}`
|
|
|
+ where isActive = 0
|
|
|
+ and objectNamespace = :objectNamespace
|
|
|
+ ", [
|
|
|
+ ':objectNamespace' => $item['namespace'],
|
|
|
+ ]);
|
|
|
+
|
|
|
$zasobTableName = substr($item['objectNamespace'], strlen('default_db/'));
|
|
|
$zasobTableName = (false !== strpos($zasobTableName, '/'))
|
|
|
? $item['objectNamespace']
|
|
|
@@ -528,6 +561,7 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
where t.objectNamespace = '{$item['objectNamespace']}'
|
|
|
and t.fieldNamespace = '{$item['fieldNamespace']}'
|
|
|
and t.isActive = 1
|
|
|
+ order by sortPrio DESC
|
|
|
") as $enum) {
|
|
|
$xsdRestrictions['enumeration'][ $enum['value'] ] = $enum['label'];
|
|
|
}
|