diff --git a/application/Espo/Controllers/Admin.php b/application/Espo/Controllers/Admin.php new file mode 100644 index 0000000000..33424d6382 --- /dev/null +++ b/application/Espo/Controllers/Admin.php @@ -0,0 +1,37 @@ +getUser()->isAdmin()) { + throw new Forbidden("You do not have access to this area"); + } + } + + + public function actionRebuild($params, $data) + { + try{ + $result = $this->getContainer()->get('schema')->rebuild(); + } catch (\Exception $e) { + $result = false; + $GLOBALS['log']->add('EXCEPTION', 'Fault to rebuild database schema'.'. Details: '.$e->getMessage()); + } + + if ($result === false) { + throw new Error("Error while rebuilding database"); + } + + return json_encode($result); + } + +} diff --git a/application/Espo/Controllers/Rebuild.php b/application/Espo/Controllers/Rebuild.php deleted file mode 100644 index 767a82218d..0000000000 --- a/application/Espo/Controllers/Rebuild.php +++ /dev/null @@ -1,26 +0,0 @@ -getContainer()->get('schema')->rebuild(); - } catch (\Exception $e) { - $result = false; - $GLOBALS['log']->add('EXCEPTION', 'Fault to rebuild database schema'.'. Details: '.$e->getMessage()); - } - - if ($result === false) { - throw new Error("Error while rebuilding database"); - } - - return json_encode($result); - } - -} diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index 375a55815e..85facd96e7 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -134,7 +134,7 @@ class Application } $controllerParams[$key] = $value; } - + $controllerName = ucfirst($controllerParams['controller']); if (!empty($controllerParams['action'])) { @@ -148,7 +148,7 @@ class Application $controllerManager = new \Espo\Core\ControllerManager($container, $serviceFactory); $result = $controllerManager->process($controllerName, $actionName, $params, $data); $container->get('output')->render($result); - } catch (\Exception $e) { + } catch (\Exception $e) { $container->get('output')->processError($e->getMessage(), $e->getCode()); } @@ -229,9 +229,10 @@ EOT; ); })->via('PATCH'); - $this->getSlim()->get('/app/rebuild/', function() { + $this->getSlim()->get('/admin/rebuild/', function() { return array( - 'controller' => 'Rebuild', + 'controller' => 'Admin', + 'action' => 'rebuild', ); }); diff --git a/application/Espo/Core/Utils/Database/Converter.php b/application/Espo/Core/Utils/Database/Converter.php index c2880631e4..eade96da06 100644 --- a/application/Espo/Core/Utils/Database/Converter.php +++ b/application/Espo/Core/Utils/Database/Converter.php @@ -81,13 +81,14 @@ class Converter $databaseMeta = $this->getOrmConverter()->prepare($databaseMeta); - $schema = $this->getSchemaConverter()->process($databaseMeta, $entityDefs); - $this->setSchemaFromMetadata($schema); - //save database meta to a file espoMetadata.php $result = $this->getMetadata()->setEspoMetadata($databaseMeta); + $schema = $this->getSchemaConverter()->process($databaseMeta, $entityDefs); + $this->setSchemaFromMetadata($schema); + + $GLOBALS['log']->add('Debug', 'Converter:process() - End: converting metadata to orm format and database schema, result=['.$result.']'); return $result; diff --git a/application/Espo/Core/Utils/Database/Converters/Orm.php b/application/Espo/Core/Utils/Database/Converters/Orm.php index bd46ed8368..efea0cbe27 100644 --- a/application/Espo/Core/Utils/Database/Converters/Orm.php +++ b/application/Espo/Core/Utils/Database/Converters/Orm.php @@ -19,6 +19,10 @@ class Orm 'int' => 11, ); + protected $defaultValue = array( + 'bool' => false, + ); + /* * //pair espo:doctrine */ @@ -95,9 +99,8 @@ class Orm $fieldParams['len'] = $this->defaultLength['varchar']; break; - case 'array': - case 'json_array': - unset($fieldParams['default']); //for db type TEXT can't be defined a default value + case 'bool': + $fieldParams['default'] = isset($fieldParams['default']) ? (bool) $fieldParams['default'] : $this->defaultValue['bool']; break; } } @@ -165,7 +168,7 @@ class Orm if (!isset($outputMeta['deleted'])) { $outputMeta['deleted'] = array( 'type' => Entity::BOOL, - 'default' => 0, + 'default' => false, ); } diff --git a/application/Espo/Core/Utils/Database/Converters/Schema.php b/application/Espo/Core/Utils/Database/Converters/Schema.php index d8b3ab7295..45ea95bc25 100644 --- a/application/Espo/Core/Utils/Database/Converters/Schema.php +++ b/application/Espo/Core/Utils/Database/Converters/Schema.php @@ -48,10 +48,6 @@ class Schema continue; } - if ($fieldParams['type'] == 'id') { - $primaryColumns[] = Util::toUnderScore($fieldName); - } - switch ($fieldParams['type']) { case 'id': $primaryColumns[] = Util::toUnderScore($fieldName);