Files
thetool/db/migrations/20231004141500_add_can_voice_plan_permission.php
2023-10-04 17:09:58 +02:00

45 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddCanVoicePlanPermission extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("WorkerPermission");
$table->addColumn("canVoiceplan", "enum", ["values" => 'false,true', "default" => "false", "after" => "canVoipnumbering"]);
$table->update();
// set canVoiceplan true where canVoipnumbering is true
$builder = $this->getQueryBuilder();
$q = $builder->select("*")->from("WorkerPermission")->where(["canVoipnumbering" => "true"])->execute();
while($perm = $q->fetch('assoc')) {
$id = $perm["id"];
$this->query("UPDATE WorkerPermission SET canVoiceplan='true' WHERE id=$id");
}
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("WorkerPermission");
$table->removeColumn("canVoiceplan");
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
}