Installing and managing modules from admin panel (#847)

This commit is contained in:
Yash Govekar
2020-10-19 19:40:28 +05:30
committed by GitHub
parent ca220f1cdf
commit 5803487d51
92 changed files with 1259 additions and 669 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Services\Installer;
use App\Contracts\Service;
use App\Models\Setting;
use App\Services\DatabaseService;
use Carbon\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
@@ -42,6 +43,10 @@ class SeederService extends Service
return true;
}
if ($this->moduleSeedsPending()) {
return true;
}
return false;
}
@@ -54,6 +59,7 @@ class SeederService extends Service
$this->syncAllYamlFileSeeds();
$this->syncAllSettings();
$this->syncAllPermissions();
$this->syncAllModules();
}
/**
@@ -83,6 +89,24 @@ class SeederService extends Service
});
}
public function syncAllModules(): void
{
$data = file_get_contents(database_path('/seeds/modules.yml'));
$yml = Yaml::parse($data);
foreach ($yml as $module) {
$module['updated_at'] = Carbon::now();
$count = DB::table('modules')->where('name', $module['name'])->count('name');
if ($count === 0) {
$module['created_at'] = Carbon::now();
DB::table('modules')->insert($module);
} else {
DB::table('modules')
->where('name', $module['name'])
->update($module);
}
}
}
public function syncAllSettings(): void
{
$data = file_get_contents(database_path('/seeds/settings.yml'));
@@ -286,4 +310,28 @@ class SeederService extends Service
return false;
}
private function moduleSeedsPending(): bool
{
$all_modules = DB::table('modules')->get();
$data = file_get_contents(database_path('/seeds/modules.yml'));
$yml = Yaml::parse($data);
foreach ($yml as $perm) {
$row = $all_modules->firstWhere('name', $perm['name']);
if (!$row) {
return true;
}
// See if any of these column values have changed
foreach (['name', 'enabled'] as $column) {
if ($row->{$column} !== $perm[$column]) {
return true;
}
}
}
return false;
}
}