diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 9ae01f5e55..35f195d037 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -12,7 +12,6 @@ namespace Alchemy\Phrasea; use Alchemy\Geonames\GeonamesServiceProvider; -use Alchemy\Phrasea\ControllerProvider\Admin\Databoxes; use Alchemy\Phrasea\ControllerProvider\Admin\Fields; use Alchemy\Phrasea\ControllerProvider\Admin\Publications; 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\Dashboard' => [], 'Alchemy\Phrasea\ControllerProvider\Admin\Databox' => [], + 'Alchemy\Phrasea\ControllerProvider\Admin\Databoxes' => [], 'Alchemy\Phrasea\ControllerProvider\Admin\Users' => [], 'Alchemy\Phrasea\ControllerProvider\Datafiles' => [], 'Alchemy\Phrasea\ControllerProvider\Lightbox' => [], @@ -618,7 +618,6 @@ class Application extends SilexApplication $this->mount('/developers/', new Developers()); $this->mount('/admin/', new AdminRoot()); - $this->mount('/admin/databoxes', new Databoxes()); $this->mount('/admin/setup', new Setup()); $this->mount('/admin/search-engine', new SearchEngine()); $this->mount('/admin/publications', new Publications()); @@ -671,6 +670,7 @@ class Application extends SilexApplication '/admin/connected-users' => 'Alchemy\Phrasea\ControllerProvider\Admin\ConnectedUsers', '/admin/dashboard' => 'Alchemy\Phrasea\ControllerProvider\Admin\Dashboard', '/admin/databox' => 'Alchemy\Phrasea\ControllerProvider\Admin\Databox', + '/admin/databoxes' => 'Alchemy\Phrasea\ControllerProvider\Admin\Databoxes', '/admin/users' => 'Alchemy\Phrasea\ControllerProvider\Admin\Users', '/datafiles' => 'Alchemy\Phrasea\ControllerProvider\Datafiles', '/include/minify' => 'Alchemy\Phrasea\ControllerProvider\Minifier', diff --git a/lib/Alchemy/Phrasea/Controller/Admin/DataboxesController.php b/lib/Alchemy/Phrasea/Controller/Admin/DataboxesController.php new file mode 100644 index 0000000000..f897ed59c4 --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Admin/DataboxesController.php @@ -0,0 +1,340 @@ +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); + } +} diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php index c5f72e1854..d6fd6f8110 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin; +use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Admin\CollectionController; use Silex\Application; use Silex\ControllerCollection; @@ -21,7 +22,7 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac { 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); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/ConnectedUsers.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/ConnectedUsers.php index 122116a22a..e30460e433 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/ConnectedUsers.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/ConnectedUsers.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin; +use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Admin\ConnectedUsersController; use Silex\Application; use Silex\ControllerCollection; @@ -21,7 +22,7 @@ class ConnectedUsers implements ControllerProviderInterface, ServiceProviderInte { 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); }); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Dashboard.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Dashboard.php index d637949d46..700a4833b5 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Dashboard.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Dashboard.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin; +use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Admin\DashboardController; use Silex\Application; use Silex\ControllerCollection; @@ -21,7 +22,7 @@ class Dashboard implements ControllerProviderInterface, ServiceProviderInterface { 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); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databox.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databox.php index 8938c8e1db..91301a1732 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databox.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databox.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin; +use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Admin\DataboxController; use Alchemy\Phrasea\Security\Firewall; use Silex\Application; @@ -23,7 +24,7 @@ class Databox implements ControllerProviderInterface, ServiceProviderInterface { 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); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databoxes.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databoxes.php index 0e08f4b0c2..b99d79ecb0 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databoxes.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Databoxes.php @@ -11,25 +11,38 @@ 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\ControllerCollection; use Silex\ControllerProviderInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; +use Silex\ServiceProviderInterface; -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) { - $app['controller.admin.databoxes'] = $this; - + /** @var ControllerCollection $controllers */ $controllers = $app['controllers_factory']; - $app['firewall']->addMandatoryAuthentication($controllers); + /** @var Firewall $firewall */ + $firewall = $app['firewall']; + $firewall->addMandatoryAuthentication($controllers); - $controllers->before(function (Request $request) use ($app) { - $app['firewall']->requireAccessToModule('admin'); + $controllers->before(function () use ($firewall) { + $firewall->requireAccessToModule('admin'); }); $controllers->get('/', 'controller.admin.databoxes:getDatabases') @@ -37,241 +50,16 @@ class Databoxes implements ControllerProviderInterface $controllers->post('/', 'controller.admin.databoxes:createDatabase') ->bind('admin_database_new') - ->before(function (Request $request) use ($app) { - $app['firewall']->requireAdmin(); + ->before(function () use ($firewall) { + $firewall->requireAdmin(); }); $controllers->post('/mount/', 'controller.admin.databoxes:databaseMount') ->bind('admin_database_mount') - ->before(function (Request $request) use ($app) { - $app['firewall']->requireAdmin(); + ->before(function () use ($firewall) { + $firewall->requireAdmin(); }); 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']); - } - } - } } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Datafiles.php b/lib/Alchemy/Phrasea/ControllerProvider/Datafiles.php index 2d30735360..bb30898ef3 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Datafiles.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Datafiles.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\ControllerProvider; +use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\DatafileController; use Silex\Application; use Silex\ControllerProviderInterface; @@ -21,7 +22,7 @@ class Datafiles implements ControllerProviderInterface, ServiceProviderInterface { 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']); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php b/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php index a608c0e164..a4b9d3b894 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php @@ -25,7 +25,7 @@ class Lightbox implements ControllerProviderInterface, ServiceProviderInterface { 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); }); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Minifier.php b/lib/Alchemy/Phrasea/ControllerProvider/Minifier.php index 11a47e0abf..1265e0fdf3 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Minifier.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Minifier.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\ControllerProvider; use Alchemy\Phrasea\Controller\MinifierController; +use Silex\ControllerCollection; use Silex\ControllerProviderInterface; use Silex\Application; use Silex\ServiceProviderInterface; @@ -21,7 +22,7 @@ class Minifier implements ControllerProviderInterface, ServiceProviderInterface { 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'; /** @var Filesystem $fs */ $fs = $app['filesystem']; @@ -38,6 +39,7 @@ class Minifier implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { + /** @var ControllerCollection $controllers */ $controllers = $app['controllers_factory']; $controllers->get('/', 'controller.minifier:minifyAction')->bind('minifier'); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Permalink.php b/lib/Alchemy/Phrasea/ControllerProvider/Permalink.php index 6c59c324ab..6bc9817e4a 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Permalink.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Permalink.php @@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\ControllerProvider; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\PermalinkController; use Silex\Application; +use Silex\ControllerCollection; use Silex\ControllerProviderInterface; use Silex\ServiceProviderInterface; @@ -21,7 +22,7 @@ class Permalink implements ControllerProviderInterface, ServiceProviderInterface { 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']); }); } @@ -32,61 +33,42 @@ class Permalink implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { + /** @var ControllerCollection $controllers */ $controllers = $app['controllers_factory']; - $controllers->get('/v1/{sbas_id}/{record_id}/caption/', 'controller.permalink:deliverCaption') + $controllers ->assert('sbas_id', '\d+') - ->assert('record_id', '\d+') - ->bind('permalinks_caption') - ; + ->assert('record_id', '\d+'); + + $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') - ->assert('sbas_id', '\d+') - ->assert('record_id', '\d+') - ->method('OPTIONS') - ; + ->method('OPTIONS'); $controllers->get('/v1/{sbas_id}/{record_id}/{subdef}/', 'controller.permalink:deliverPermaview') - ->bind('permalinks_permaview') - ->assert('sbas_id', '\d+') - ->assert('record_id', '\d+') - ; + ->bind('permalinks_permaview'); $controllers->match('/v1/{sbas_id}/{record_id}/{subdef}/', 'controller.permalink:getOptionsResponse') - ->method('OPTIONS') - ->assert('sbas_id', '\d+') - ->assert('record_id', '\d+') - ; + ->method('OPTIONS'); $controllers->get( '/v1/{label}/{sbas_id}/{record_id}/{token}/{subdef}/view/', 'controller.permalink:deliverPermaviewOldWay' ) - ->bind('permalinks_permaview_old') - ->assert('sbas_id', '\d+') - ->assert('record_id', '\d+') - ; + ->bind('permalinks_permaview_old'); $controllers->get('/v1/{sbas_id}/{record_id}/{subdef}/{label}', 'controller.permalink:deliverPermalink') - ->bind('permalinks_permalink') - ->assert('sbas_id', '\d+') - ->assert('record_id', '\d+') - ; + ->bind('permalinks_permalink'); $controllers->match('/v1/{sbas_id}/{record_id}/{subdef}/{label}', 'controller.permalink:getOptionsResponse') - ->method('OPTIONS') - ->assert('sbas_id', '\d+') - ->assert('record_id', '\d+') - ; + ->method('OPTIONS'); $controllers->get( '/v1/{label}/{sbas_id}/{record_id}/{token}/{subdef}/', 'controller.permalink:deliverPermalinkOldWay' ) - ->bind('permalinks_permalink_old') - ->assert('sbas_id', '\d+') - ->assert('record_id', '\d+') - ; + ->bind('permalinks_permalink_old'); return $controllers; } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Setup.php b/lib/Alchemy/Phrasea/ControllerProvider/Setup.php index da2b81993b..7d24b304b7 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Setup.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Setup.php @@ -11,33 +11,35 @@ namespace Alchemy\Phrasea\ControllerProvider; -use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\SetupController; use Alchemy\Phrasea\Helper\DatabaseHelper; use Alchemy\Phrasea\Helper\PathHelper; +use Silex\ControllerCollection; use Silex\ControllerProviderInterface; -use Silex\Application as SilexApplication; +use Silex\Application; use Silex\ServiceProviderInterface; use Symfony\Component\HttpFoundation\Request; 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); }); } - 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->get('/', function (Application $app) { + $controllers->get('/', function (PhraseaApplication $app) { return $app->redirectPath('install_root'); })->bind('setup'); @@ -53,19 +55,19 @@ class Setup implements ControllerProviderInterface, ServiceProviderInterface $controllers->post('/installer/install/', 'controller.setup:doInstall') ->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); 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); 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); return $app->json($pathHelper->checkUrl()); diff --git a/lib/classes/databox.php b/lib/classes/databox.php index 9508eb7376..af7ed71359 100644 --- a/lib/classes/databox.php +++ b/lib/classes/databox.php @@ -516,6 +516,13 @@ class databox extends base 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) { if ( ! file_exists($data_template->getRealPath())) {