| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- Lib::loadClass('RouteBase');
- Lib::loadClass('Router');
- Lib::loadClass('Response');
- Lib::loadClass('UI');
- Lib::loadClass('SchemaFactory');
- class Route_Storage_AclReinstall extends RouteBase {
- public function handleAuth() {
- if (!User::logged()) {
- User::authByRequest();
- }
- }
- public function defaultAction() {
- UI::gora();
- UI::startContainer();
- try {
- $namespace = V::get('namespace', '', $_GET);
- if (empty($namespace)) throw new Exception("Missing param namespace");
- echo UI::h('h3', [], $namespace);
- echo UI::h('p', [], [
- UI::h('a', [
- 'href' => Router::getRoute('Storage_AclStruct')->getLink('', [ 'namespace' => $namespace ]),
- 'class' => "btn btn-md btn-link",
- ], "<i class=\"glyphicon glyphicon-arrow-left\"></i> Wróć do struktury"),
- ]);
- if ('reinstall' !== V::get('_postTask', '', $_POST)) {
- echo UI::hButtonPost("Reinstall", [
- 'data' => [
- '_postTask' => 'reinstall'
- ],
- 'class' => 'btn btn-md btn-danger',
- 'title' => "Reinstall structure"
- ]);
- echo '<hr>';
- try {
- $this->printReinstallPreview($namespace);
- } catch (Exception $e) {
- DBG::log($e);
- UI::alert('danger', $e->getMessage());
- }
- return;
- }
- Lib::loadClass('Schema_SystemObjectFieldStorageAcl');
- $objFieldAcl = new Schema_SystemObjectFieldStorageAcl();
- $objFieldAcl->updateCache($namespace);
- DBG::nicePrint([
- 'idInstance' => ACL::getInstanceId($namespace),
- 'rootInstance' => ACL::getRootNamespace($namespace),
- 'conf' => ACL::fetchInstanceConfig($namespace),
- 'table' => ACL::getInstanceTable($namespace),
- ], "dbg");
- {
- $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
- if ('AntAcl' === $item['_type']) {
- $dbName = DB::getPDO()->getDatabaseName();
- $sqlFunBody = ACL::generateIsInstanceFunctionBody($namespace, $item);
- DBG::nicePrint($sqlFunBody, "\$sqlFunBody");
- DB::getPDO()->execSql(" DROP FUNCTION IF EXISTS `{$dbName}`.`isInstance_{$namespace}` ");
- // CREATE
- // [DEFINER = { user | CURRENT_USER }]
- // FUNCTION sp_name ([func_parameter[,...]])
- // RETURNS type
- // [characteristic ...] routine_body
- DB::getPDO()->execSql("
- CREATE DEFINER=`root`@`localhost`
- FUNCTION `{$dbName}`.`isInstance_{$namespace}` ( pk INT(11) )
- RETURNS TINYINT(1)
- {$sqlFunBody}
- ");
- }
- }
- } catch (Exception $e) {
- UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- DBG::log($e);
- }
- UI::endContainer();
- UI::dol();
- }
- public function printReinstallPreview($namespace) {
- $objectItem = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => "*,field" ]);
- DBG::log($objectItem, 'array', '$objectItem preview');
- switch ($objectItem['_type']) {
- case 'AntAcl': $this->printReinstallAntAclPreview($objectItem); break;
- case 'TableAcl': $this->printReinstallTableAclPreview($objectItem); break;
- default: throw new Exception("TODO: Not Implemented type '{$objectItem['_type']}'");
- }
- }
- public function printReinstallAntAclPreview($item) {
- $antAclPath = APP_PATH_SCHEMA . DS . 'ant-object' . DS . str_replace(['__x3A__', ':'], ['.', '/'], $item['typeName']);
- if (!file_exists("{$antAclPath}/build.xml")) throw new Exception("Ant build file not exists");
- Lib::loadClass('XML');
- $xsdType = XML::getXsdTypeFromXsdSchema("{$antAclPath}/{$item['name']}.xsd", $namespace = $item['namespace'], $name = $item['name']);
- DBG::nicePrint($xsdType, '$xsdType');
- if (empty($xsdType['struct'])) throw new Exception("Field list not found for '{$item['namespace']}'");
- foreach ($xsdType['struct'] as $fieldName => $x) {
- $listEnum = [];
- if (!empty($x['restrictions']['enumeration'])) {
- $listEnum = $x['restrictions']['enumeration'];
- unset($x['restrictions']['enumeration']);
- }
- // DB::getPDO()->insertOrUpdate($this->_rootTableName, [
- // 'namespace' => "{$item['namespace']}/{$fieldName}",
- // 'objectNamespace' => $item['namespace'],
- // 'idDatabase' => $item['idDatabase'],
- // '_rootTableName' => $item['_rootTableName'],
- // 'fieldNamespace' => $fieldName,
- // 'xsdType' => $x['type'],
- // 'xsdRestrictions' => json_encode($x['restrictions']),
- // 'appInfo' => json_encode($x['appInfo']),
- // 'minOccurs' => $x['minOccurs'],
- // 'maxOccurs' => $x['maxOccurs'],
- // 'isActive' => 1
- // ]);
- if (!empty($listEnum)) {
- DBG::nicePrint($listEnum, "\$listEnum for field '{$fieldName}'");
- 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
- // ]);
- }
- }
- }
- throw new Exception("TODO: printReinstallAntAclPreview...");
- }
- public function printReinstallTableAclPreview($item) {
- throw new Exception("TODO: printReinstallTableAclPreview...");
- }
- }
|