Host/Service: Transform y|n enums to true|false

This commit is contained in:
Johannes Meyer 2019-10-11 15:55:14 +02:00 committed by Eric Lippmann
parent f93dcd1d9e
commit 88ccf14907
3 changed files with 37 additions and 0 deletions

View file

@ -0,0 +1,11 @@
<?php
namespace Icinga\Module\Eagle\Model\Behavior;
class BoolCast extends PropertiesBehavior
{
public function __invoke($value, $key)
{
return $value === 'y';
}
}

View file

@ -2,6 +2,8 @@
namespace Icinga\Module\Eagle\Model;
use Icinga\Module\Eagle\Model\Behavior\BoolCast;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Relations;
@ -66,6 +68,17 @@ class Host extends Model
];
}
public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new BoolCast([
'active_checks_enabled',
'passive_checks_enabled',
'event_handler_enabled',
'notifications_enabled',
'flapping_enabled'
]));
}
public function createRelations(Relations $relations)
{
$relations->belongsTo('environment', Environment::class);

View file

@ -2,6 +2,8 @@
namespace Icinga\Module\Eagle\Model;
use Icinga\Module\Eagle\Model\Behavior\BoolCast;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Relations;
@ -60,6 +62,17 @@ class Service extends Model
];
}
public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new BoolCast([
'active_checks_enabled',
'passive_checks_enabled',
'event_handler_enabled',
'notifications_enabled',
'flapping_enabled'
]));
}
public function createRelations(Relations $relations)
{
$relations->belongsTo('environment', Environment::class);