2015-07-23 11:45:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Objects;
|
|
|
|
|
2018-01-25 13:13:42 +01:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
2016-02-17 22:02:28 +01:00
|
|
|
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
|
2017-08-20 15:14:37 +02:00
|
|
|
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
|
|
|
use Icinga\Module\Director\Objects\Extension\PriorityColumn;
|
2015-07-23 11:45:07 +02:00
|
|
|
|
2016-02-17 22:02:28 +01:00
|
|
|
class ImportRowModifier extends DbObjectWithSettings
|
2015-07-23 11:45:07 +02:00
|
|
|
{
|
2017-08-20 15:14:37 +02:00
|
|
|
use PriorityColumn;
|
|
|
|
|
2015-07-23 11:45:07 +02:00
|
|
|
protected $table = 'import_row_modifier';
|
|
|
|
|
|
|
|
protected $keyName = 'id';
|
|
|
|
|
|
|
|
protected $autoincKeyName = 'id';
|
|
|
|
|
2017-08-20 15:14:37 +02:00
|
|
|
protected $defaultProperties = [
|
2016-07-20 13:41:16 +02:00
|
|
|
'id' => null,
|
|
|
|
'source_id' => null,
|
|
|
|
'property_name' => null,
|
|
|
|
'provider_class' => null,
|
|
|
|
'target_property' => null,
|
|
|
|
'priority' => null,
|
2017-07-14 14:56:22 +02:00
|
|
|
'description' => null,
|
2017-08-20 15:14:37 +02:00
|
|
|
];
|
2015-07-23 11:45:07 +02:00
|
|
|
|
2016-02-17 22:02:28 +01:00
|
|
|
protected $settingsTable = 'import_row_modifier_setting';
|
2015-07-23 11:45:07 +02:00
|
|
|
|
2016-02-17 22:02:28 +01:00
|
|
|
protected $settingsRemoteId = 'row_modifier_id';
|
2016-07-20 12:59:02 +02:00
|
|
|
|
|
|
|
private $hookInstance;
|
|
|
|
|
|
|
|
public function getInstance()
|
|
|
|
{
|
|
|
|
if ($this->hookInstance === null) {
|
2017-08-20 15:17:22 +02:00
|
|
|
$class = $this->get('provider_class');
|
2017-08-20 15:14:37 +02:00
|
|
|
/** @var PropertyModifierHook $obj */
|
2018-01-25 13:13:42 +01:00
|
|
|
if (! class_exists($class)) {
|
|
|
|
throw new ConfigurationError('Cannot instantiate Property modifier %s', $class);
|
|
|
|
}
|
2017-08-20 15:17:22 +02:00
|
|
|
$obj = new $class;
|
2016-07-20 12:59:02 +02:00
|
|
|
$obj->setSettings($this->getSettings());
|
2017-08-20 15:14:37 +02:00
|
|
|
$obj->setTargetProperty($this->get('target_property'));
|
2016-07-20 12:59:02 +02:00
|
|
|
$obj->setDb($this->connection);
|
|
|
|
$this->hookInstance = $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->hookInstance;
|
|
|
|
}
|
2017-08-20 15:14:37 +02:00
|
|
|
|
2018-05-29 12:34:18 +02:00
|
|
|
/**
|
|
|
|
* @return \stdClass
|
|
|
|
*/
|
|
|
|
public function export()
|
|
|
|
{
|
|
|
|
$properties = $this->getProperties();
|
|
|
|
unset($properties['id']);
|
|
|
|
unset($properties['source_id']);
|
|
|
|
$properties['settings'] = (object) $this->getSettings();
|
|
|
|
|
|
|
|
return (object) $properties;
|
|
|
|
}
|
|
|
|
|
2017-08-20 15:14:37 +02:00
|
|
|
protected function beforeStore()
|
|
|
|
{
|
|
|
|
if (! $this->hasBeenLoadedFromDb()) {
|
|
|
|
$this->setNextPriority('source_id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function onInsert()
|
|
|
|
{
|
|
|
|
$this->refreshPriortyProperty();
|
|
|
|
}
|
2015-07-23 11:45:07 +02:00
|
|
|
}
|