changed rebuild path to /admin/rebuild

This commit is contained in:
Taras Machyshyn
2013-12-16 17:36:50 +02:00
parent e68a489a1e
commit c0c867b729
6 changed files with 53 additions and 41 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace Espo\Controllers;
use \Espo\Core\Exceptions\Error,
\Espo\Core\Exceptions\Forbidden;
class Admin extends \Espo\Core\Controllers\Base
{
public function __construct(Container $container, ServiceFactory $serviceFactory)
{
parent::__construct($container, $serviceFactory);
if (!$this->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);
}
}

View File

@@ -1,26 +0,0 @@
<?php
namespace Espo\Controllers;
use \Espo\Core\Exceptions\Error;
class Rebuild extends \Espo\Core\Controllers\Base
{
public function actionRead($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);
}
}

View File

@@ -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',
);
});

View File

@@ -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;

View File

@@ -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,
);
}

View File

@@ -48,10 +48,6 @@ class Schema
continue;
}
if ($fieldParams['type'] == 'id') {
$primaryColumns[] = Util::toUnderScore($fieldName);
}
switch ($fieldParams['type']) {
case 'id':
$primaryColumns[] = Util::toUnderScore($fieldName);