From 60421c11666cfbbe174814ea3b3f5385eae6d969 Mon Sep 17 00:00:00 2001 From: Stefan Ninic Date: Sat, 23 Jun 2018 15:45:50 +0000 Subject: [PATCH] Apply fixes from StyleCI [ci skip] [skip ci] --- routes.php | 75 +++++++++---------- src/Console/Commands/NewClient.php | 18 ++--- src/Events/LaravelDeployFailed.php | 17 ++--- src/Events/LaravelDeployFinished.php | 17 ++--- src/Events/LaravelDeployStarted.php | 17 ++--- src/Exceptions/InvalidClientException.php | 6 +- src/Exceptions/UnableToReadScriptFile.php | 6 +- src/Http/Controllers/BaseController.php | 9 +-- src/Http/Controllers/DeployController.php | 32 ++++---- .../Front/Ajax/ClientsController.php | 28 +++---- .../Front/Ajax/SettingsController.php | 74 ++++++++---------- .../Controllers/Front/DashboardController.php | 7 +- src/Http/Middleware/IsValidToken.php | 29 ++++--- src/Jobs/DeployJob.php | 58 +++++++------- src/LaravelDeployServiceProvider.php | 71 +++++++++--------- src/Models/Client.php | 23 +++--- src/config/laravel-deploy.php | 40 +++++----- ..._04_000000_create_deploy_sources_table.php | 26 +++---- ..._10_113144_rename_deploy_sources_table.php | 18 ++--- ...28_table_clients_rename_to_ldp_clients.php | 18 ++--- ...1443_table_ldp_clients_add_auto_deploy.php | 18 ++--- src/resources/lang/en/clients.php | 4 +- src/resources/lang/en/navbar.php | 4 +- src/resources/lang/en/settings.php | 4 +- 24 files changed, 285 insertions(+), 334 deletions(-) diff --git a/routes.php b/routes.php index 7af3d2b..a441d89 100644 --- a/routes.php +++ b/routes.php @@ -3,53 +3,49 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 12:18 AM + * Time: 12:18 AM. */ - use KgBot\LaravelDeploy\Http\Middleware\IsValidToken; -Route::group( [ - 'prefix' => config( 'laravel-deploy.routes.prefix' ), - 'middleware' => array_merge( [ IsValidToken::class ], config( 'laravel-deploy.routes.middleware' ) ), +Route::group([ + 'prefix' => config('laravel-deploy.routes.prefix'), + 'middleware' => array_merge([IsValidToken::class], config('laravel-deploy.routes.middleware')), 'namespace' => 'KgBot\LaravelDeploy\Http\Controllers', ], function () { + Route::any('deploy', 'DeployController@request')->name('laravel-deploy.deploy.request'); +}); - Route::any( 'deploy', 'DeployController@request' )->name( 'laravel-deploy.deploy.request' ); -} ); - -/** +/* * Front-end routes */ -Route::group( [ +Route::group([ - 'prefix' => config( 'laravel-deploy.routes.prefix' ) . '/dashboard', - 'middleware' => array_merge( [ 'web', 'auth' ], config( 'laravel-deploy.front.routes.middleware' ) ), - 'namespace' => config( 'laravel-deploy.front.routes.namespace' ), + 'prefix' => config('laravel-deploy.routes.prefix').'/dashboard', + 'middleware' => array_merge(['web', 'auth'], config('laravel-deploy.front.routes.middleware')), + 'namespace' => config('laravel-deploy.front.routes.namespace'), ], function () { + Route::get('', 'DashboardController@index')->name('laravel-deploy.dashboard'); +}); - Route::get( '', 'DashboardController@index' )->name( 'laravel-deploy.dashboard' ); -} ); - -/** +/* * Ajax routes */ -Route::group( [ +Route::group([ - 'prefix' => config( 'laravel-deploy.routes.prefix' ) . '/ajax', - 'middleware' => array_merge( [ 'web' ], config( 'laravel-deploy.front.routes.ajax.middleware' ) ), - 'namespace' => config( 'laravel-deploy.front.routes.ajax.namespace' ), + 'prefix' => config('laravel-deploy.routes.prefix').'/ajax', + 'middleware' => array_merge(['web'], config('laravel-deploy.front.routes.ajax.middleware')), + 'namespace' => config('laravel-deploy.front.routes.ajax.namespace'), ], function () { + Route::post('/clients/{client}/status', 'ClientsController@changeStatus') + ->name('laravel-deploy.ajax.clients.status'); - Route::post( '/clients/{client}/status', 'ClientsController@changeStatus' ) - ->name( 'laravel-deploy.ajax.clients.status' ); - - Route::post( '/clients/{client}/auto-deploy', 'ClientsController@changeAutoDeploy' ) - ->name( 'laravel-deploy.ajax.clients.auto_deploy' ); + Route::post('/clients/{client}/auto-deploy', 'ClientsController@changeAutoDeploy') + ->name('laravel-deploy.ajax.clients.auto_deploy'); - Route::resource( '/clients', 'ClientsController', [ + Route::resource('/clients', 'ClientsController', [ - 'only' => [ 'index', 'store', 'update', 'destroy' ], + 'only' => ['index', 'store', 'update', 'destroy'], 'names' => [ 'index' => 'laravel-deploy.ajax.clients.index', @@ -57,21 +53,20 @@ 'update' => 'laravel-deploy.ajax.clients.update', 'destroy' => 'laravel-deploy.ajax.clients.destroy', ], - ] ); + ]); - /** + /* * Settings routes */ - Route::group( [ 'prefix' => 'settings' ], function () { - - Route::get( 'last-log', 'SettingsController@lastLog' )->name( 'laravel-deploy.ajax.settings.last_log' ); - Route::get( 'logs', 'SettingsController@allLogs' )->name( 'laravel-deploy.ajax.settings.logs' ); - Route::get( 'index', 'SettingsController@index' )->name( 'laravel-deploy.ajax.settings.index' ); + Route::group(['prefix' => 'settings'], function () { + Route::get('last-log', 'SettingsController@lastLog')->name('laravel-deploy.ajax.settings.last_log'); + Route::get('logs', 'SettingsController@allLogs')->name('laravel-deploy.ajax.settings.logs'); + Route::get('index', 'SettingsController@index')->name('laravel-deploy.ajax.settings.index'); - /** + /* * Deployments routes */ - Route::post( 'deploy/now/{client}', 'SettingsController@deployNow' ) - ->name( 'laravel-deploy.ajax.settings.deployments.deploy_now' ); - } ); -} ); + Route::post('deploy/now/{client}', 'SettingsController@deployNow') + ->name('laravel-deploy.ajax.settings.deployments.deploy_now'); + }); +}); diff --git a/src/Console/Commands/NewClient.php b/src/Console/Commands/NewClient.php index 0f85c70..7de4d96 100644 --- a/src/Console/Commands/NewClient.php +++ b/src/Console/Commands/NewClient.php @@ -3,12 +3,11 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 1:29 AM + * Time: 1:29 AM. */ namespace KgBot\LaravelDeploy\Console\Commands; - use Illuminate\Console\Command; use KgBot\LaravelDeploy\Models\Client; @@ -45,14 +44,13 @@ public function __construct() */ public function handle() { + $name = $this->argument('name'); + $token = $this->argument('token'); + $script_source = $this->argument('script_source'); + $source = $this->argument('source'); - $name = $this->argument( 'name' ); - $token = $this->argument( 'token' ); - $script_source = $this->argument( 'script_source' ); - $source = $this->argument( 'source' ); - - $client = Client::create( compact( 'name', 'token', 'script_source', 'source' ) ); + $client = Client::create(compact('name', 'token', 'script_source', 'source')); - $this->info( 'New client created, token has been encrypted and it is: ' . $token ); + $this->info('New client created, token has been encrypted and it is: '.$token); } -} \ No newline at end of file +} diff --git a/src/Events/LaravelDeployFailed.php b/src/Events/LaravelDeployFailed.php index faa90e2..98c9cf0 100644 --- a/src/Events/LaravelDeployFailed.php +++ b/src/Events/LaravelDeployFailed.php @@ -3,17 +3,16 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 1:18 AM + * Time: 1:18 AM. */ namespace KgBot\LaravelDeploy\Events; - -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; use KgBot\LaravelDeploy\Models\Client; +use Illuminate\Broadcasting\PrivateChannel; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Broadcasting\InteractsWithSockets; class LaravelDeployFailed { @@ -27,9 +26,9 @@ class LaravelDeployFailed * * @return void */ - public function __construct( Client $client, string $message ) + public function __construct(Client $client, string $message) { - $this->client = $client; + $this->client = $client; $this->message = $message; } @@ -40,6 +39,6 @@ public function __construct( Client $client, string $message ) */ public function broadcastOn() { - return new PrivateChannel( config( 'laravel-deploy.events.channel', 'channel-name' ) ); + return new PrivateChannel(config('laravel-deploy.events.channel', 'channel-name')); } -} \ No newline at end of file +} diff --git a/src/Events/LaravelDeployFinished.php b/src/Events/LaravelDeployFinished.php index afcc791..2121597 100644 --- a/src/Events/LaravelDeployFinished.php +++ b/src/Events/LaravelDeployFinished.php @@ -3,17 +3,16 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 1:18 AM + * Time: 1:18 AM. */ namespace KgBot\LaravelDeploy\Events; - -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; use KgBot\LaravelDeploy\Models\Client; +use Illuminate\Broadcasting\PrivateChannel; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Broadcasting\InteractsWithSockets; class LaravelDeployFinished { @@ -27,9 +26,9 @@ class LaravelDeployFinished * * @return void */ - public function __construct( Client $client, $message ) + public function __construct(Client $client, $message) { - $this->client = $client; + $this->client = $client; $this->message = $message; } @@ -40,6 +39,6 @@ public function __construct( Client $client, $message ) */ public function broadcastOn() { - return new PrivateChannel( config( 'laravel-deploy.events.channel', 'channel-name' ) ); + return new PrivateChannel(config('laravel-deploy.events.channel', 'channel-name')); } -} \ No newline at end of file +} diff --git a/src/Events/LaravelDeployStarted.php b/src/Events/LaravelDeployStarted.php index 5198ae7..2c8f12f 100644 --- a/src/Events/LaravelDeployStarted.php +++ b/src/Events/LaravelDeployStarted.php @@ -3,17 +3,16 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 1:18 AM + * Time: 1:18 AM. */ namespace KgBot\LaravelDeploy\Events; - -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; use KgBot\LaravelDeploy\Models\Client; +use Illuminate\Broadcasting\PrivateChannel; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Broadcasting\InteractsWithSockets; class LaravelDeployStarted { @@ -27,9 +26,9 @@ class LaravelDeployStarted * * @return void */ - public function __construct( Client $client, string $command ) + public function __construct(Client $client, string $command) { - $this->client = $client; + $this->client = $client; $this->command = $command; } @@ -40,6 +39,6 @@ public function __construct( Client $client, string $command ) */ public function broadcastOn() { - return new PrivateChannel( config( 'laravel-deploy.events.channel', 'channel-name' ) ); + return new PrivateChannel(config('laravel-deploy.events.channel', 'channel-name')); } -} \ No newline at end of file +} diff --git a/src/Exceptions/InvalidClientException.php b/src/Exceptions/InvalidClientException.php index 1304084..46df42c 100644 --- a/src/Exceptions/InvalidClientException.php +++ b/src/Exceptions/InvalidClientException.php @@ -3,15 +3,13 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 12:32 AM + * Time: 12:32 AM. */ namespace KgBot\LaravelDeploy\Exceptions; use Exception; - class InvalidClientException extends Exception { - -} \ No newline at end of file +} diff --git a/src/Exceptions/UnableToReadScriptFile.php b/src/Exceptions/UnableToReadScriptFile.php index 9b3b3a7..54303d0 100644 --- a/src/Exceptions/UnableToReadScriptFile.php +++ b/src/Exceptions/UnableToReadScriptFile.php @@ -3,15 +3,13 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 12:55 AM + * Time: 12:55 AM. */ namespace KgBot\LaravelDeploy\Exceptions; use Exception; - class UnableToReadScriptFile extends Exception { - -} \ No newline at end of file +} diff --git a/src/Http/Controllers/BaseController.php b/src/Http/Controllers/BaseController.php index 9d8e07a..e764420 100644 --- a/src/Http/Controllers/BaseController.php +++ b/src/Http/Controllers/BaseController.php @@ -3,18 +3,17 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 12:44 AM + * Time: 12:44 AM. */ namespace KgBot\LaravelDeploy\Http\Controllers; - -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; +use Illuminate\Routing\Controller; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; -use Illuminate\Routing\Controller; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; class BaseController extends Controller { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; -} \ No newline at end of file +} diff --git a/src/Http/Controllers/DeployController.php b/src/Http/Controllers/DeployController.php index 3625b7c..5dd281a 100644 --- a/src/Http/Controllers/DeployController.php +++ b/src/Http/Controllers/DeployController.php @@ -3,38 +3,36 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 12:40 AM + * Time: 12:40 AM. */ namespace KgBot\LaravelDeploy\Http\Controllers; use Illuminate\Http\Request; -use KgBot\LaravelDeploy\Exceptions\UnableToReadScriptFile; -use KgBot\LaravelDeploy\Jobs\DeployJob; use KgBot\LaravelDeploy\Models\Client; +use KgBot\LaravelDeploy\Jobs\DeployJob; +use KgBot\LaravelDeploy\Exceptions\UnableToReadScriptFile; class DeployController extends BaseController { - public function request( Request $request ) + public function request(Request $request) { - $client = Client::where( [ - - [ 'token', $request->get( '_token' ) ], - [ 'active', true ], - [ 'auto_deploy' => true ], - ] )->first(); + $client = Client::where([ - $filename = $client->script_source; - $script_file = base_path( $filename ); + ['token', $request->get('_token')], + ['active', true], + ['auto_deploy' => true], + ])->first(); - if ( !file_exists( $script_file ) ) { + $filename = $client->script_source; + $script_file = base_path($filename); + if (! file_exists($script_file)) { throw new UnableToReadScriptFile(); - } - dispatch( new DeployJob( $client, $script_file ) )->onQueue( config( 'laravel-deploy.queue', 'default' ) ); + dispatch(new DeployJob($client, $script_file))->onQueue(config('laravel-deploy.queue', 'default')); - return response()->json( 'success' ); + return response()->json('success'); } -} \ No newline at end of file +} diff --git a/src/Http/Controllers/Front/Ajax/ClientsController.php b/src/Http/Controllers/Front/Ajax/ClientsController.php index ee645a2..9ec5ed6 100644 --- a/src/Http/Controllers/Front/Ajax/ClientsController.php +++ b/src/Http/Controllers/Front/Ajax/ClientsController.php @@ -2,9 +2,9 @@ namespace KgBot\LaravelDeploy\Http\Controllers\Front\Ajax; +use KgBot\LaravelDeploy\Models\Client; use KgBot\LaravelDeploy\Http\Controllers\BaseController; use KgBot\LaravelDeploy\Http\Requests\Clients\ClientRequest; -use KgBot\LaravelDeploy\Models\Client; class ClientsController extends BaseController { @@ -17,7 +17,7 @@ public function index() { $clients = Client::all(); - return response()->json( compact( 'clients' ) ); + return response()->json(compact('clients')); } /** @@ -27,11 +27,11 @@ public function index() * * @return \Illuminate\Http\Response */ - public function store( ClientRequest $request ) + public function store(ClientRequest $request) { - $client = Client::create( $request->all() ); + $client = Client::create($request->all()); - return response()->json( compact( 'client' ) ); + return response()->json(compact('client')); } /** @@ -42,11 +42,11 @@ public function store( ClientRequest $request ) * * @return \Illuminate\Http\Response */ - public function update( ClientRequest $request, Client $client ) + public function update(ClientRequest $request, Client $client) { - $client->update( $request->all() ); + $client->update($request->all()); - return response()->json( compact( 'client' ) ); + return response()->json(compact('client')); } /** @@ -56,24 +56,24 @@ public function update( ClientRequest $request, Client $client ) * * @return \Illuminate\Http\Response */ - public function destroy( Client $client ) + public function destroy(Client $client) { $client->delete(); - return response()->json( 'success' ); + return response()->json('success'); } - public function changeStatus( Client $client ) + public function changeStatus(Client $client) { $client->changeStatus(); - return response()->json( 'success' ); + return response()->json('success'); } - public function changeAutoDeploy( Client $client ) + public function changeAutoDeploy(Client $client) { $client->changeAutoDeploy(); - return response()->json( 'success' ); + return response()->json('success'); } } diff --git a/src/Http/Controllers/Front/Ajax/SettingsController.php b/src/Http/Controllers/Front/Ajax/SettingsController.php index 46c7269..5df3f5d 100644 --- a/src/Http/Controllers/Front/Ajax/SettingsController.php +++ b/src/Http/Controllers/Front/Ajax/SettingsController.php @@ -3,95 +3,81 @@ namespace KgBot\LaravelDeploy\Http\Controllers\Front\Ajax; use Dubture\Monolog\Reader\LogReader; -use KgBot\LaravelDeploy\Http\Controllers\BaseController; -use KgBot\LaravelDeploy\Jobs\DeployJob; use KgBot\LaravelDeploy\Models\Client; +use KgBot\LaravelDeploy\Jobs\DeployJob; +use KgBot\LaravelDeploy\Http\Controllers\BaseController; class SettingsController extends BaseController { /** - * Return last deploy log + * Return last deploy log. * * @return \Illuminate\Http\JsonResponse */ public function lastLog() { + $log_file_name = config('laravel-deploy.log_file_name', 'laravel-log'); + $path = storage_path('logs/'.$log_file_name); - $log_file_name = config( 'laravel-deploy.log_file_name', 'laravel-log' ); - $path = storage_path( 'logs/' . $log_file_name ); - - if ( file_exists( $path ) ) { - - $reader = new LogReader( $path ); + if (file_exists($path)) { + $reader = new LogReader($path); $pattern = '/\[(?P.*)\] (?P[\w-\s]+).(?P\w+): (?P[^\[\{]+) (?P[\[\{].*[\]\}]) (?P[\[\{].*[\]\}])/'; - $reader->getParser()->registerPattern( 'newPatternName', $pattern ); - $reader->setPattern( 'newPatternName' ); - + $reader->getParser()->registerPattern('newPatternName', $pattern); + $reader->setPattern('newPatternName'); } else { - - return response()->json( 'Log file path does not exist, check your configuration and try again.', 404 ); + return response()->json('Log file path does not exist, check your configuration and try again.', 404); } - if ( count( $reader ) ) { - - return response()->json( [ 'log' => $reader[ count( $reader ) - 2 ] ] ); - + if (count($reader)) { + return response()->json(['log' => $reader[count($reader) - 2]]); } else { - - return response()->json( 'Log is empty, deploy something!!!', 404 ); + return response()->json('Log is empty, deploy something!!!', 404); } } /** - * Return collection of all logs + * Return collection of all logs. * * @return \Illuminate\Http\JsonResponse */ public function allLogs() { - $log_file_name = config( 'laravel-deploy.log_file_name', 'laravel-log' ); - $path = storage_path( 'logs/' . $log_file_name ); - - if ( file_exists( $path ) ) { + $log_file_name = config('laravel-deploy.log_file_name', 'laravel-log'); + $path = storage_path('logs/'.$log_file_name); - $reader = new LogReader( $path ); + if (file_exists($path)) { + $reader = new LogReader($path); $pattern = '/\[(?P.*)\] (?P[\w-\s]+).(?P\w+): (?P[^\[\{]+) (?P[\[\{].*[\]\}]) (?P[\[\{].*[\]\}])/'; - $reader->getParser()->registerPattern( 'newPatternName', $pattern ); - $reader->setPattern( 'newPatternName' ); - + $reader->getParser()->registerPattern('newPatternName', $pattern); + $reader->setPattern('newPatternName'); } else { - - return response()->json( 'Log file path does not exist, check your configuration and try again.', 404 ); + return response()->json('Log file path does not exist, check your configuration and try again.', 404); } - if ( count( $reader ) ) { - - return response()->json( [ 'logs' => collect( $reader ) ] ); - + if (count($reader)) { + return response()->json(['logs' => collect($reader)]); } else { - - return response()->json( 'Log is empty, deploy something!!!', 404 ); + return response()->json('Log is empty, deploy something!!!', 404); } } - public function deployNow( Client $client ) + public function deployNow(Client $client) { + dispatch(new DeployJob($client, base_path($client->script_source))); - dispatch( new DeployJob( $client, base_path( $client->script_source ) ) ); - - return response()->json( 'success' ); + return response()->json('success'); } public function index() { - $clients = Client::Active()->get(); + $clients = Client::Active()->get(); $settings = [ - 'quick_deploy' => config( 'laravel-deploy.run_deploy' ), + 'quick_deploy' => config('laravel-deploy.run_deploy'), ]; - return response()->json( compact( 'clients', 'settings' ) ); + return response()->json(compact('clients', 'settings')); } } diff --git a/src/Http/Controllers/Front/DashboardController.php b/src/Http/Controllers/Front/DashboardController.php index cdf71d8..86c9c75 100644 --- a/src/Http/Controllers/Front/DashboardController.php +++ b/src/Http/Controllers/Front/DashboardController.php @@ -3,7 +3,7 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 12:40 AM + * Time: 12:40 AM. */ namespace KgBot\LaravelDeploy\Http\Controllers\Front; @@ -12,9 +12,8 @@ class DashboardController extends BaseController { - public function index() { - return view( 'laravel-deploy::dashboard' ); + return view('laravel-deploy::dashboard'); } -} \ No newline at end of file +} diff --git a/src/Http/Middleware/IsValidToken.php b/src/Http/Middleware/IsValidToken.php index dfcc845..0c0832d 100644 --- a/src/Http/Middleware/IsValidToken.php +++ b/src/Http/Middleware/IsValidToken.php @@ -3,16 +3,15 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 12:25 AM + * Time: 12:25 AM. */ namespace KgBot\LaravelDeploy\Http\Middleware; use Closure; -use Illuminate\Cookie\Middleware\EncryptCookies as Middleware; -use KgBot\LaravelDeploy\Exceptions\InvalidClientException; use KgBot\LaravelDeploy\Models\Client; - +use KgBot\LaravelDeploy\Exceptions\InvalidClientException; +use Illuminate\Cookie\Middleware\EncryptCookies as Middleware; class IsValidToken extends Middleware { @@ -24,24 +23,22 @@ class IsValidToken extends Middleware * * @return mixed */ - public function handle( $request, Closure $next ) + public function handle($request, Closure $next) { - $token = $request->get( '_token' ); - - if ( $token ) { - - $client = Client::where( [ + $token = $request->get('_token'); - [ 'token', $token ], - [ 'active', true ], - ] )->first(); + if ($token) { + $client = Client::where([ - if ( !$client ) { + ['token', $token], + ['active', true], + ])->first(); + if (! $client) { throw new InvalidClientException(); } - return $next( $request ); + return $next($request); } } -} \ No newline at end of file +} diff --git a/src/Jobs/DeployJob.php b/src/Jobs/DeployJob.php index 81b8dd1..7743ed1 100644 --- a/src/Jobs/DeployJob.php +++ b/src/Jobs/DeployJob.php @@ -2,38 +2,37 @@ namespace KgBot\LaravelDeploy\Jobs; +use Monolog\Logger; use Illuminate\Bus\Queueable; +use Monolog\Handler\StreamHandler; +use Illuminate\Queue\SerializesModels; +use KgBot\LaravelDeploy\Models\Client; +use Symfony\Component\Process\Process; +use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; -use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Queue\SerializesModels; use KgBot\LaravelDeploy\Events\LaravelDeployFailed; -use KgBot\LaravelDeploy\Events\LaravelDeployFinished; use KgBot\LaravelDeploy\Events\LaravelDeployStarted; -use KgBot\LaravelDeploy\Models\Client; -use Monolog\Handler\StreamHandler; -use Monolog\Logger; -use Symfony\Component\Process\Process; +use KgBot\LaravelDeploy\Events\LaravelDeployFinished; class DeployJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public $timeout = 240; - public $tries = 1; + public $tries = 1; public $client; public $script_file; - /** * Create a new job instance. * * @return void */ - public function __construct( Client $client, string $script_file ) + public function __construct(Client $client, string $script_file) { - $this->client = $client; + $this->client = $client; $this->script_file = $script_file; } @@ -44,33 +43,30 @@ public function __construct( Client $client, string $script_file ) */ public function handle() { - $logger = new Logger( 'laravel-deploy-logger' ); + $logger = new Logger('laravel-deploy-logger'); - $log_file_name = config( 'laravel-deploy.log_file_name', 'laravel-log' ); - $logger->pushHandler( new StreamHandler( storage_path( '/logs/' . $log_file_name ), Logger::DEBUG ) ); + $log_file_name = config('laravel-deploy.log_file_name', 'laravel-log'); + $logger->pushHandler(new StreamHandler(storage_path('/logs/'.$log_file_name), Logger::DEBUG)); - $command = 'echo ' . config( 'laravel-deploy.user.password' ); - $command .= ' | sudo -S -u ' . config( 'laravel-deploy.user.username' ); - $command .= ' sh ' . $this->script_file; + $command = 'echo '.config('laravel-deploy.user.password'); + $command .= ' | sudo -S -u '.config('laravel-deploy.user.username'); + $command .= ' sh '.$this->script_file; - $process = new Process( $command ); - event( new LaravelDeployStarted( $this->client, $command ) ); + $process = new Process($command); + event(new LaravelDeployStarted($this->client, $command)); $process->run(); try { - - $logger->info( $process->getOutput(), [ - 'client' => json_encode( $this->client ), + $logger->info($process->getOutput(), [ + 'client' => json_encode($this->client), 'script' => $this->script_file, - ] ); - event( new LaravelDeployFinished( $this->client, $process->getOutput() ) ); - - } catch ( \Exception $exception ) { - - $logger->critical( $process->getOutput(), [ - 'client' => json_encode( $this->client ), + ]); + event(new LaravelDeployFinished($this->client, $process->getOutput())); + } catch (\Exception $exception) { + $logger->critical($process->getOutput(), [ + 'client' => json_encode($this->client), 'script' => $this->script_file, - ] ); - event( new LaravelDeployFailed( $this->client, $exception->getMessage() ) ); + ]); + event(new LaravelDeployFailed($this->client, $exception->getMessage())); } } } diff --git a/src/LaravelDeployServiceProvider.php b/src/LaravelDeployServiceProvider.php index d6bd9c9..b636b10 100644 --- a/src/LaravelDeployServiceProvider.php +++ b/src/LaravelDeployServiceProvider.php @@ -3,12 +3,11 @@ * Created by PhpStorm. * User: kgbot * Date: 6/3/18 - * Time: 11:48 PM + * Time: 11:48 PM. */ namespace KgBot\LaravelDeploy; - use ExportLocalization; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; @@ -18,73 +17,71 @@ class LaravelDeployServiceProvider extends ServiceProvider { public function register() { - } public function boot() { - View::composer( 'laravel-deploy::dashboard', function ( $view ) { - - return $view->with( [ + View::composer('laravel-deploy::dashboard', function ($view) { + return $view->with([ 'user' => auth()->user(), 'messages' => ExportLocalization::export()->toFlat(), - ] ); - } ); + ]); + }); - if ( $this->app->runningInConsole() ) { - $this->commands( [ + if ($this->app->runningInConsole()) { + $this->commands([ NewClient::class, - ] ); + ]); } - /** + /* * Config */ $this->mergeConfigFrom( - __DIR__ . '//config/laravel-deploy.php', 'laravel-deploy' + __DIR__.'//config/laravel-deploy.php', 'laravel-deploy' ); - $this->publishes( [ - __DIR__ . '/config/laravel-deploy.php' => config_path( 'laravel-deploy.php' ), - ], 'config' ); + $this->publishes([ + __DIR__.'/config/laravel-deploy.php' => config_path('laravel-deploy.php'), + ], 'config'); - /** + /* * Migrations */ - $this->publishes( [ - __DIR__ . '/database/migrations/' => database_path( 'migrations' ), - ], 'migrations' ); + $this->publishes([ + __DIR__.'/database/migrations/' => database_path('migrations'), + ], 'migrations'); - /** + /* * Routes */ - $this->loadRoutesFrom( __DIR__ . '/../routes.php' ); + $this->loadRoutesFrom(__DIR__.'/../routes.php'); - /** + /* * Assets */ - $this->publishes( [ + $this->publishes([ - __DIR__ . '/resources/assets/' => resource_path( 'assets/vendor/laravel-deploy' ), - ], 'assets' ); + __DIR__.'/resources/assets/' => resource_path('assets/vendor/laravel-deploy'), + ], 'assets'); - /** + /* * Localization */ - $this->loadTranslationsFrom( __DIR__ . '/resource/lang', 'laravel-deploy' ); - $this->publishes( [ + $this->loadTranslationsFrom(__DIR__.'/resource/lang', 'laravel-deploy'); + $this->publishes([ - __DIR__ . '/resources/lang' => resource_path( 'lang/vendor/laravel-deploy' ), - ], 'lang' ); + __DIR__.'/resources/lang' => resource_path('lang/vendor/laravel-deploy'), + ], 'lang'); - /** + /* * Views */ - $this->loadViewsFrom( __DIR__ . '/resources/views', 'laravel-deploy' ); + $this->loadViewsFrom(__DIR__.'/resources/views', 'laravel-deploy'); - $this->publishes( [ + $this->publishes([ - __DIR__ . '/resources/views' => resource_path( 'views/vendor/laravel-deploy' ), - ], 'views' ); + __DIR__.'/resources/views' => resource_path('views/vendor/laravel-deploy'), + ], 'views'); } -} \ No newline at end of file +} diff --git a/src/Models/Client.php b/src/Models/Client.php index ee2f370..37df8f2 100644 --- a/src/Models/Client.php +++ b/src/Models/Client.php @@ -3,12 +3,11 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 12:29 AM + * Time: 12:29 AM. */ namespace KgBot\LaravelDeploy\Models; - use Illuminate\Database\Eloquent\Model; class Client extends Model @@ -31,29 +30,29 @@ class Client extends Model 'auto_deploy' => 'boolean', ]; - public function setTokenAttribute( $value ) + public function setTokenAttribute($value) { - $this->attributes[ 'token' ] = bcrypt( $value ); + $this->attributes['token'] = bcrypt($value); } public function changeStatus() { - $this->update( [ + $this->update([ - 'active' => !$this->active, - ] ); + 'active' => ! $this->active, + ]); } public function changeAutoDeploy() { - $this->update( [ + $this->update([ - 'auto_deploy' => !$this->auto_deploy, - ] ); + 'auto_deploy' => ! $this->auto_deploy, + ]); } public function scopeActive() { - return $this->where( 'active', true ); + return $this->where('active', true); } -} \ No newline at end of file +} diff --git a/src/config/laravel-deploy.php b/src/config/laravel-deploy.php index b4d67e4..759a5e7 100644 --- a/src/config/laravel-deploy.php +++ b/src/config/laravel-deploy.php @@ -3,61 +3,61 @@ * Created by PhpStorm. * User: kgbot * Date: 6/4/18 - * Time: 1:37 AM + * Time: 1:37 AM. */ return [ 'routes' => [ - /** + /* * Route prefix, example of route http://localhost/laravel-deploy/deploy?_token=################# * */ - 'prefix' => env( 'LARAVEL_DEPLOY_PREFIX', 'laravel-deploy' ), + 'prefix' => env('LARAVEL_DEPLOY_PREFIX', 'laravel-deploy'), - /** + /* * Middleware used on webhook routes, default middleware is KgBot\LaravelDeploy\Http\Middleware\IsTokenValid * * You can add more middleware with .env directive, example LARAVEL_DEPLOY_MIDDLEWARE=webhook,auth:api, etc. * * Don't use space in .env directive after , */ - 'middleware' => ( env( 'LARAVEL_DEPLOY_MIDDLEWARE' ) ) ? explode( ',', env( 'LARAVEL_DEPLOY_MIDDLEWARE' ) ) + 'middleware' => (env('LARAVEL_DEPLOY_MIDDLEWARE')) ? explode(',', env('LARAVEL_DEPLOY_MIDDLEWARE')) : [], ], 'events' => [ - /** + /* * This package emits some events before and after it run's deployment script * * Here you can change channel on which events will be broadcast */ - 'channel' => env( 'LARAVEL_DEPLOY_EVENTS_CHANNEL', '' ), + 'channel' => env('LARAVEL_DEPLOY_EVENTS_CHANNEL', ''), ], - /** + /* * This packages is doing all of it's work in a Job and here you change queue on which it will execute jobs */ - 'queue' => env( 'LARAVEL_DEPLOY_QUEUE', 'default' ), + 'queue' => env('LARAVEL_DEPLOY_QUEUE', 'default'), - /** + /* * Detailed description is provided inside a README.md file * * Here you set your default server user and password which will be used to run deploy script */ 'user' => [ - 'username' => env( 'LARAVEL_DEPLOY_USERNAME', 'www-data' ), - 'password' => env( 'LARAVEL_DEPLOY_PASSWORD', '' ), + 'username' => env('LARAVEL_DEPLOY_USERNAME', 'www-data'), + 'password' => env('LARAVEL_DEPLOY_PASSWORD', ''), ], - /** + /* * Name of the log file where deployment logs will be saved */ - 'log_file_name' => env( 'LARAVEL_DEPLOY_LOG_FILE_NAME', 'laravel-deploy' ), + 'log_file_name' => env('LARAVEL_DEPLOY_LOG_FILE_NAME', 'laravel-deploy'), - /** + /* * Everything related to front-end part of package should go here */ 'front' => [ @@ -66,20 +66,20 @@ 'routes' => [ - 'middleware' => ( env( 'LARAVEL_DEPLOY_FRONT_MIDDLEWARE' ) ) ? - explode( ',', env( 'LARAVEL_DEPLOY_FRONT_MIDDLEWARE' ) ) : + 'middleware' => (env('LARAVEL_DEPLOY_FRONT_MIDDLEWARE')) ? + explode(',', env('LARAVEL_DEPLOY_FRONT_MIDDLEWARE')) : [], 'namespace' => 'KgBot\LaravelDeploy\Http\Controllers\Front', 'ajax' => [ - 'middleware' => ( env( 'LARAVEL_DEPLOY_FRONT_AJAX_MIDDLEWARE' ) ) ? - explode( ',', env( 'LARAVEL_DEPLOY_FRONT_AJAX_MIDDLEWARE' ) ) : + 'middleware' => (env('LARAVEL_DEPLOY_FRONT_AJAX_MIDDLEWARE')) ? + explode(',', env('LARAVEL_DEPLOY_FRONT_AJAX_MIDDLEWARE')) : [], 'namespace' => 'KgBot\LaravelDeploy\Http\Controllers\Front\Ajax', ], ], ], -]; \ No newline at end of file +]; diff --git a/src/database/migrations/2018_06_04_000000_create_deploy_sources_table.php b/src/database/migrations/2018_06_04_000000_create_deploy_sources_table.php index 5279cc3..1bf1891 100644 --- a/src/database/migrations/2018_06_04_000000_create_deploy_sources_table.php +++ b/src/database/migrations/2018_06_04_000000_create_deploy_sources_table.php @@ -1,14 +1,14 @@ increments( 'id' ); + Schema::create('deploy_sources', function (Blueprint $table) { + $table->increments('id'); $table->timestamps(); - $table->string( 'source' ); - $table->boolean( 'active' )->default( true ); - $table->string( 'token', 512 )->unique(); - $table->string( 'name' ); - $table->string( 'script_source' ); - } ); + $table->string('source'); + $table->boolean('active')->default(true); + $table->string('token', 512)->unique(); + $table->string('name'); + $table->string('script_source'); + }); } /** @@ -38,6 +38,6 @@ public function up() */ public function down() { - Schema::dropIfExists( 'deploy_sources' ); + Schema::dropIfExists('deploy_sources'); } -} \ No newline at end of file +} diff --git a/src/database/migrations/2018_06_10_113144_rename_deploy_sources_table.php b/src/database/migrations/2018_06_10_113144_rename_deploy_sources_table.php index 0fca87f..8c5a5d7 100644 --- a/src/database/migrations/2018_06_10_113144_rename_deploy_sources_table.php +++ b/src/database/migrations/2018_06_10_113144_rename_deploy_sources_table.php @@ -1,8 +1,8 @@ rename( 'clients' ); - } ); + Schema::table('deploy_sources', function (Blueprint $table) { + $table->rename('clients'); + }); } /** @@ -26,9 +25,8 @@ public function up() */ public function down() { - Schema::table( 'clients', function ( Blueprint $table ) { - - $table->rename( 'deploy_sources' ); - } ); + Schema::table('clients', function (Blueprint $table) { + $table->rename('deploy_sources'); + }); } } diff --git a/src/database/migrations/2018_06_10_231128_table_clients_rename_to_ldp_clients.php b/src/database/migrations/2018_06_10_231128_table_clients_rename_to_ldp_clients.php index 87e7de9..890a493 100644 --- a/src/database/migrations/2018_06_10_231128_table_clients_rename_to_ldp_clients.php +++ b/src/database/migrations/2018_06_10_231128_table_clients_rename_to_ldp_clients.php @@ -1,8 +1,8 @@ rename( 'ldp_clients' ); - } ); + Schema::table('clients', function (Blueprint $table) { + $table->rename('ldp_clients'); + }); } /** @@ -26,9 +25,8 @@ public function up() */ public function down() { - Schema::table( 'ldp_clients', function ( Blueprint $table ) { - - $table->rename( 'clients' ); - } ); + Schema::table('ldp_clients', function (Blueprint $table) { + $table->rename('clients'); + }); } } diff --git a/src/database/migrations/2018_06_10_231443_table_ldp_clients_add_auto_deploy.php b/src/database/migrations/2018_06_10_231443_table_ldp_clients_add_auto_deploy.php index 105862a..6edff10 100644 --- a/src/database/migrations/2018_06_10_231443_table_ldp_clients_add_auto_deploy.php +++ b/src/database/migrations/2018_06_10_231443_table_ldp_clients_add_auto_deploy.php @@ -1,8 +1,8 @@ boolean( 'auto_deploy' )->default( true ); - } ); + Schema::table('ldp_clients', function (Blueprint $table) { + $table->boolean('auto_deploy')->default(true); + }); } /** @@ -26,9 +25,8 @@ public function up() */ public function down() { - Schema::table( 'ldp_clients', function ( Blueprint $table ) { - - $table->dropColumn( 'auto_deploy' ); - } ); + Schema::table('ldp_clients', function (Blueprint $table) { + $table->dropColumn('auto_deploy'); + }); } } diff --git a/src/resources/lang/en/clients.php b/src/resources/lang/en/clients.php index 8a4dc28..4b397e4 100644 --- a/src/resources/lang/en/clients.php +++ b/src/resources/lang/en/clients.php @@ -3,7 +3,7 @@ * Created by PhpStorm. * User: kgbot * Date: 6/10/18 - * Time: 1:35 PM + * Time: 1:35 PM. */ return [ @@ -46,4 +46,4 @@ 'token' => 'eg. test123', ], ], -]; \ No newline at end of file +]; diff --git a/src/resources/lang/en/navbar.php b/src/resources/lang/en/navbar.php index 25fd62c..8218aa5 100644 --- a/src/resources/lang/en/navbar.php +++ b/src/resources/lang/en/navbar.php @@ -3,11 +3,11 @@ * Created by PhpStorm. * User: kgbot * Date: 6/10/18 - * Time: 12:12 AM + * Time: 12:12 AM. */ return [ 'clients' => 'Clients', 'settings' => 'Settings', -]; \ No newline at end of file +]; diff --git a/src/resources/lang/en/settings.php b/src/resources/lang/en/settings.php index 6c58653..d8d8663 100644 --- a/src/resources/lang/en/settings.php +++ b/src/resources/lang/en/settings.php @@ -3,7 +3,7 @@ * Created by PhpStorm. * User: kgbot * Date: 6/10/18 - * Time: 11:03 PM + * Time: 11:03 PM. */ return [ @@ -47,4 +47,4 @@ ], ], ], -]; \ No newline at end of file +];