mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 13:03:20 +00:00
DataboxesController Refactor, CS fixup
This commit is contained in:
@@ -12,7 +12,6 @@
|
|||||||
namespace Alchemy\Phrasea;
|
namespace Alchemy\Phrasea;
|
||||||
|
|
||||||
use Alchemy\Geonames\GeonamesServiceProvider;
|
use Alchemy\Geonames\GeonamesServiceProvider;
|
||||||
use Alchemy\Phrasea\ControllerProvider\Admin\Databoxes;
|
|
||||||
use Alchemy\Phrasea\ControllerProvider\Admin\Fields;
|
use Alchemy\Phrasea\ControllerProvider\Admin\Fields;
|
||||||
use Alchemy\Phrasea\ControllerProvider\Admin\Publications;
|
use Alchemy\Phrasea\ControllerProvider\Admin\Publications;
|
||||||
use Alchemy\Phrasea\ControllerProvider\Admin\Root as AdminRoot;
|
use Alchemy\Phrasea\ControllerProvider\Admin\Root as AdminRoot;
|
||||||
@@ -312,6 +311,7 @@ class Application extends SilexApplication
|
|||||||
'Alchemy\Phrasea\ControllerProvider\Admin\ConnectedUsers' => [],
|
'Alchemy\Phrasea\ControllerProvider\Admin\ConnectedUsers' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Admin\Dashboard' => [],
|
'Alchemy\Phrasea\ControllerProvider\Admin\Dashboard' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Admin\Databox' => [],
|
'Alchemy\Phrasea\ControllerProvider\Admin\Databox' => [],
|
||||||
|
'Alchemy\Phrasea\ControllerProvider\Admin\Databoxes' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Admin\Users' => [],
|
'Alchemy\Phrasea\ControllerProvider\Admin\Users' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
|
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
|
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
|
||||||
@@ -618,7 +618,6 @@ class Application extends SilexApplication
|
|||||||
$this->mount('/developers/', new Developers());
|
$this->mount('/developers/', new Developers());
|
||||||
|
|
||||||
$this->mount('/admin/', new AdminRoot());
|
$this->mount('/admin/', new AdminRoot());
|
||||||
$this->mount('/admin/databoxes', new Databoxes());
|
|
||||||
$this->mount('/admin/setup', new Setup());
|
$this->mount('/admin/setup', new Setup());
|
||||||
$this->mount('/admin/search-engine', new SearchEngine());
|
$this->mount('/admin/search-engine', new SearchEngine());
|
||||||
$this->mount('/admin/publications', new Publications());
|
$this->mount('/admin/publications', new Publications());
|
||||||
@@ -671,6 +670,7 @@ class Application extends SilexApplication
|
|||||||
'/admin/connected-users' => 'Alchemy\Phrasea\ControllerProvider\Admin\ConnectedUsers',
|
'/admin/connected-users' => 'Alchemy\Phrasea\ControllerProvider\Admin\ConnectedUsers',
|
||||||
'/admin/dashboard' => 'Alchemy\Phrasea\ControllerProvider\Admin\Dashboard',
|
'/admin/dashboard' => 'Alchemy\Phrasea\ControllerProvider\Admin\Dashboard',
|
||||||
'/admin/databox' => 'Alchemy\Phrasea\ControllerProvider\Admin\Databox',
|
'/admin/databox' => 'Alchemy\Phrasea\ControllerProvider\Admin\Databox',
|
||||||
|
'/admin/databoxes' => 'Alchemy\Phrasea\ControllerProvider\Admin\Databoxes',
|
||||||
'/admin/users' => 'Alchemy\Phrasea\ControllerProvider\Admin\Users',
|
'/admin/users' => 'Alchemy\Phrasea\ControllerProvider\Admin\Users',
|
||||||
'/datafiles' => 'Alchemy\Phrasea\ControllerProvider\Datafiles',
|
'/datafiles' => 'Alchemy\Phrasea\ControllerProvider\Datafiles',
|
||||||
'/include/minify' => 'Alchemy\Phrasea\ControllerProvider\Minifier',
|
'/include/minify' => 'Alchemy\Phrasea\ControllerProvider\Minifier',
|
||||||
|
340
lib/Alchemy/Phrasea/Controller/Admin/DataboxesController.php
Normal file
340
lib/Alchemy/Phrasea/Controller/Admin/DataboxesController.php
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2015 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Controller\Admin;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
|
use Alchemy\Phrasea\Authentication\ACLProvider;
|
||||||
|
use Alchemy\Phrasea\Authentication\Authenticator;
|
||||||
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
|
use Doctrine\DBAL\DBALException;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class DataboxesController
|
||||||
|
{
|
||||||
|
/** @var Application */
|
||||||
|
private $app;
|
||||||
|
|
||||||
|
public function __construct(Application $app)
|
||||||
|
{
|
||||||
|
$this->app = $app;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Databases control panel
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function getDatabases(Request $request)
|
||||||
|
{
|
||||||
|
$acl = $this->getAclForUser();
|
||||||
|
$sbasIds = array_merge(
|
||||||
|
array_keys($acl->get_granted_sbas(['bas_manage'])),
|
||||||
|
array_keys($acl->get_granted_sbas(['bas_modify_struct']))
|
||||||
|
);
|
||||||
|
|
||||||
|
$sbas = [];
|
||||||
|
foreach ($sbasIds as $sbasId) {
|
||||||
|
$sbas[$sbasId] = [
|
||||||
|
'version' => 'unknown',
|
||||||
|
'image' => '/skins/icons/db-remove.png',
|
||||||
|
'server_info' => '',
|
||||||
|
'name' => $this->app->trans('Unreachable server')
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$databox = $this->findDataboxById($sbasId);
|
||||||
|
|
||||||
|
/** @var \PDO $pdoConnection */
|
||||||
|
$pdoConnection = $databox->get_connection()->getWrappedConnection();
|
||||||
|
$sbas[$sbasId] = [
|
||||||
|
'version' => $databox->get_version(),
|
||||||
|
'image' => '/skins/icons/foldph20close_0.gif',
|
||||||
|
'server_info' => $pdoConnection->getAttribute(\PDO::ATTR_SERVER_VERSION),
|
||||||
|
'name' => \phrasea::sbas_labels($sbasId, $this->app)
|
||||||
|
];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($errorMsg = $request->query->get('error')) {
|
||||||
|
case 'scheduler-started' :
|
||||||
|
$errorMsg = $this->app->trans('Veuillez arreter le planificateur avant la mise a jour');
|
||||||
|
break;
|
||||||
|
case 'already-started' :
|
||||||
|
$errorMsg = $this->app->trans('The upgrade is already started');
|
||||||
|
break;
|
||||||
|
case 'unknow' :
|
||||||
|
$errorMsg = $this->app->trans('An error occured');
|
||||||
|
break;
|
||||||
|
case 'bad-email' :
|
||||||
|
$errorMsg = $this->app->trans('Please fix the database before starting');
|
||||||
|
break;
|
||||||
|
case 'special-chars' :
|
||||||
|
$errorMsg = $this->app->trans('Database name can not contains special characters');
|
||||||
|
break;
|
||||||
|
case 'base-failed' :
|
||||||
|
$errorMsg = $this->app->trans('Base could not be created');
|
||||||
|
break;
|
||||||
|
case 'database-failed' :
|
||||||
|
$errorMsg = $this->app->trans('Database does not exists or can not be accessed');
|
||||||
|
break;
|
||||||
|
case 'no-empty' :
|
||||||
|
$errorMsg = $this->app->trans('Database can not be empty');
|
||||||
|
break;
|
||||||
|
case 'mount-failed' :
|
||||||
|
$errorMsg = $this->app->trans('Database could not be mounted');
|
||||||
|
break;
|
||||||
|
case 'innodb-support' :
|
||||||
|
$errorMsg = _('Database server does not support InnoDB storage engine');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('admin/databases.html.twig', [
|
||||||
|
'files' => new \DirectoryIterator($this->app['root.path'] . '/lib/conf.d/data_templates'),
|
||||||
|
'sbas' => $sbas,
|
||||||
|
'error_msg' => $errorMsg,
|
||||||
|
'advices' => $request->query->get('advices', []),
|
||||||
|
'reloadTree' => (Boolean) $request->query->get('reload-tree'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new databox
|
||||||
|
*
|
||||||
|
* @param Request $request The current HTTP request
|
||||||
|
* @return RedirectResponse
|
||||||
|
*/
|
||||||
|
public function createDatabase(Request $request)
|
||||||
|
{
|
||||||
|
if ('' === $dbName = $request->request->get('new_dbname', '')) {
|
||||||
|
return $this->app->redirectPath('admin_databases', ['error' => 'no-empty']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\p4string::hasAccent($dbName)) {
|
||||||
|
return $this->app->redirectPath('admin_databases', ['error' => 'special-chars']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((null === $request->request->get('new_settings')) && (null !== $dataTemplate = $request->request->get('new_data_template'))) {
|
||||||
|
$connexion = $this->app['conf']->get(['main', 'database']);
|
||||||
|
|
||||||
|
$hostname = $connexion['host'];
|
||||||
|
$port = $connexion['port'];
|
||||||
|
$user = $connexion['user'];
|
||||||
|
$password = $connexion['password'];
|
||||||
|
|
||||||
|
$dataTemplate = new \SplFileInfo($this->app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml');
|
||||||
|
|
||||||
|
try {
|
||||||
|
/** @var Connection $connection */
|
||||||
|
$connection = $this->app['dbal.provider']([
|
||||||
|
'host' => $hostname,
|
||||||
|
'port' => $port,
|
||||||
|
'user' => $user,
|
||||||
|
'password' => $password,
|
||||||
|
'dbname' => $dbName,
|
||||||
|
]);
|
||||||
|
$connection->connect();
|
||||||
|
} catch (DBALException $e) {
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'database-failed']);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$base = \databox::create($this->app, $connection, $dataTemplate);
|
||||||
|
$base->registerAdmin($this->getAuthenticator()->getUser());
|
||||||
|
$this->getAclForUser()->delete_data_from_cache();
|
||||||
|
|
||||||
|
$connection->close();
|
||||||
|
return $this->app->redirectPath('admin_database', [
|
||||||
|
'databox_id' => $base->get_sbas_id(),
|
||||||
|
'success' => 1,
|
||||||
|
'reload-tree' => 1
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'base-failed']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $request->request->get('new_settings')
|
||||||
|
&& (null !== $hostname = $request->request->get('new_hostname'))
|
||||||
|
&& (null !== $port = $request->request->get('new_port'))
|
||||||
|
&& (null !== $userDb = $request->request->get('new_user'))
|
||||||
|
&& (null !== $passwordDb = $request->request->get('new_password'))
|
||||||
|
&& (null !== $dataTemplate = $request->request->get('new_data_template'))
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
$data_template = new \SplFileInfo($this->app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml');
|
||||||
|
/** @var Connection $connection */
|
||||||
|
$connection = $this->app['db.provider']([
|
||||||
|
'host' => $hostname,
|
||||||
|
'port' => $port,
|
||||||
|
'user' => $userDb,
|
||||||
|
'password' => $passwordDb,
|
||||||
|
'dbname' => $dbName,
|
||||||
|
]);
|
||||||
|
$connection->connect();
|
||||||
|
try {
|
||||||
|
$base = \databox::create($this->app, $connection, $data_template);
|
||||||
|
$base->registerAdmin($this->getAuthenticator()->getUser());
|
||||||
|
|
||||||
|
return $this->app->redirectPath('admin_database', [
|
||||||
|
'databox_id' => $base->get_sbas_id(),
|
||||||
|
'success' => 1,
|
||||||
|
'reload-tree' => 1,
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'base-failed']);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'database-failed']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'base-failed']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount a databox
|
||||||
|
*
|
||||||
|
* @param Request $request The current HTTP request
|
||||||
|
* @return RedirectResponse
|
||||||
|
*/
|
||||||
|
public function databaseMount(Request $request)
|
||||||
|
{
|
||||||
|
if ('' === $dbName = trim($request->request->get('new_dbname', ''))) {
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'no-empty']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\p4string::hasAccent($dbName)) {
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'special-chars']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((null === $request->request->get('new_settings'))) {
|
||||||
|
try {
|
||||||
|
$connexion = $this->app['conf']->get(['main', 'database']);
|
||||||
|
|
||||||
|
$hostname = $connexion['host'];
|
||||||
|
$port = $connexion['port'];
|
||||||
|
$user = $connexion['user'];
|
||||||
|
$password = $connexion['password'];
|
||||||
|
|
||||||
|
$this->app['phraseanet.appbox']->get_connection()->beginTransaction();
|
||||||
|
$base = \databox::mount($this->app, $hostname, $port, $user, $password, $dbName);
|
||||||
|
$base->registerAdmin($this->app['authentication']->getUser());
|
||||||
|
$this->app['phraseanet.appbox']->get_connection()->commit();
|
||||||
|
|
||||||
|
return $this->app->redirectPath('admin_database', [
|
||||||
|
'databox_id' => $base->get_sbas_id(),
|
||||||
|
'success' => 1,
|
||||||
|
'reload-tree' => 1,
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->app['phraseanet.appbox']->get_connection()->rollBack();
|
||||||
|
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'mount-failed']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $request->request->get('new_settings')
|
||||||
|
&& (null !== $hostname = $request->request->get('new_hostname'))
|
||||||
|
&& (null !== $port = $request->request->get('new_port'))
|
||||||
|
&& (null !== $userDb = $request->request->get('new_user'))
|
||||||
|
&& (null !== $passwordDb = $request->request->get('new_password'))
|
||||||
|
) {
|
||||||
|
$connection = $this->getApplicationBox()->get_connection();
|
||||||
|
try {
|
||||||
|
$connection->beginTransaction();
|
||||||
|
$base = \databox::mount($this->app, $hostname, $port, $userDb, $passwordDb, $dbName);
|
||||||
|
$base->registerAdmin($this->getAuthenticator()->getUser());
|
||||||
|
$connection->commit();
|
||||||
|
|
||||||
|
return $this->app->redirectPath('admin_database', [
|
||||||
|
'databox_id' => $base->get_sbas_id(),
|
||||||
|
'success' => 1,
|
||||||
|
'reload-tree' => 1
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$connection->rollBack();
|
||||||
|
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'mount-failed']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->app->redirectPath('admin_databases', ['success' => 0, 'error' => 'mount-failed']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \appbox
|
||||||
|
*/
|
||||||
|
private function getApplicationBox()
|
||||||
|
{
|
||||||
|
return $this->app['phraseanet.appbox'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @return \databox
|
||||||
|
*/
|
||||||
|
private function findDataboxById($id)
|
||||||
|
{
|
||||||
|
$appbox = $this->getApplicationBox();
|
||||||
|
|
||||||
|
return $appbox->get_databox($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @param array $context
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function render($name, array $context = [])
|
||||||
|
{
|
||||||
|
/** @var \Twig_Environment $twig */
|
||||||
|
$twig = $this->app['twig'];
|
||||||
|
return $twig->render(
|
||||||
|
$name,
|
||||||
|
$context
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ACLProvider
|
||||||
|
*/
|
||||||
|
private function getAclProvider()
|
||||||
|
{
|
||||||
|
return $this->app['acl'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Authenticator
|
||||||
|
*/
|
||||||
|
private function getAuthenticator()
|
||||||
|
{
|
||||||
|
return $this->app['authentication'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User|null $user
|
||||||
|
* @return \ACL
|
||||||
|
*/
|
||||||
|
private function getAclForUser(User $user = null)
|
||||||
|
{
|
||||||
|
$aclProvider = $this->getAclProvider();
|
||||||
|
if (null === $user) {
|
||||||
|
$user = $this->getAuthenticator()->getUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aclProvider->get($user);
|
||||||
|
}
|
||||||
|
}
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Controller\Admin\CollectionController;
|
use Alchemy\Phrasea\Controller\Admin\CollectionController;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ControllerCollection;
|
use Silex\ControllerCollection;
|
||||||
@@ -21,7 +22,7 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.admin.collection'] = $app->share(function () use ($app) {
|
$app['controller.admin.collection'] = $app->share(function (PhraseaApplication $app) {
|
||||||
return new CollectionController($app);
|
return new CollectionController($app);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Controller\Admin\ConnectedUsersController;
|
use Alchemy\Phrasea\Controller\Admin\ConnectedUsersController;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ControllerCollection;
|
use Silex\ControllerCollection;
|
||||||
@@ -21,7 +22,7 @@ class ConnectedUsers implements ControllerProviderInterface, ServiceProviderInte
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.admin.connected-users'] = $app->share(function () use ($app) {
|
$app['controller.admin.connected-users'] = $app->share(function (PhraseaApplication $app) {
|
||||||
return new ConnectedUsersController($app);
|
return new ConnectedUsersController($app);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Controller\Admin\DashboardController;
|
use Alchemy\Phrasea\Controller\Admin\DashboardController;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ControllerCollection;
|
use Silex\ControllerCollection;
|
||||||
@@ -21,7 +22,7 @@ class Dashboard implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.admin.dashboard'] = $app->share(function () use ($app) {
|
$app['controller.admin.dashboard'] = $app->share(function (PhraseaApplication $app) {
|
||||||
return new DashboardController($app);
|
return new DashboardController($app);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Controller\Admin\DataboxController;
|
use Alchemy\Phrasea\Controller\Admin\DataboxController;
|
||||||
use Alchemy\Phrasea\Security\Firewall;
|
use Alchemy\Phrasea\Security\Firewall;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
@@ -23,7 +24,7 @@ class Databox implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.admin.databox'] = $app->share(function () use ($app) {
|
$app['controller.admin.databox'] = $app->share(function (PhraseaApplication $app) {
|
||||||
return new DataboxController($app);
|
return new DataboxController($app);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -11,25 +11,38 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
||||||
|
|
||||||
use Doctrine\DBAL\DBALException;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
|
use Alchemy\Phrasea\Controller\Admin\DataboxesController;
|
||||||
|
use Alchemy\Phrasea\Security\Firewall;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
|
use Silex\ControllerCollection;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Silex\ServiceProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
|
|
||||||
class Databoxes implements ControllerProviderInterface
|
class Databoxes implements ControllerProviderInterface, ServiceProviderInterface
|
||||||
{
|
{
|
||||||
|
public function register(Application $app)
|
||||||
|
{
|
||||||
|
$app['controller.admin.databoxes'] = $app->share(function (PhraseaApplication $app) {
|
||||||
|
return new DataboxesController($app);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(Application $app)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function connect(Application $app)
|
public function connect(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.admin.databoxes'] = $this;
|
/** @var ControllerCollection $controllers */
|
||||||
|
|
||||||
$controllers = $app['controllers_factory'];
|
$controllers = $app['controllers_factory'];
|
||||||
|
|
||||||
$app['firewall']->addMandatoryAuthentication($controllers);
|
/** @var Firewall $firewall */
|
||||||
|
$firewall = $app['firewall'];
|
||||||
|
$firewall->addMandatoryAuthentication($controllers);
|
||||||
|
|
||||||
$controllers->before(function (Request $request) use ($app) {
|
$controllers->before(function () use ($firewall) {
|
||||||
$app['firewall']->requireAccessToModule('admin');
|
$firewall->requireAccessToModule('admin');
|
||||||
});
|
});
|
||||||
|
|
||||||
$controllers->get('/', 'controller.admin.databoxes:getDatabases')
|
$controllers->get('/', 'controller.admin.databoxes:getDatabases')
|
||||||
@@ -37,241 +50,16 @@ class Databoxes implements ControllerProviderInterface
|
|||||||
|
|
||||||
$controllers->post('/', 'controller.admin.databoxes:createDatabase')
|
$controllers->post('/', 'controller.admin.databoxes:createDatabase')
|
||||||
->bind('admin_database_new')
|
->bind('admin_database_new')
|
||||||
->before(function (Request $request) use ($app) {
|
->before(function () use ($firewall) {
|
||||||
$app['firewall']->requireAdmin();
|
$firewall->requireAdmin();
|
||||||
});
|
});
|
||||||
|
|
||||||
$controllers->post('/mount/', 'controller.admin.databoxes:databaseMount')
|
$controllers->post('/mount/', 'controller.admin.databoxes:databaseMount')
|
||||||
->bind('admin_database_mount')
|
->bind('admin_database_mount')
|
||||||
->before(function (Request $request) use ($app) {
|
->before(function () use ($firewall) {
|
||||||
$app['firewall']->requireAdmin();
|
$firewall->requireAdmin();
|
||||||
});
|
});
|
||||||
|
|
||||||
return $controllers;
|
return $controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Databases control panel
|
|
||||||
*
|
|
||||||
* @param $app Application $app
|
|
||||||
* @param $request Request $request
|
|
||||||
* @return Response
|
|
||||||
*/
|
|
||||||
public function getDatabases(Application $app, Request $request)
|
|
||||||
{
|
|
||||||
$sbasIds = array_merge(
|
|
||||||
array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_sbas(['bas_manage']))
|
|
||||||
, array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_sbas(['bas_modify_struct']))
|
|
||||||
);
|
|
||||||
|
|
||||||
$sbas = [];
|
|
||||||
foreach ($sbasIds as $sbasId) {
|
|
||||||
$sbas[$sbasId] = [
|
|
||||||
'version' => 'unknown',
|
|
||||||
'image' => '/skins/icons/db-remove.png',
|
|
||||||
'server_info' => '',
|
|
||||||
'name' => $app->trans('Unreachable server')
|
|
||||||
];
|
|
||||||
|
|
||||||
try {
|
|
||||||
$databox = $app['phraseanet.appbox']->get_databox($sbasId);
|
|
||||||
|
|
||||||
$sbas[$sbasId] = [
|
|
||||||
'version' => $databox->get_version(),
|
|
||||||
'image' => '/skins/icons/foldph20close_0.gif',
|
|
||||||
'server_info' => $databox->get_connection()->getWrappedConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION),
|
|
||||||
'name' => \phrasea::sbas_labels($sbasId, $app)
|
|
||||||
];
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($errorMsg = $request->query->get('error')) {
|
|
||||||
case 'scheduler-started' :
|
|
||||||
$errorMsg = $app->trans('Veuillez arreter le planificateur avant la mise a jour');
|
|
||||||
break;
|
|
||||||
case 'already-started' :
|
|
||||||
$errorMsg = $app->trans('The upgrade is already started');
|
|
||||||
break;
|
|
||||||
case 'unknow' :
|
|
||||||
$errorMsg = $app->trans('An error occured');
|
|
||||||
break;
|
|
||||||
case 'bad-email' :
|
|
||||||
$errorMsg = $app->trans('Please fix the database before starting');
|
|
||||||
break;
|
|
||||||
case 'special-chars' :
|
|
||||||
$errorMsg = $app->trans('Database name can not contains special characters');
|
|
||||||
break;
|
|
||||||
case 'base-failed' :
|
|
||||||
$errorMsg = $app->trans('Base could not be created');
|
|
||||||
break;
|
|
||||||
case 'database-failed' :
|
|
||||||
$errorMsg = $app->trans('Database does not exists or can not be accessed');
|
|
||||||
break;
|
|
||||||
case 'no-empty' :
|
|
||||||
$errorMsg = $app->trans('Database can not be empty');
|
|
||||||
break;
|
|
||||||
case 'mount-failed' :
|
|
||||||
$errorMsg = $app->trans('Database could not be mounted');
|
|
||||||
break;
|
|
||||||
case 'innodb-support' :
|
|
||||||
$errorMsg = _('Database server does not support InnoDB storage engine');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $app['twig']->render('admin/databases.html.twig', [
|
|
||||||
'files' => new \DirectoryIterator($app['root.path'] . '/lib/conf.d/data_templates'),
|
|
||||||
'sbas' => $sbas,
|
|
||||||
'error_msg' => $errorMsg,
|
|
||||||
'advices' => $request->query->get('advices', []),
|
|
||||||
'reloadTree' => (Boolean) $request->query->get('reload-tree'),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new databox
|
|
||||||
*
|
|
||||||
* @param Application $app The silex application
|
|
||||||
* @param Request $request The current HTTP request
|
|
||||||
*
|
|
||||||
* @return RedirectResponse
|
|
||||||
*/
|
|
||||||
public function createDatabase(Application $app, Request $request)
|
|
||||||
{
|
|
||||||
if ('' === $dbName = $request->request->get('new_dbname', '')) {
|
|
||||||
return $app->redirectPath('admin_databases', ['error' => 'no-empty']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\p4string::hasAccent($dbName)) {
|
|
||||||
return $app->redirectPath('admin_databases', ['error' => 'special-chars']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((null === $request->request->get('new_settings')) && (null !== $dataTemplate = $request->request->get('new_data_template'))) {
|
|
||||||
$connexion = $app['conf']->get(['main', 'database']);
|
|
||||||
|
|
||||||
$hostname = $connexion['host'];
|
|
||||||
$port = $connexion['port'];
|
|
||||||
$user = $connexion['user'];
|
|
||||||
$password = $connexion['password'];
|
|
||||||
|
|
||||||
$dataTemplate = new \SplFileInfo($app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml');
|
|
||||||
|
|
||||||
try {
|
|
||||||
$connbas = $app['dbal.provider']([
|
|
||||||
'host' => $hostname,
|
|
||||||
'port' => $port,
|
|
||||||
'user' => $user,
|
|
||||||
'password' => $password,
|
|
||||||
'dbname' => $dbName,
|
|
||||||
]);
|
|
||||||
$connbas->connect();
|
|
||||||
} catch (DBALException $e) {
|
|
||||||
return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'database-failed']);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$base = \databox::create($app, $connbas, $dataTemplate);
|
|
||||||
$base->registerAdmin($app['authentication']->getUser());
|
|
||||||
$app['acl']->get($app['authentication']->getUser())->delete_data_from_cache();
|
|
||||||
|
|
||||||
$connbas->close();
|
|
||||||
return $app->redirectPath('admin_database', ['databox_id' => $base->get_sbas_id(), 'success' => 1, 'reload-tree' => 1]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'base-failed']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
null !== $request->request->get('new_settings')
|
|
||||||
&& (null !== $hostname = $request->request->get('new_hostname'))
|
|
||||||
&& (null !== $port = $request->request->get('new_port'))
|
|
||||||
&& (null !== $userDb = $request->request->get('new_user'))
|
|
||||||
&& (null !== $passwordDb = $request->request->get('new_password'))
|
|
||||||
&& (null !== $dataTemplate = $request->request->get('new_data_template'))) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
$data_template = new \SplFileInfo($app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml');
|
|
||||||
$connbas = $app['db.provider']([
|
|
||||||
'host' => $hostname,
|
|
||||||
'port' => $port,
|
|
||||||
'user' => $userDb,
|
|
||||||
'password' => $passwordDb,
|
|
||||||
'dbname' => $dbName,
|
|
||||||
]);
|
|
||||||
$connbas->connect();
|
|
||||||
try {
|
|
||||||
$base = \databox::create($app, $connbas, $data_template);
|
|
||||||
$base->registerAdmin($app['authentication']->getUser());
|
|
||||||
|
|
||||||
return $app->redirectPath('admin_database', ['databox_id' => $base->get_sbas_id(), 'success' => 1, 'reload-tree' => 1]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'base-failed']);
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'database-failed']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mount a databox
|
|
||||||
*
|
|
||||||
* @param Application $app The silex application
|
|
||||||
* @param Request $request The current HTTP request
|
|
||||||
* @return RedirectResponse
|
|
||||||
*/
|
|
||||||
public function databaseMount(Application $app, Request $request)
|
|
||||||
{
|
|
||||||
if ('' === $dbName = trim($request->request->get('new_dbname', ''))) {
|
|
||||||
return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'no-empty']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\p4string::hasAccent($dbName)) {
|
|
||||||
return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'special-chars']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((null === $request->request->get('new_settings'))) {
|
|
||||||
try {
|
|
||||||
$connexion = $app['conf']->get(['main', 'database']);
|
|
||||||
|
|
||||||
$hostname = $connexion['host'];
|
|
||||||
$port = $connexion['port'];
|
|
||||||
$user = $connexion['user'];
|
|
||||||
$password = $connexion['password'];
|
|
||||||
|
|
||||||
$app['phraseanet.appbox']->get_connection()->beginTransaction();
|
|
||||||
$base = \databox::mount($app, $hostname, $port, $user, $password, $dbName);
|
|
||||||
$base->registerAdmin($app['authentication']->getUser());
|
|
||||||
$app['phraseanet.appbox']->get_connection()->commit();
|
|
||||||
|
|
||||||
return $app->redirectPath('admin_database', ['databox_id' => $base->get_sbas_id(), 'success' => 1, 'reload-tree' => 1]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$app['phraseanet.appbox']->get_connection()->rollBack();
|
|
||||||
|
|
||||||
return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'mount-failed']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
null !== $request->request->get('new_settings')
|
|
||||||
&& (null !== $hostname = $request->request->get('new_hostname'))
|
|
||||||
&& (null !== $port = $request->request->get('new_port'))
|
|
||||||
&& (null !== $userDb = $request->request->get('new_user'))
|
|
||||||
&& (null !== $passwordDb = $request->request->get('new_password'))) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
$app['phraseanet.appbox']->get_connection()->beginTransaction();
|
|
||||||
$base = \databox::mount($app, $hostname, $port, $userDb, $passwordDb, $dbName);
|
|
||||||
$base->registerAdmin($app['authentication']->getUser());
|
|
||||||
$app['phraseanet.appbox']->get_connection()->commit();
|
|
||||||
|
|
||||||
return $app->redirectPath('admin_database', ['databox_id' => $base->get_sbas_id(), 'success' => 1, 'reload-tree' => 1]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$app['phraseanet.appbox']->get_connection()->rollBack();
|
|
||||||
|
|
||||||
return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'mount-failed']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\ControllerProvider;
|
namespace Alchemy\Phrasea\ControllerProvider;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Controller\DatafileController;
|
use Alchemy\Phrasea\Controller\DatafileController;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
@@ -21,7 +22,7 @@ class Datafiles implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.datafiles'] = $app->share(function () use ($app) {
|
$app['controller.datafiles'] = $app->share(function (PhraseaApplication $app) {
|
||||||
return new DatafileController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication']);
|
return new DatafileController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ class Lightbox implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.lightbox'] = $app->share(function () use ($app) {
|
$app['controller.lightbox'] = $app->share(function (PhraseaApplication $app) {
|
||||||
return new LightboxController($app);
|
return new LightboxController($app);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
namespace Alchemy\Phrasea\ControllerProvider;
|
namespace Alchemy\Phrasea\ControllerProvider;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Controller\MinifierController;
|
use Alchemy\Phrasea\Controller\MinifierController;
|
||||||
|
use Silex\ControllerCollection;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ServiceProviderInterface;
|
use Silex\ServiceProviderInterface;
|
||||||
@@ -21,7 +22,7 @@ class Minifier implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.minifier'] = $app->share(function ($app) {
|
$app['controller.minifier'] = $app->share(function (Application $app) {
|
||||||
$cachePath = $app['cache.path'] . '/minify';
|
$cachePath = $app['cache.path'] . '/minify';
|
||||||
/** @var Filesystem $fs */
|
/** @var Filesystem $fs */
|
||||||
$fs = $app['filesystem'];
|
$fs = $app['filesystem'];
|
||||||
@@ -38,6 +39,7 @@ class Minifier implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
|
|
||||||
public function connect(Application $app)
|
public function connect(Application $app)
|
||||||
{
|
{
|
||||||
|
/** @var ControllerCollection $controllers */
|
||||||
$controllers = $app['controllers_factory'];
|
$controllers = $app['controllers_factory'];
|
||||||
|
|
||||||
$controllers->get('/', 'controller.minifier:minifyAction')->bind('minifier');
|
$controllers->get('/', 'controller.minifier:minifyAction')->bind('minifier');
|
||||||
|
@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\ControllerProvider;
|
|||||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Controller\PermalinkController;
|
use Alchemy\Phrasea\Controller\PermalinkController;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
|
use Silex\ControllerCollection;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
use Silex\ServiceProviderInterface;
|
use Silex\ServiceProviderInterface;
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ class Permalink implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.permalink'] = $app->share(function () use ($app) {
|
$app['controller.permalink'] = $app->share(function (PhraseaApplication $app) {
|
||||||
return new PermalinkController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication']);
|
return new PermalinkController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -32,61 +33,42 @@ class Permalink implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
|
|
||||||
public function connect(Application $app)
|
public function connect(Application $app)
|
||||||
{
|
{
|
||||||
|
/** @var ControllerCollection $controllers */
|
||||||
$controllers = $app['controllers_factory'];
|
$controllers = $app['controllers_factory'];
|
||||||
|
|
||||||
$controllers->get('/v1/{sbas_id}/{record_id}/caption/', 'controller.permalink:deliverCaption')
|
$controllers
|
||||||
->assert('sbas_id', '\d+')
|
->assert('sbas_id', '\d+')
|
||||||
->assert('record_id', '\d+')
|
->assert('record_id', '\d+');
|
||||||
->bind('permalinks_caption')
|
|
||||||
;
|
$controllers->get('/v1/{sbas_id}/{record_id}/caption/', 'controller.permalink:deliverCaption')
|
||||||
|
->bind('permalinks_caption');
|
||||||
|
|
||||||
$controllers->match('/v1/{sbas_id}/{record_id}/caption/', 'controller.permalink:getOptionsResponse')
|
$controllers->match('/v1/{sbas_id}/{record_id}/caption/', 'controller.permalink:getOptionsResponse')
|
||||||
->assert('sbas_id', '\d+')
|
->method('OPTIONS');
|
||||||
->assert('record_id', '\d+')
|
|
||||||
->method('OPTIONS')
|
|
||||||
;
|
|
||||||
|
|
||||||
$controllers->get('/v1/{sbas_id}/{record_id}/{subdef}/', 'controller.permalink:deliverPermaview')
|
$controllers->get('/v1/{sbas_id}/{record_id}/{subdef}/', 'controller.permalink:deliverPermaview')
|
||||||
->bind('permalinks_permaview')
|
->bind('permalinks_permaview');
|
||||||
->assert('sbas_id', '\d+')
|
|
||||||
->assert('record_id', '\d+')
|
|
||||||
;
|
|
||||||
|
|
||||||
$controllers->match('/v1/{sbas_id}/{record_id}/{subdef}/', 'controller.permalink:getOptionsResponse')
|
$controllers->match('/v1/{sbas_id}/{record_id}/{subdef}/', 'controller.permalink:getOptionsResponse')
|
||||||
->method('OPTIONS')
|
->method('OPTIONS');
|
||||||
->assert('sbas_id', '\d+')
|
|
||||||
->assert('record_id', '\d+')
|
|
||||||
;
|
|
||||||
|
|
||||||
$controllers->get(
|
$controllers->get(
|
||||||
'/v1/{label}/{sbas_id}/{record_id}/{token}/{subdef}/view/',
|
'/v1/{label}/{sbas_id}/{record_id}/{token}/{subdef}/view/',
|
||||||
'controller.permalink:deliverPermaviewOldWay'
|
'controller.permalink:deliverPermaviewOldWay'
|
||||||
)
|
)
|
||||||
->bind('permalinks_permaview_old')
|
->bind('permalinks_permaview_old');
|
||||||
->assert('sbas_id', '\d+')
|
|
||||||
->assert('record_id', '\d+')
|
|
||||||
;
|
|
||||||
|
|
||||||
$controllers->get('/v1/{sbas_id}/{record_id}/{subdef}/{label}', 'controller.permalink:deliverPermalink')
|
$controllers->get('/v1/{sbas_id}/{record_id}/{subdef}/{label}', 'controller.permalink:deliverPermalink')
|
||||||
->bind('permalinks_permalink')
|
->bind('permalinks_permalink');
|
||||||
->assert('sbas_id', '\d+')
|
|
||||||
->assert('record_id', '\d+')
|
|
||||||
;
|
|
||||||
|
|
||||||
$controllers->match('/v1/{sbas_id}/{record_id}/{subdef}/{label}', 'controller.permalink:getOptionsResponse')
|
$controllers->match('/v1/{sbas_id}/{record_id}/{subdef}/{label}', 'controller.permalink:getOptionsResponse')
|
||||||
->method('OPTIONS')
|
->method('OPTIONS');
|
||||||
->assert('sbas_id', '\d+')
|
|
||||||
->assert('record_id', '\d+')
|
|
||||||
;
|
|
||||||
|
|
||||||
$controllers->get(
|
$controllers->get(
|
||||||
'/v1/{label}/{sbas_id}/{record_id}/{token}/{subdef}/',
|
'/v1/{label}/{sbas_id}/{record_id}/{token}/{subdef}/',
|
||||||
'controller.permalink:deliverPermalinkOldWay'
|
'controller.permalink:deliverPermalinkOldWay'
|
||||||
)
|
)
|
||||||
->bind('permalinks_permalink_old')
|
->bind('permalinks_permalink_old');
|
||||||
->assert('sbas_id', '\d+')
|
|
||||||
->assert('record_id', '\d+')
|
|
||||||
;
|
|
||||||
|
|
||||||
return $controllers;
|
return $controllers;
|
||||||
}
|
}
|
||||||
|
@@ -11,33 +11,35 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\ControllerProvider;
|
namespace Alchemy\Phrasea\ControllerProvider;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Controller\SetupController;
|
use Alchemy\Phrasea\Controller\SetupController;
|
||||||
use Alchemy\Phrasea\Helper\DatabaseHelper;
|
use Alchemy\Phrasea\Helper\DatabaseHelper;
|
||||||
use Alchemy\Phrasea\Helper\PathHelper;
|
use Alchemy\Phrasea\Helper\PathHelper;
|
||||||
|
use Silex\ControllerCollection;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
use Silex\Application as SilexApplication;
|
use Silex\Application;
|
||||||
use Silex\ServiceProviderInterface;
|
use Silex\ServiceProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class Setup implements ControllerProviderInterface, ServiceProviderInterface
|
class Setup implements ControllerProviderInterface, ServiceProviderInterface
|
||||||
{
|
{
|
||||||
public function register(SilexApplication $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.setup'] = $app->share(function ($application) {
|
$app['controller.setup'] = $app->share(function (PhraseaApplication $application) {
|
||||||
return new SetupController($application);
|
return new SetupController($application);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(SilexApplication $app)
|
public function boot(Application $app)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connect(SilexApplication $app)
|
public function connect(Application $app)
|
||||||
{
|
{
|
||||||
|
/** @var ControllerCollection $controllers */
|
||||||
$controllers = $app['controllers_factory'];
|
$controllers = $app['controllers_factory'];
|
||||||
|
|
||||||
$controllers->get('/', function (Application $app) {
|
$controllers->get('/', function (PhraseaApplication $app) {
|
||||||
return $app->redirectPath('install_root');
|
return $app->redirectPath('install_root');
|
||||||
})->bind('setup');
|
})->bind('setup');
|
||||||
|
|
||||||
@@ -53,19 +55,19 @@ class Setup implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
$controllers->post('/installer/install/', 'controller.setup:doInstall')
|
$controllers->post('/installer/install/', 'controller.setup:doInstall')
|
||||||
->bind('install_do_install');
|
->bind('install_do_install');
|
||||||
|
|
||||||
$controllers->get('/connection_test/mysql/', function (Application $app, Request $request) {
|
$controllers->get('/connection_test/mysql/', function (PhraseaApplication $app, Request $request) {
|
||||||
$dbHelper = new DatabaseHelper($app, $request);
|
$dbHelper = new DatabaseHelper($app, $request);
|
||||||
|
|
||||||
return $app->json($dbHelper->checkConnection());
|
return $app->json($dbHelper->checkConnection());
|
||||||
});
|
});
|
||||||
|
|
||||||
$controllers->get('/test/path/', function (Application $app, Request $request) {
|
$controllers->get('/test/path/', function (PhraseaApplication $app, Request $request) {
|
||||||
$pathHelper = new PathHelper($app, $request);
|
$pathHelper = new PathHelper($app, $request);
|
||||||
|
|
||||||
return $app->json($pathHelper->checkPath());
|
return $app->json($pathHelper->checkPath());
|
||||||
});
|
});
|
||||||
|
|
||||||
$controllers->get('/test/url/', function (Application $app, Request $request) {
|
$controllers->get('/test/url/', function (PhraseaApplication $app, Request $request) {
|
||||||
$pathHelper = new PathHelper($app, $request);
|
$pathHelper = new PathHelper($app, $request);
|
||||||
|
|
||||||
return $app->json($pathHelper->checkUrl());
|
return $app->json($pathHelper->checkUrl());
|
||||||
|
@@ -516,6 +516,13 @@ class databox extends base
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Application $app
|
||||||
|
* @param Connection $connection
|
||||||
|
* @param SplFileInfo $data_template
|
||||||
|
* @return databox
|
||||||
|
* @throws \Doctrine\DBAL\DBALException
|
||||||
|
*/
|
||||||
public static function create(Application $app, Connection $connection, \SplFileInfo $data_template)
|
public static function create(Application $app, Connection $connection, \SplFileInfo $data_template)
|
||||||
{
|
{
|
||||||
if ( ! file_exists($data_template->getRealPath())) {
|
if ( ! file_exists($data_template->getRealPath())) {
|
||||||
|
Reference in New Issue
Block a user