Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the remains of kohana #1841

Merged
merged 20 commits into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f666cae
chore: Remove all kohana related dependencies
rjmackay Jun 22, 2017
5221ad1
refactor: Stop bootstrapping kohana and fixup broken kohana deps
rjmackay Jun 26, 2017
381756b
chore: Move media for tests out of application/media
rjmackay Dec 21, 2017
1b58122
fix: Remove kohana dependency from JSON formatter
rjmackay Dec 21, 2017
43b1ddf
refactor: Remove kohana refs in media formatter
rjmackay Dec 21, 2017
7034f15
fix: Remove check for SYSPATH from validation lang files
rjmackay Dec 21, 2017
c11471e
chore: Git ignore media uploads
rjmackay Dec 21, 2017
124eb58
refactor: remove application/
rjmackay Dec 21, 2017
ef2e1ed
refactor: Update media formatter and config work without kohana-media
rjmackay Dec 21, 2017
73c28f7
style: Fix lint issues in in AppServiceProvider
rjmackay Dec 21, 2017
66acf80
refactor: Update Notification command to use trans() not Kohana::mess…
rjmackay Dec 21, 2017
ef94959
refactor: Log using facade not kohana
rjmackay Dec 21, 2017
8c37b77
fix: Use config() in multisite not Kohana::$config
rjmackay Dec 21, 2017
d356517
fix: Remove stray `use Kohana` statement
rjmackay Dec 21, 2017
457f93e
docs: Remove Kohana refs in comments
rjmackay Dec 21, 2017
926b7db
refactor: Start splitting DI into sections or moving into Init.php
rjmackay Jan 23, 2018
d4f76db
fix: Multisite needs to grab ohanzee-db config
rjmackay Jan 23, 2018
03d80aa
refactor: clean out unused code in RESTController
rjmackay Jan 23, 2018
5b2137e
chore: Enable facades
rjmackay Jan 23, 2018
a7d8bb8
docs: Add todos and remove old comment refs
rjmackay Jan 25, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Controllers/API/MigrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function index(Request $request, $command = 'status')
$command = 'status';
}

$db = service('db.config');
$phinx_config = ['configuration' => realpath(APPPATH . '../phinx.php'),
$phinx_config = [
'configuration' => base_path('phinx.php'),
'parser' => 'php',
];

Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ class MigrateController extends Controller

public function migrate()
{
$db = service('db.config');
$phinx_config = [
'configuration' => realpath(APPPATH . '../phinx.php'),
'configuration' => base_path('phinx.php'),
'parser' => 'php',
];

Expand Down
65 changes: 25 additions & 40 deletions app/Http/Controllers/RESTController.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ protected function getRouteParams(Request $request)
/**
* Execute the usecase that the controller prepared.
*
* @todo should this take Usecase as a param rather than use $this->usecase?
*
* @throws HTTP_Exception_400
* @throws HTTP_Exception_403
* @throws HTTP_Exception_404
Expand Down Expand Up @@ -243,9 +245,6 @@ protected function executeUsecase(Request $request)
*/
protected function prepResponse(array $responsePayload = null, Request $request)
{
// Add CORS headers to the response
// $this->add_cors_headers($this->response);

// Use JSON if the request method is OPTIONS
if ($request->method() === Request::METHOD_OPTIONS) {
$type = 'json';
Expand All @@ -255,45 +254,31 @@ protected function prepResponse(array $responsePayload = null, Request $request)
$type = strtolower($request->query('format')) ?: 'json';
}

try {
//$format = service("formatter.output.$type");

// $body = $format($this->_response_payload);
// $mime = $format->getMimeType();
// $this->response->headers('Content-Type', $mime);

if (empty($responsePayload)) {
// If the payload is empty, return a 204
// https://tools.ietf.org/html/rfc7231#section-6.3.5
$response = response('', 204);
} else {
$response = response()->json(
$responsePayload,
200,
[],
env('APP_DEBUG', false) ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES : null
);

if ($type === 'jsonp') {
$response->withCallback($request->input('callback'));
// Prevent Opera and Chrome from executing the response as anything
// other than JSONP, see T455.
$response->headers->set('X-Content-Type-Options', 'nosniff');
}
}

// Should we prevent this request from being cached?
if (! in_array($request->method(), $this->cacheableMethods)) {
$response->headers->set('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate');
if (empty($responsePayload)) {
// If the payload is empty, return a 204
// https://tools.ietf.org/html/rfc7231#section-6.3.5
$response = response('', 204);
} else {
$response = response()->json(
$responsePayload,
200,
[],
env('APP_DEBUG', false) ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES : null
);

if ($type === 'jsonp') {
$response->withCallback($request->input('callback'));
// Prevent Opera and Chrome from executing the response as anything
// other than JSONP, see T455.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be a link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh its a reference to phabricator WAT

$response->headers->set('X-Content-Type-Options', 'nosniff');
}
}

return $response;
} catch (\Aura\Di\Exception\ServiceNotFound $e) {
abort(400, 'Unknown response format:' . $type);
} catch (\InvalidArgumentException $e) {
abort(400, 'Bad formatting parameters:' . $e->getMessage());
} catch (\Ushahidi\Core\Exception\FormatterException $e) {
abort(500, 'Error while formatting response:' . $e->getMessage());
// Should we prevent this request from being cached?
if (! in_array($request->method(), $this->cacheableMethods)) {
$response->headers->set('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate');
}

return $response;
}
}
198 changes: 94 additions & 104 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ class AppServiceProvider extends ServiceProvider
* @return void
*/
public function register()
{
$this->app->configure('cdn');
$this->app->configure('media');
$this->app->configure('ratelimiter');
$this->app->configure('multisite');
$this->app->configure('ohanzee-db');

$this->registerServicesFromAura();
Copy link
Contributor

@rowasc rowasc Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it matter that it is using AuraDI to register usecase and repository.message?


$this->registerFilesystem();
$this->registerMailer();
$this->registerDataSources();

$this->configureAuraDI();

// Hack, must construct it to register route :/
$this->app->make('datasources');
}

public function registerServicesFromAura()
{
$this->app->singleton(\Ushahidi\Factory\UsecaseFactory::class, function ($app) {
// Just return it from AuraDI
Expand All @@ -22,20 +42,10 @@ public function register()
// Just return it from AuraDI
return service('repository.message');
});
}

$this->app->configure('cdn');
$this->app->configure('ratelimiter');
$this->app->configure('multisite');

// Add filesystem
$this->app->singleton('filesystem', function ($app) {
return $app->loadComponent(
'filesystems',
\Illuminate\Filesystem\FilesystemServiceProvider::class,
'filesystem'
);
});

public function registerMailer()
{
// Add mailer
$this->app->singleton('mailer', function ($app) {
return $app->loadComponent(
Expand All @@ -44,103 +54,68 @@ public function register()
'mailer'
);
});
}

public function registerFilesystem()
{
// Add filesystem
$this->app->singleton('filesystem', function ($app) {
return $app->loadComponent(
'filesystems',
\Illuminate\Filesystem\FilesystemServiceProvider::class,
'filesystem'
);
});
}

public function registerDataSources()
{
$this->app->singleton('datasources', function () {
return $this->app->loadComponent(
'datasources',
\Ushahidi\App\DataSource\DataSourceServiceProvider::class,
'datasources'
);
});

$this->configureAuraDI();

// Hack, must construct it to register route :/
$this->app->make('datasources');
}

// @todo move most of this elsewhere
protected function configureAuraDI()
{
$di = service();

// Multisite db
$di->set('site', function () use ($di) {
$site = '';

// Is this a multisite install?
$multisite = config('multisite.enabled');
if ($multisite) {
$site = $di->get('multisite')->getSite();
}

return $site;
});

// Site config
$di->set('site.config', function () use ($di) {
return $di->get('repository.config')->get('site')->asArray();
});

// Client Url
$di->set('clienturl', function () use ($di) {
return $this->getClientUrl($di->get('site.config'));
});

// Feature config
$di->set('features', function () use ($di) {
return $di->get('repository.config')->get('features')->asArray();
});

// Roles config settings
$di->set('roles.enabled', function () use ($di) {
$config = $di->get('features');

return $config['roles']['enabled'];
});

// Feature config
$di->set('features.limits', function () use ($di) {
$config = $di->get('features');

return $config['limits'];
});

// Webhooks config settings
$di->set('webhooks.enabled', function () use ($di) {
$config = $di->get('features');

return $config['webhooks']['enabled'];
});

// Post Locking config settings
$di->set('post-locking.enabled', function () use ($di) {
$config = $di->get('features');

return $config['post-locking']['enabled'];
});
$this->configureAuraServices($di);
$this->injectAuraConfig($di);
}

// Redis config settings
$di->set('redis.enabled', function () use ($di) {
$config = $di->get('features');
protected function configureAuraServices(\Aura\Di\ContainerInterface $di)
{
// Configure mailer
$di->set('tool.mailer', $di->lazyNew('Ushahidi\App\Tools\LumenMailer', [
'mailer' => app('mailer'),
'siteConfig' => $di->lazyGet('site.config'),
'clientUrl' => $di->lazyGet('clienturl')
]));

return $config['redis']['enabled'];
});
// Setup user session service
$di->set('session', $di->lazyNew(\Ushahidi\App\Tools\LumenSession::class, [
'userRepo' => $di->lazyGet('repository.user')
]));

// Data import config settings
$di->set('data-import.enabled', function () use ($di) {
$config = $di->get('features');
// Multisite db
$di->set('kohana.db.multisite', function () use ($di) {
$config = config('ohanzee-db');

return $config['data-import']['enabled'];
return \Ohanzee\Database::instance('multisite', $config['default']);
});

$di->set('features.data-providers', function () use ($di) {
$config = $di->get('features');

return array_filter($config['data-providers']);
// Deployment db
$di->set('kohana.db', function () use ($di) {
return \Ohanzee\Database::instance('deployment', $this->getDbConfig($di));
});
}

protected function injectAuraConfig(\Aura\Di\ContainerInterface $di)
{
// CDN Config settings
$di->set('cdn.config', function () use ($di) {
return config('cdn');
Expand All @@ -151,15 +126,21 @@ protected function configureAuraDI()
return config('ratelimiter');
});

// Private deployment config settings
// @todo move to repo
$di->set('site.private', function () use ($di) {
$site = $di->get('site.config');
$features = $di->get('features');
return $site['private']
and $features['private']['enabled'];
// Multisite db
// Move multisite enabled check to class and move to src/App
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we talk about multisite install, is that the way we have the setup for ushahidi.io clients?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's correct, yes

$di->set('site', function () use ($di) {
$site = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a todo to make this a logical default?


// Is this a multisite install?
$multisite = config('multisite.enabled');
if ($multisite) {
$site = $di->get('multisite')->getSite();
}

return $site;
});

// Move multisite enabled check to class and move to src/App
$di->set('tool.uploader.prefix', function () use ($di) {
// Is this a multisite install?
$multisite = config('multisite.enabled');
Expand All @@ -170,17 +151,26 @@ protected function configureAuraDI()
return '';
});

// Configure mailer
$di->set('tool.mailer', $di->lazyNew('Ushahidi\App\Tools\LumenMailer', [
'mailer' => app('mailer'),
'siteConfig' => $di->lazyGet('site.config'),
'clientUrl' => $di->lazyGet('clienturl')
]));
// Client Url
$di->set('clienturl', function () use ($di) {
return $this->getClientUrl($di->get('site.config'));
});
}

// @todo move to auth provider?
$di->set('session', $di->lazyNew(\Ushahidi\App\Tools\LumenSession::class, [
'userRepo' => $di->lazyGet('repository.user')
]));
protected function getDbConfig(\Aura\Di\ContainerInterface $di)
{
// Kohana injection
// DB config
$config = config('ohanzee-db');
$config = $config['default'];

// Is this a multisite install?
$multisite = config('multisite.enabled');
if ($multisite) {
$config = $di->get('multisite')->getDbConfig();
}

return $config;
}

protected function getClientUrl($config)
Expand Down
Loading