Skip to content

Commit

Permalink
Merge pull request #59 from ngmy/upgrade-to-laravel-5.2.0
Browse files Browse the repository at this point in the history
Upgrade to Laravel 5.2.0
  • Loading branch information
ngmy authored Sep 4, 2016
2 parents 181611b + c14c9d5 commit 0ebc1bb
Show file tree
Hide file tree
Showing 36 changed files with 1,314 additions and 757 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ Webloyer has the following requirements:
composer create-project ngmy/webloyer
```

2. Give write permission to the `storage` directory, the `bootstrap/cache` directory, and the `.env` file for your web-server user by running the following command:
2. Give write permission to the `storage` directory and the `bootstrap/cache` directory for your web-server user by running the following command:

```
chmod -R 777 storage
chmod -R 777 bootstrap/cache
chmod 666 .env
```

3. Run the installer by using the Artisan `webloyer:install` command:
Expand Down
41 changes: 41 additions & 0 deletions app/Entities/Setting/MailSettingEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,64 @@
namespace App\Entities\Setting;

use App\Entities\Setting\AbstractSettingEntity;
use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SerializedName;

class MailSettingEntity extends AbstractSettingEntity
{
/**
* @Type("string")
* @Accessor(getter="getDriver",setter="setDriver")
*/
protected $driver;

/**
* @Type("array")
* @Accessor(getter="getFrom",setter="setFrom")
*/
protected $from;

/**
* @Type("string")
* @Accessor(getter="getSmtpHost",setter="setSmtpHost")
* @SerializedName("smtp_host")
*/
protected $smtpHost;

/**
* @Type("integer")
* @Accessor(getter="getSmtpPort",setter="setSmtpPort")
* @SerializedName("smtp_port")
*/
protected $smtpPort;

/**
* @Type("string")
* @Accessor(getter="getSmtpEncryption",setter="setSmtpEncryption")
* @SerializedName("smtp_encryption")
*/
protected $smtpEncryption;

/**
* @Type("string")
* @Accessor(getter="getSmtpUsername",setter="setSmtpUsername")
* @SerializedName("smtp_username")
*/
protected $smtpUsername;

/**
* @Type("string")
* @Accessor(getter="getSmtpPassword",setter="setSmtpPassword")
* @SerializedName("smtp_password")
*/
protected $smtpPassword;

/**
* @Type("string")
* @Accessor(getter="getSendmailPath",setter="setSendmailPath")
* @SerializedName("sendmail_path")
*/
protected $sendmailPath;

public function getDriver()
Expand Down
9 changes: 8 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace App\Exceptions;

use Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
Expand All @@ -13,7 +17,10 @@ class Handler extends ExceptionHandler
* @var array
*/
protected $dontReport = [
'Symfony\Component\HttpKernel\Exception\HttpException'
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

abstract class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Services\Form\Setting\MailSettingForm;
use App\Repositories\Setting\MailSettingInterface;
use App\Repositories\Setting\SettingInterface;

class SettingsController extends Controller
{
Expand All @@ -17,9 +17,9 @@ public function __construct()
$this->middleware('acl');
}

public function getEmail(MailSettingInterface $mailSettingRepository)
public function getEmail(SettingInterface $settingRepository)
{
$settings = $mailSettingRepository->all();
$settings = $settingRepository->byType('mail');

return view('settings.email')
->with('settings', $settings);
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Kernel extends HttpKernel
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
'App\Http\Middleware\VerifyCsrfToken',
'App\Http\Middleware\ApplySettings',
];

/**
Expand Down
52 changes: 52 additions & 0 deletions app/Http/Middleware/ApplySettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Http\Middleware;

use Closure;
use App\Repositories\Setting\SettingInterface;

class ApplySettings
{
protected $settingRepository;

public function __construct(SettingInterface $settingRepository)
{
$this->settingRepository = $settingRepository;
}

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$mailSettings = $this->settingRepository->byType('mail');

if (isset($mailSettings->attributes->getFrom()['address'])) {
$fromAddress = $mailSettings->attributes->getFrom()['address'];
} else {
$fromAddress = null;
}

if (isset($mailSettings->attributes->getFrom()['name'])) {
$fromName = $mailSettings->attributes->getFrom()['name'];
} else {
$fromName = null;
}

config(['mail.driver' => $mailSettings->attributes->getDriver()]);
config(['mail.from.address' => $fromAddress]);
config(['mail.from.name' => $fromName]);
config(['mail.host' => $mailSettings->attributes->getSmtpHost()]);
config(['mail.port' => $mailSettings->attributes->getSmtpPort()]);
config(['mail.encryption' => $mailSettings->attributes->getSmtpEncryption()]);
config(['mail.username' => $mailSettings->attributes->getSmtpUsername()]);
config(['mail.password' => $mailSettings->attributes->getSmtpPassword()]);
config(['mail.sendmail' => $mailSettings->attributes->getSendmailPath()]);

return $next($request);
}
}
24 changes: 12 additions & 12 deletions app/Http/breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@

Breadcrumbs::register('projects.show', function ($breadcrumbs, App\Models\Project $project) {
$breadcrumbs->parent('projects.index');
$breadcrumbs->push($project->name, route('projects.show', $project));
$breadcrumbs->push($project->name, route('projects.show', [$project]));
});

Breadcrumbs::register('projects.edit', function ($breadcrumbs, App\Models\Project $project) {
$breadcrumbs->parent('projects.show', $project);
$breadcrumbs->push('Edit', route('projects.edit', $project));
$breadcrumbs->push('Edit', route('projects.edit', [$project]));
});

Breadcrumbs::register('projects.deployments.index', function ($breadcrumbs, App\Models\Project $project) {
$breadcrumbs->parent('projects.show', $project);
$breadcrumbs->push('Deployments', route('projects.deployments.index', $project));
$breadcrumbs->push('Deployments', route('projects.deployments.index', [$project]));
});

Breadcrumbs::register('projects.deployments.show', function ($breadcrumbs, App\Models\Project $project, App\Models\Deployment $deployment) {
$breadcrumbs->parent('projects.deployments.index', $project);
$breadcrumbs->push($deployment->number, route('projects.deployments.show', $project, $deployment));
$breadcrumbs->push($deployment->number, route('projects.deployments.show', [$project, $deployment]));
});

Breadcrumbs::register('recipes.index', function ($breadcrumbs) {
Expand All @@ -40,12 +40,12 @@

Breadcrumbs::register('recipes.show', function ($breadcrumbs, App\Models\Recipe $recipe) {
$breadcrumbs->parent('recipes.index');
$breadcrumbs->push($recipe->name, route('recipes.show', $recipe));
$breadcrumbs->push($recipe->name, route('recipes.show', [$recipe]));
});

Breadcrumbs::register('recipes.edit', function ($breadcrumbs, App\Models\Recipe $recipe) {
$breadcrumbs->parent('recipes.show', $recipe);
$breadcrumbs->push('Edit', route('recipes.edit', $recipe));
$breadcrumbs->push('Edit', route('recipes.edit', [$recipe]));
});

Breadcrumbs::register('servers.index', function ($breadcrumbs) {
Expand All @@ -59,12 +59,12 @@

Breadcrumbs::register('servers.show', function ($breadcrumbs, App\Models\Server $server) {
$breadcrumbs->parent('servers.index');
$breadcrumbs->push($server->name, route('servers.show', $server));
$breadcrumbs->push($server->name, route('servers.show', [$server]));
});

Breadcrumbs::register('servers.edit', function ($breadcrumbs, App\Models\Server $server) {
$breadcrumbs->parent('servers.show', $server);
$breadcrumbs->push('Edit', route('servers.edit', $server));
$breadcrumbs->push('Edit', route('servers.edit', [$server]));
});

Breadcrumbs::register('users.index', function ($breadcrumbs) {
Expand All @@ -78,20 +78,20 @@

Breadcrumbs::register('users.show', function ($breadcrumbs, App\Models\User $user) {
$breadcrumbs->parent('users.index');
$breadcrumbs->push($user->name, route('users.show', $user));
$breadcrumbs->push($user->name, route('users.show', [$user]));
});

Breadcrumbs::register('users.edit', function ($breadcrumbs, App\Models\User $user) {
$breadcrumbs->parent('users.show', $user);
$breadcrumbs->push('Edit', route('users.edit', $user));
$breadcrumbs->push('Edit', route('users.edit', [$user]));
});

Breadcrumbs::register('users.password.change', function ($breadcrumbs, App\Models\User $user) {
$breadcrumbs->parent('users.show', $user);
$breadcrumbs->push('Change Password', route('users.password.change', $user));
$breadcrumbs->push('Change Password', route('users.password.change', [$user]));
});

Breadcrumbs::register('users.role.edit', function ($breadcrumbs, App\Models\User $user) {
$breadcrumbs->parent('users.show', $user);
$breadcrumbs->push('Edit Role', route('users.role.edit', $user));
$breadcrumbs->push('Edit Role', route('users.role.edit', [$user]));
});
2 changes: 1 addition & 1 deletion app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'protect_alias' => 'deployment',
], function () {
Route::resource('projects.deployments', 'DeploymentsController', [
'expect' => ['index', 'store', 'show']
'only' => ['index', 'store', 'show']
]);
});

Expand Down
51 changes: 31 additions & 20 deletions app/Jobs/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
use App\Jobs\Job;
use App\Repositories\Project\ProjectInterface;
use App\Repositories\Server\ServerInterface;
use App\Repositories\Setting\MailSettingInterface;
use App\Repositories\Setting\SettingInterface;
use App\Services\Notification\NotifierInterface;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Model;

use Symfony\Component\Process\ProcessBuilder;

class Deploy extends Job implements SelfHandling, ShouldQueue
class Deploy extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;

Expand All @@ -38,14 +37,14 @@ public function __construct(Model $deployment)
/**
* Execute the job.
*
* @param \App\Repositories\Project\ProjectInterface $projectRepository
* @param \App\Repositories\Server\ServerInterface $serverRepository
* @param \Symfony\Component\Process\ProcessBuilder $processBuilder
* @param \App\Services\Notification\NotifierInterface $notifier
* @param \App\Repositories\Setting\MailSettingInterface $mailSettingRepository
* @param \App\Repositories\Project\ProjectInterface $projectRepository
* @param \App\Repositories\Server\ServerInterface $serverRepository
* @param \Symfony\Component\Process\ProcessBuilder $processBuilder
* @param \App\Services\Notification\NotifierInterface $notifier
* @param \App\Repositories\Setting\SettingInterface $settingRepository
* @return void
*/
public function handle(ProjectInterface $projectRepository, ServerInterface $serverRepository, ProcessBuilder $processBuilder, NotifierInterface $notifier, MailSettingInterface $mailSettingRepository)
public function handle(ProjectInterface $projectRepository, ServerInterface $serverRepository, ProcessBuilder $processBuilder, NotifierInterface $notifier, SettingInterface $settingRepository)
{
$deployment = $this->deployment;
$project = $projectRepository->byId($deployment->project_id);
Expand Down Expand Up @@ -112,17 +111,29 @@ public function handle(ProjectInterface $projectRepository, ServerInterface $ser

// Notify
if (isset($project->email_notification_recipient)) {
$mailSettings = $mailSettingRepository->all();

config(['mail.driver' => $mailSettings->getDriver()]);
config(['mail.from.address' => $mailSettings->getFrom()['address']]);
config(['mail.from.name' => $mailSettings->getFrom()['name']]);
config(['mail.host' => $mailSettings->getSmtpHost()]);
config(['mail.port' => $mailSettings->getSmtpPort()]);
config(['mail.encryption' => $mailSettings->getSmtpEncryption()]);
config(['mail.username' => $mailSettings->getSmtpUsername()]);
config(['mail.password' => $mailSettings->getSmtpPassword()]);
config(['mail.sendmail' => $mailSettings->getSendmailPath()]);
$mailSettings = $settingRepository->byType('mail');

if (isset($mailSettings->attributes->getFrom()['address'])) {
$fromAddress = $mailSettings->attributes->getFrom()['address'];
} else {
$fromAddress = null;
}

if (isset($mailSettings->attributes->getFrom()['name'])) {
$fromName = $mailSettings->attributes->getFrom()['name'];
} else {
$fromName = null;
}

config(['mail.driver' => $mailSettings->attributes->getDriver()]);
config(['mail.from.address' => $fromAddress]);
config(['mail.from.name' => $fromName]);
config(['mail.host' => $mailSettings->attributes->getSmtpHost()]);
config(['mail.port' => $mailSettings->attributes->getSmtpPort()]);
config(['mail.encryption' => $mailSettings->attributes->getSmtpEncryption()]);
config(['mail.username' => $mailSettings->attributes->getSmtpUsername()]);
config(['mail.password' => $mailSettings->attributes->getSmtpPassword()]);
config(['mail.sendmail' => $mailSettings->attributes->getSendmailPath()]);

$deployment = $project->getDeploymentByNumber($deployment->number);

Expand Down
Loading

0 comments on commit 0ebc1bb

Please sign in to comment.