From 8cb0021b9f3e1bdb67b5f556d7ea4d03113780be Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Mon, 9 Dec 2019 15:26:30 -0500 Subject: [PATCH] Use PhpExecutableFinder() closes #457 #458 (#460) --- .../Controllers/Admin/DashboardController.php | 13 ++++++++---- .../Admin/MaintenanceController.php | 9 +-------- app/Providers/AppServiceProvider.php | 2 +- app/Services/CronService.php | 20 ++++++++++++++++++- .../views/admin/dashboard/index.blade.php | 6 ++++++ 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 79495ea40..510e443b5 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -7,6 +7,7 @@ use App\Repositories\NewsRepository; use App\Repositories\PirepRepository; use App\Repositories\UserRepository; +use App\Services\CronService; use App\Services\NewsService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -15,6 +16,7 @@ class DashboardController extends Controller { + private $cronSvc; private $kvpRepo; private $newsRepo; private $newsSvc; @@ -24,6 +26,7 @@ class DashboardController extends Controller /** * DashboardController constructor. * + * @param CronService $cronSvc * @param KvpRepository $kvpRepo * @param NewsRepository $newsRepo * @param NewsService $newsSvc @@ -31,12 +34,14 @@ class DashboardController extends Controller * @param UserRepository $userRepo */ public function __construct( + CronService $cronSvc, KvpRepository $kvpRepo, NewsRepository $newsRepo, NewsService $newsSvc, PirepRepository $pirepRepo, UserRepository $userRepo ) { + $this->cronSvc = $cronSvc; $this->kvpRepo = $kvpRepo; $this->newsRepo = $newsRepo; $this->newsSvc = $newsSvc; @@ -79,10 +84,10 @@ public function index(Request $request) $this->checkNewVersion(); return view('admin.dashboard.index', [ - 'news' => $this->newsRepo->getLatest(), -// 'installer_enabled' => $installerEnabled, - 'pending_pireps' => $this->pirepRepo->getPendingCount(), - 'pending_users' => $this->userRepo->getPendingCount(), + 'news' => $this->newsRepo->getLatest(), + 'pending_pireps' => $this->pirepRepo->getPendingCount(), + 'pending_users' => $this->userRepo->getPendingCount(), + 'cron_problem_exists' => $this->cronSvc->cronProblemExists(), ]); } diff --git a/app/Http/Controllers/Admin/MaintenanceController.php b/app/Http/Controllers/Admin/MaintenanceController.php index 033500b43..8f1470e8f 100644 --- a/app/Http/Controllers/Admin/MaintenanceController.php +++ b/app/Http/Controllers/Admin/MaintenanceController.php @@ -19,15 +19,8 @@ public function __construct(CronService $cronSvc) public function index() { - // Generate the cron path. Replace php-fpm with just php - $cron_path = [ - '* * * * *', - $this->cronSvc->getCronPath(), - '>> /dev/null 2>&1', - ]; - return view('admin.maintenance.index', [ - 'cron_path' => implode(' ', $cron_path), + 'cron_path' => $this->cronSvc->getCronExecString(), 'cron_problem_exists' => $this->cronSvc->cronProblemExists(), ]); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index f293355dd..1d02a7944 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -67,7 +67,7 @@ public function boot(): void public function register(): void { // Only load the IDE helper if it's included and enabled - if (config('app.debug_toolbar') === true) { + if (config('app.debug') === true) { /* @noinspection NestedPositiveIfStatementsInspection */ /* @noinspection PhpFullyQualifiedNameUsageInspection */ if (class_exists(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class)) { diff --git a/app/Services/CronService.php b/app/Services/CronService.php index c6de36bff..51ce8f32c 100644 --- a/app/Services/CronService.php +++ b/app/Services/CronService.php @@ -8,6 +8,7 @@ use DateTimeZone; use Exception; use Illuminate\Support\Facades\Log; +use Symfony\Component\Process\PhpExecutableFinder; class CronService extends Service { @@ -26,16 +27,33 @@ public function __construct( */ public function getCronPath(): string { + $finder = new PhpExecutableFinder(); + $php_path = $finder->find(false); + $path = [ 'cd '.base_path(), '&&', - str_replace('-fpm', '', PHP_BINARY), + str_replace('-fpm', '', $php_path), 'artisan schedule:run', ]; return implode(' ', $path); } + /** + * Show an example cron command that runs every minute + * + * @return string + */ + public function getCronExecString(): string + { + return implode(' ', [ + '* * * * *', + $this->getCronPath(), + '>> /dev/null 2>&1', + ]); + } + /** * Update the last time the cron was run in the kvp repo */ diff --git a/resources/views/admin/dashboard/index.blade.php b/resources/views/admin/dashboard/index.blade.php index f5a6769ea..277428334 100644 --- a/resources/views/admin/dashboard/index.blade.php +++ b/resources/views/admin/dashboard/index.blade.php @@ -2,6 +2,12 @@ @section('title', 'Dashboard') @section('content')
+ @if($cron_problem_exists) + + @endif