added update interface for companies
This commit is contained in:
parent
67f8be51c6
commit
640cafb133
8
app/Interfaces/Update/ShouldUpdateAllCompanies.php
Normal file
8
app/Interfaces/Update/ShouldUpdateAllCompanies.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Interfaces\Update;
|
||||||
|
|
||||||
|
interface ShouldUpdateAllCompanies
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
@ -3,8 +3,10 @@
|
|||||||
namespace App\Jobs\Install;
|
namespace App\Jobs\Install;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Interfaces\Update\ShouldUpdateAllCompanies;
|
||||||
use App\Models\Module\Module;
|
use App\Models\Module\Module;
|
||||||
use App\Utilities\Console;
|
use App\Utilities\Console;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
|
||||||
class FinishUpdate extends Job
|
class FinishUpdate extends Job
|
||||||
{
|
{
|
||||||
@ -32,19 +34,9 @@ class FinishUpdate extends Job
|
|||||||
$this->company_id = $company_id;
|
$this->company_id = $company_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handle(): void
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
if ($this->alias == 'core') {
|
$companies = $this->getCompanies();
|
||||||
$companies = [$this->company_id];
|
|
||||||
} else {
|
|
||||||
// Get company list from modules table
|
|
||||||
$companies = Module::alias($this->alias)->allCompanies()->cursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($companies as $company) {
|
foreach ($companies as $company) {
|
||||||
$company_id = is_object($company) ? $company->company_id : $company;
|
$company_id = is_object($company) ? $company->company_id : $company;
|
||||||
@ -58,4 +50,63 @@ class FinishUpdate extends Job
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCompanies()
|
||||||
|
{
|
||||||
|
if ($this->alias == 'core') {
|
||||||
|
return [$this->company_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getCompaniesOfModule();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCompaniesOfModule()
|
||||||
|
{
|
||||||
|
$listener = $this->getListenerTypeOfModule();
|
||||||
|
|
||||||
|
if ($listener == 'none') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($listener == 'one') {
|
||||||
|
return [$this->company_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get company list from modules table
|
||||||
|
return Module::alias($this->alias)->allCompanies()->cursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getListenerTypeOfModule(): string
|
||||||
|
{
|
||||||
|
$listener = 'none';
|
||||||
|
|
||||||
|
$module = module($this->alias);
|
||||||
|
$filesystem = app(Filesystem::class);
|
||||||
|
|
||||||
|
$updates_folder = $module->getPath() . '/Listeners/Update';
|
||||||
|
|
||||||
|
foreach ($filesystem->allFiles($updates_folder) as $file) {
|
||||||
|
$path = str_replace([$module->getPath(), '.php'], '', $file->getPathname());
|
||||||
|
|
||||||
|
// Thank you PSR-4
|
||||||
|
$class = '\Modules\\' . $module->getStudlyName() . str_replace('/', '\\', $path);
|
||||||
|
|
||||||
|
// Skip if listener is same or lower than old version
|
||||||
|
if (version_compare($class::VERSION, $this->old, '=<')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app($class) instanceof ShouldUpdateAllCompanies) {
|
||||||
|
// Going to update data
|
||||||
|
$listener = 'all';
|
||||||
|
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// Going to update tables/files
|
||||||
|
$listener = 'one';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $listener;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user