Skip to content

Commit

Permalink
Merge 69b1653 into f1c3aaf
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmackay committed Nov 14, 2018
2 parents f1c3aaf + 69b1653 commit 0e61a62
Show file tree
Hide file tree
Showing 80 changed files with 1,532 additions and 695 deletions.
2 changes: 1 addition & 1 deletion .env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DB_DATABASE=ushahidi
DB_USERNAME=ushahidi
DB_PASSWORD=ushahidi

CACHE_DRIVER=file
CACHE_DRIVER=array
QUEUE_DRIVER=sync
MAIL_DRIVER=array

Expand Down
2 changes: 1 addition & 1 deletion .env.travis
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DB_DATABASE=ushahidi
DB_USERNAME=travis
DB_PASSWORD=

CACHE_DRIVER=file
CACHE_DRIVER=array
QUEUE_DRIVER=sync

MEDIA_MAX_UPLOAD=1048576
Expand Down
32 changes: 32 additions & 0 deletions app/Console/Commands/TestMultisiteJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Ushahidi\App\Console\Commands;

use Illuminate\Console\Command;

class TestMultisiteJob extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'test:multisitejob';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Queue a TestMultisiteJob.';

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
dispatch(new \Ushahidi\App\Jobs\TestMultisiteJob());
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Kernel extends ConsoleKernel
\Ushahidi\Console\Command\SavedSearch::class,
\Ushahidi\Console\Command\Webhook::class,
\Ushahidi\Console\Command\ObfuscateData::class,
Commands\TestMultisiteJob::class,
];

/**
Expand Down
12 changes: 7 additions & 5 deletions app/Http/Middleware/CheckDemoExpiration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ class CheckDemoExpiration
*/
public function handle($request, Closure $next, $guard = null)
{
$multisite = config('multisite.enabled');
$isDemoTier = service('site.config')['tier'] === 'demo';
$multisite = app('multisite');
$site = $multisite->getSite();
$isDemoTier = $site->tier === 'demo';
$isNotGet = !$request->isMethod('get');

if ($multisite && $isNotGet && $isDemoTier) {
if ($multisite->enabled() && $isNotGet && $isDemoTier) {
$now = new DateTime();
$expiration_date = strtotime(service('site.config')['expiration_date']);
$extension_date = strtotime(service('site.config')['extension_date']);
// Move time conversion to Site model
$expiration_date = strtotime($site->expiration_date);
$extension_date = strtotime($site->extension_date);

if ($expiration_date < $now && (!$extension_date || $extension_date < $now)) {
abort(503, 'The demo period for this deployment has expired.');
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Middleware/MaintenanceMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function handle($request, Closure $next, $guard = null)
$maintenanceMode = env('MAINTENANCE_MODE');
if ($maintenanceMode) {
$maintenanceMessage = 'This site is down for maintenance';
if (service('site.config')) {
$maintenanceMessage = service('site.config')['name'] . ' is down for maintenance.';
if ($site = app('multisite')->getSite()) {
$maintenanceMessage = $site->getName() . ' is down for maintenance.';
}
abort(
503,
Expand Down
2 changes: 2 additions & 0 deletions app/Jobs/CombineExportedPostBatchesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Ushahidi\Core\Entity\ExportJob;
use Ushahidi\Core\Entity\ExportJobRepository;
use Ushahidi\Core\Entity\ExportBatchRepository;
use Ushahidi\App\Multisite\MultisiteAwareJob;
use Illuminate\Http\File;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
Expand All @@ -16,6 +17,7 @@

class CombineExportedPostBatchesJob extends Job
{
use MultisiteAwareJob;
use RecordsExportJobFailure;

protected $jobId;
Expand Down
2 changes: 2 additions & 0 deletions app/Jobs/ExportPostsBatchJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Ushahidi\Factory\UsecaseFactory;
use Ushahidi\Core\Entity\ExportJob;
use Ushahidi\Core\Entity\ExportJobRepository;
use Ushahidi\App\Multisite\MultisiteAwareJob;
use Ushahidi\Core\Usecase\Post\Export;

class ExportPostsBatchJob extends Job
{
use MultisiteAwareJob;
use RecordsExportJobFailure;

protected $jobId;
Expand Down
2 changes: 2 additions & 0 deletions app/Jobs/ExportPostsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Ushahidi\Core\Usecase\Export\Job\PostCount;
use Ushahidi\Core\Entity\ExportJob;
use Ushahidi\Core\Entity\ExportJobRepository;
use Ushahidi\App\Multisite\MultisiteAwareJob;
use Illuminate\Support\Facades\Log;

class ExportPostsJob extends Job
{
use MultisiteAwareJob;
use RecordsExportJobFailure;

protected $batchSize;
Expand Down
46 changes: 46 additions & 0 deletions app/Jobs/TestMultisiteJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Ushahidi\App\Jobs;

use Illuminate\Support\Facades\Log;
use Ushahidi\App\Multisite\MultisiteAwareJob;

class TestMultisiteJob extends Job
{
use MultisiteAwareJob;

/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
//
}

/**
* Execute the job.
*
* @return void
*/
public function handle(\Ushahidi\App\Multisite\MultisiteManager $multisite)
{
// Get deployment ID
Log::debug('Site', [$multisite->getSite()]);

// Get config
Log::debug(
'Site config',
[app(\Ushahidi\Core\Entity\ConfigRepository::class)->get('site')->asArray()]
);

// Get an ohanzee DB connection
// Get an illuminate DB connection
Log::debug(
'Export batch',
[app(\Ushahidi\Core\Entity\ExportBatchRepository::class)->getByJobId(10)]
);
}
}
62 changes: 11 additions & 51 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public function register()
$this->registerFilesystem();
$this->registerMailer();

$this->registerMultisite();
$this->registerDataSources();

$this->setupMultisiteIlluminateDB();

$this->registerFeatures();
}

Expand All @@ -45,6 +44,11 @@ public function registerServicesFromAura()
return service('repository.message');
});

$this->app->singleton(\Ushahidi\Core\Entity\ConfigRepository::class, function ($app) {
// Just return it from AuraDI
return service('repository.config');
});

$this->app->singleton(\Ushahidi\Core\Entity\ContactRepository::class, function ($app) {
// Just return it from AuraDI
return service('repository.contact');
Expand Down Expand Up @@ -121,64 +125,20 @@ public function registerFilesystem()
});
}

public function registerDataSources()
{
$this->app->register(\Ushahidi\App\DataSource\DataSourceServiceProvider::class);
}

protected function getDbConfig()
public function registerMultisite()
{
// Kohana injection
// DB config
$config = config('ohanzee-db');
$config = $config['default'];

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

return $config;
$this->app->register(\Ushahidi\App\Multisite\MultisiteServiceProvider::class);
}

protected function getClientUrl($config, $multisite)
{
$clientUrl = env('CLIENT_URL', false);

if (env("MULTISITE_DOMAIN", false)) {
try {
$clientUrl = $multisite()->getClientUrl();
} catch (Exception $e) {
}
}

// Or overwrite from config
if (!$clientUrl && $config['client_url']) {
$client_url = $config['client_url'];
}

return $clientUrl;
}

protected function setupMultisiteIlluminateDB()
public function registerDataSources()
{
$config = $this->getDbConfig();

$existing = config('database.connections.mysql');

config(['database.connections.mysql' => [
'database' => $config['connection']['database'],
'username' => $config['connection']['username'],
'password' => $config['connection']['password'],
'host' => $config['connection']['hostname'],
] + $existing]);
$this->app->register(\Ushahidi\App\DataSource\DataSourceServiceProvider::class);
}

public function registerFeatures()
{
$this->app->singleton('features', function ($app) {
return new \Ushahidi\App\Tools\Features(service('repository.config'));
return new \Ushahidi\App\Tools\Features($app[\Ushahidi\Core\Entity\ConfigRepository::class]);
});
}
}
96 changes: 12 additions & 84 deletions app/Providers/LumenAuraConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ protected function configureAuraServices(Container $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')
'mailer' => app('mailer')
]));

// Configure filesystem
Expand All @@ -31,27 +29,23 @@ protected function configureAuraServices(Container $di)
return app('filesystem')->disk()->getDriver();
});

$di->set('multisite', function () {
return app('multisite');
});

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

// Multisite db
$di->set('kohana.db.multisite', function () use ($di) {
$config = config('ohanzee-db');

return \Ohanzee\Database::instance('multisite', $config['multisite']);
});

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

$di->set('db.eloquent.connection', function () use ($di) {
return DB::connection();
});
$di->set('db.eloquent.resolver', $di->lazy(function () {
return app('db');
}));

// Abstract repository parameters
$di->set('db.ohanzee.resolver', $di->lazy(function () {
return app(\Ushahidi\App\Multisite\OhanzeeResolver::class);
}));

// Configure dispatcher
$di->setters[\Ushahidi\Core\Traits\Events\DispatchesEvents::class]['setDispatcher']
Expand All @@ -69,71 +63,5 @@ protected function injectAuraConfig(Container $di)
$di->set('ratelimiter.config', function () use ($di) {
return config('ratelimiter');
});

// Multisite db
// Move multisite enabled check to class and move to src/App
$di->set('site', function () use ($di) {
// @todo default to using the current domain
$site = '';

// 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');
if ($multisite) {
return $di->get('multisite')->getCdnPrefix();
}

return '';
});

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

protected function getDbConfig(\Aura\Di\Container $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, $multisite)
{
$clientUrl = env('CLIENT_URL', false);

if (env("MULTISITE_DOMAIN", false)) {
try {
$clientUrl = $multisite()->getClientUrl();
} catch (Exception $e) {
}
}

// Or overwrite from config
if (!$clientUrl && $config['client_url']) {
$client_url = $config['client_url'];
}

return $clientUrl;
}
}
Loading

0 comments on commit 0e61a62

Please sign in to comment.