2019-11-19 23:54:42 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Installer;
|
|
|
|
|
|
|
|
use App\Contracts\Service;
|
2020-02-09 02:29:34 +08:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2020-10-22 02:12:38 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-11-19 23:54:42 +08:00
|
|
|
|
|
|
|
class InstallerService extends Service
|
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
private MigrationService $migrationSvc;
|
|
|
|
private SeederService $seederSvc;
|
2019-11-19 23:54:42 +08:00
|
|
|
|
|
|
|
/**
|
2022-03-14 23:45:18 +08:00
|
|
|
* @param MigrationService $migrationSvc
|
|
|
|
* @param SeederService $seederSvc
|
2019-11-19 23:54:42 +08:00
|
|
|
*/
|
|
|
|
public function __construct(MigrationService $migrationSvc, SeederService $seederSvc)
|
|
|
|
{
|
|
|
|
$this->migrationSvc = $migrationSvc;
|
|
|
|
$this->seederSvc = $seederSvc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if there is an upgrade pending by checking the migrations or seeds
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isUpgradePending(): bool
|
|
|
|
{
|
2020-10-22 02:12:38 +08:00
|
|
|
$pendingMigrations = count($this->migrationSvc->migrationsAvailable());
|
|
|
|
if ($pendingMigrations > 0) {
|
|
|
|
Log::info('Found '.$pendingMigrations.' pending migrations, update available');
|
2019-11-19 23:54:42 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->seederSvc->seedsPending()) {
|
2020-10-22 02:12:38 +08:00
|
|
|
Log::info('Found seeds pending, update available');
|
2019-11-19 23:54:42 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-09 02:29:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear whatever caches we can by calling Artisan
|
|
|
|
*/
|
|
|
|
public function clearCaches(): void
|
|
|
|
{
|
2020-10-19 22:10:28 +08:00
|
|
|
Artisan::call('optimize:clear');
|
2020-02-09 02:29:34 +08:00
|
|
|
}
|
2019-11-19 23:54:42 +08:00
|
|
|
}
|