From 228831bf2371b4a0dcfd2b8222f75c9a3b180fc7 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 9 Jan 2017 22:15:02 +0100 Subject: [PATCH] Udpate to support dev/prod env --- .gitignore | 6 +++++- app/config/services.yml | 3 ++- env.php.sample | 1 + src/AppBundle/Controller/ApiController.php | 9 +++++++-- src/AppBundle/Eloquent.php | 13 ++++++------- src/AppBundle/Model/Change.php | 2 +- web/.ovhconfig | 4 ++++ web/app.php | 4 +++- web/config.php | 0 9 files changed, 29 insertions(+), 13 deletions(-) create mode 100755 env.php.sample create mode 100755 web/.ovhconfig mode change 100755 => 100644 web/config.php diff --git a/.gitignore b/.gitignore index 4a5f419fc..7d194c329 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /app/config/parameters.yml +/app/config/parameters_dev.yml +/app/config/parameters_prod.yml /build/ /phpunit.xml /var/* @@ -25,4 +27,6 @@ QtClient/data/ app/data/uploads/ !app/data/uploads/.gitkeep sparse_test.php -INFO.md \ No newline at end of file +INFO.md +/web/env.php +sync_staging.sh \ No newline at end of file diff --git a/app/config/services.yml b/app/config/services.yml index 8d921efcd..f4fadc0cc 100755 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -7,7 +7,8 @@ services: app.eloquent: class: AppBundle\Eloquent - arguments: ['@app.mime_types', '@app.paths'] + # arguments: [%kernel.environment%, '@app.mime_types', '@app.paths'] + arguments: [%database%, '@app.mime_types', '@app.paths'] twig.exception_listener: class: stdObject diff --git a/env.php.sample b/env.php.sample new file mode 100755 index 000000000..d64e21a96 --- /dev/null +++ b/env.php.sample @@ -0,0 +1 @@ +session(); - // TODO: find less hacky way to get request path + // TODO: find less hacky way to get request path and method $requestPath = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $requestPath = ltrim($requestPath, '/'); $requestPath = rtrim($requestPath, '?'); + $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; + + $sessionRequired = true; + if ($method == 'POST' && $requestPath == 'sessions') $sessionRequired = false; + if ($method == 'POST' && $requestPath == 'users') $sessionRequired = false; // TODO: to keep it simple, only respond to logged in users, but in theory some data // could be public. - if ($requestPath != 'sessions' && (!$s || !$this->user())) throw new UnauthorizedException('A session and user are required'); + if ($sessionRequired && (!$s || !$this->user())) throw new UnauthorizedException('A session and user are required'); BaseModel::setClientId($s ? $s->client_id : 0); } diff --git a/src/AppBundle/Eloquent.php b/src/AppBundle/Eloquent.php index 34d070bb0..84569098a 100755 --- a/src/AppBundle/Eloquent.php +++ b/src/AppBundle/Eloquent.php @@ -6,20 +6,19 @@ class Eloquent { private $capsule_ = null; - public function __construct($mimeTypes, $paths) { + public function __construct($dbParams, $mimeTypes, $paths) { $this->capsule_ = new \Illuminate\Database\Capsule\Manager(); - $this->capsule_->addConnection([ + $dbParamsDefaults = array( 'driver' => 'mysql', - 'host' => 'localhost', - 'database' => 'notes', - 'username' => 'root', - 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', - ]); + ); + $dbParams = array_merge($dbParamsDefaults, $dbParams); + + $this->capsule_->addConnection($dbParams); $this->capsule_->bootEloquent(); // In order to keep things lightweight, the models aren't part of Symfony dependency diff --git a/src/AppBundle/Model/Change.php b/src/AppBundle/Model/Change.php index 7938072b6..0d45fc05b 100755 --- a/src/AppBundle/Model/Change.php +++ b/src/AppBundle/Model/Change.php @@ -83,7 +83,7 @@ class Change extends BaseModel { }); foreach ($output as $k => $syncItem) { - if ($syncItem['item']) { + if (isset($syncItem['item'])) { $item = $syncItem['item']->toPublicArray(); if ($syncItem['type'] == 'update') { foreach ($item as $field => $value) { diff --git a/web/.ovhconfig b/web/.ovhconfig new file mode 100755 index 000000000..c4b6fdd2d --- /dev/null +++ b/web/.ovhconfig @@ -0,0 +1,4 @@ +app.engine=php +app.engine.version=7.0 +http.firewall=none +environment=development \ No newline at end of file diff --git a/web/app.php b/web/app.php index 6bd0ea016..b041fc237 100755 --- a/web/app.php +++ b/web/app.php @@ -6,7 +6,9 @@ use Symfony\Component\HttpFoundation\Request; $loader = require __DIR__.'/../app/autoload.php'; include_once __DIR__.'/../var/bootstrap.php.cache'; -$kernel = new AppKernel('prod', false); +$env = require 'env.php'; + +$kernel = new AppKernel($env, false); $kernel->loadClassCache(); //$kernel = new AppCache($kernel); diff --git a/web/config.php b/web/config.php old mode 100755 new mode 100644