Files
emails/api/common/Service/Install.php
2023-06-08 20:49:27 -04:00

41 lines
1.1 KiB
PHP

<?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);
}
}
}