Various updates
This commit is contained in:
40
api/common/Service/Install.php
Normal file
40
api/common/Service/Install.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Service;
|
||||
|
||||
use ProVM\Common\Factory\Model;
|
||||
|
||||
class Install
|
||||
{
|
||||
public function __construct(protected Model $factory, protected array $model_list) {}
|
||||
|
||||
public function check(): bool
|
||||
{
|
||||
foreach ($this->model_list as $model_class) {
|
||||
$repository = $this->factory->find($model_class);
|
||||
if (!$repository->isInstalled()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function install(): void
|
||||
{
|
||||
$check = true;
|
||||
$repository = null;
|
||||
foreach ($this->model_list as $model_class) {
|
||||
$repository = $this->factory->find($model_class);
|
||||
if ($check) {
|
||||
$query = "SET FOREIGN_KEY_CHECKS = 0";
|
||||
$repository->getConnection()->query($query);
|
||||
$check = false;
|
||||
}
|
||||
if (!$repository->isInstalled()) {
|
||||
$repository->install();
|
||||
}
|
||||
}
|
||||
if (!$check) {
|
||||
$query = "SET FOREIGN_KEY_CHECKS = 1";
|
||||
$repository->getConnection()->query($query);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user