diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 7b8407d997..c8724f6b20 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -77,6 +77,7 @@ use Alchemy\Phrasea\Core\Event\Subscriber\LogoutSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaLocaleSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\MaintenanceSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\CookiesDisablerSubscriber; +use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaInstallSubscriber; use Alchemy\Phrasea\Core\Middleware\ApiApplicationMiddlewareProvider; use Alchemy\Phrasea\Core\Middleware\BasketMiddlewareProvider; use Alchemy\Phrasea\Core\Middleware\TokenMiddlewareProvider; @@ -473,6 +474,7 @@ class Application extends SilexApplication $dispatcher->addSubscriber(new PhraseaLocaleSubscriber($app)); $dispatcher->addSubscriber(new MaintenanceSubscriber($app)); $dispatcher->addSubscriber(new CookiesDisablerSubscriber($app)); + $dispatcher->addSubscriber(new PhraseaInstallSubscriber($app)); return $dispatcher; }) diff --git a/lib/Alchemy/Phrasea/Core/Event/InstallFinishEvent.php b/lib/Alchemy/Phrasea/Core/Event/InstallFinishEvent.php new file mode 100644 index 0000000000..b3a4ec1ccf --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/InstallFinishEvent.php @@ -0,0 +1,31 @@ +user = $user; + } + + public function getUser() + { + return $this->user; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaInstallSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaInstallSubscriber.php new file mode 100644 index 0000000000..ae0f9b415a --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaInstallSubscriber.php @@ -0,0 +1,77 @@ +app = $app; + } + + public static function getSubscribedEvents() + { + return [ + PhraseaEvents::INSTALL_FINISH => 'onInstallFinished' + ]; + } + + public function onInstallFinished(InstallFinishEvent $event) + { + $this->createNavigatorApplication(); + $this->createOfficePluginApplication(); + } + + private function createNavigatorApplication() + { + $application = $this->app['manipulator.api-application']->create( + \API_OAuth2_Application_Navigator::CLIENT_NAME, + ApiApplication::DESKTOP_TYPE, + '', + 'http://www.phraseanet.com', + null, + ApiApplication::NATIVE_APP_REDIRECT_URI + ); + + $application->setGrantPassword(true); + $application->setClientId(\API_OAuth2_Application_Navigator::CLIENT_ID); + $application->setClientSecret(\API_OAuth2_Application_Navigator::CLIENT_SECRET); + + $this->app['manipulator.api-application']->update($application); + } + + private function createOfficePluginApplication() + { + $application = $this->app['manipulator.api-application']->create( + \API_OAuth2_Application_OfficePlugin::CLIENT_NAME, + ApiApplication::DESKTOP_TYPE, + '', + 'http://www.phraseanet.com', + null, + ApiApplication::NATIVE_APP_REDIRECT_URI + ); + + $application->setGrantPassword(true); + $application->setClientId(\API_OAuth2_Application_OfficePlugin::CLIENT_ID); + $application->setClientSecret(\API_OAuth2_Application_OfficePlugin::CLIENT_SECRET); + + $this->app['manipulator.api-application']->update($application); + } +} diff --git a/lib/Alchemy/Phrasea/Core/PhraseaEvents.php b/lib/Alchemy/Phrasea/Core/PhraseaEvents.php index 6cff63f9e2..c282f9e831 100644 --- a/lib/Alchemy/Phrasea/Core/PhraseaEvents.php +++ b/lib/Alchemy/Phrasea/Core/PhraseaEvents.php @@ -18,6 +18,8 @@ final class PhraseaEvents const PRE_AUTHENTICATE = 'phrasea.pre-authenticate'; const POST_AUTHENTICATE = 'phrasea.post-authenticate'; + const INSTALL_FINISH = "phrasea.install-finish"; + const API_OAUTH2_START = 'api.oauth2.start'; const API_OAUTH2_END = 'api.oauth2.end'; const API_LOAD_START = 'api.load.start'; diff --git a/lib/Alchemy/Phrasea/Setup/Installer.php b/lib/Alchemy/Phrasea/Setup/Installer.php index 40b7600337..eb4a304f3d 100644 --- a/lib/Alchemy/Phrasea/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Setup/Installer.php @@ -12,10 +12,12 @@ namespace Alchemy\Phrasea\Setup; use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Core\PhraseaEvents; +use Alchemy\Phrasea\Core\Event\InstallFinishEvent; +use Alchemy\Phrasea\Model\Entities\User; use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\DBALException; use Doctrine\ORM\Tools\SchemaTool; -use Alchemy\Phrasea\Model\Entities\User; class Installer { @@ -46,6 +48,8 @@ class Installer throw $e; } + $this->app['dispatcher']->dispatch(PhraseaEvents::INSTALL_FINISH, new InstallFinishEvent($user)); + return $user; }