1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-02 12:47:41 +02:00

Udpate to support dev/prod env

This commit is contained in:
Laurent Cozic 2017-01-09 22:15:02 +01:00
parent 11115077d5
commit 228831bf23
9 changed files with 29 additions and 13 deletions

4
.gitignore vendored
View File

@ -1,4 +1,6 @@
/app/config/parameters.yml
/app/config/parameters_dev.yml
/app/config/parameters_prod.yml
/build/
/phpunit.xml
/var/*
@ -26,3 +28,5 @@ app/data/uploads/
!app/data/uploads/.gitkeep
sparse_test.php
INFO.md
/web/env.php
sync_staging.sh

View File

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

1
env.php.sample Executable file
View File

@ -0,0 +1 @@
<?php return 'dev'; // return 'prod';

View File

@ -47,14 +47,19 @@ abstract class ApiController extends Controller {
$s = $this->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);
}

View File

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

View File

@ -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) {

4
web/.ovhconfig Executable file
View File

@ -0,0 +1,4 @@
app.engine=php
app.engine.version=7.0
http.firewall=none
environment=development

View File

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

0
web/config.php Executable file → Normal file
View File