2015-07-23 11:45:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Objects;
|
|
|
|
|
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;
|
2018-10-08 06:27:14 +02:00
|
|
|
use RuntimeException;
|
2015-07-23 11:45:07 +02:00
|
|
|
|
2022-06-20 09:49:34 +02:00
|
|
|
class ImportRowModifier extends DbObjectWithSettings implements InstantiatedViaHook
|
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)) {
|
2018-10-08 06:27:14 +02:00
|
|
|
throw new RuntimeException(sprintf(
|
|
|
|
'Cannot instantiate Property modifier %s',
|
|
|
|
$class
|
|
|
|
));
|
2018-01-25 13:13:42 +01:00
|
|
|
}
|
2017-08-20 15:17:22 +02:00
|
|
|
$obj = new $class;
|
2016-07-20 12:59:02 +02:00
|
|
|
$obj->setSettings($this->getSettings());
|
2020-12-02 17:59:15 +01:00
|
|
|
$obj->setPropertyName($this->get('property_name'));
|
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
|
|
|
/**
|
2022-06-20 09:49:34 +02:00
|
|
|
* @deprecated please use \Icinga\Module\Director\Data\Exporter
|
2018-05-29 12:34:18 +02:00
|
|
|
* @return \stdClass
|
|
|
|
*/
|
|
|
|
public function export()
|
|
|
|
{
|
|
|
|
$properties = $this->getProperties();
|
|
|
|
unset($properties['id']);
|
|
|
|
unset($properties['source_id']);
|
2019-09-19 17:24:31 +02:00
|
|
|
$properties['settings'] = $this->getInstance()->exportSettings();
|
2018-10-04 06:53:55 +02:00
|
|
|
ksort($properties);
|
2018-05-29 12:34:18 +02:00
|
|
|
|
|
|
|
return (object) $properties;
|
|
|
|
}
|
|
|
|
|
2019-09-20 00:10:30 +02:00
|
|
|
public function setSettings($settings)
|
|
|
|
{
|
|
|
|
$settings = $this->getInstance()->setSettings((array) $settings)->getSettings();
|
|
|
|
|
|
|
|
return parent::setSettings($settings); // TODO: Change the autogenerated stub
|
|
|
|
}
|
|
|
|
|
2017-08-20 15:14:37 +02:00
|
|
|
protected function beforeStore()
|
|
|
|
{
|
2018-06-11 17:37:54 +02:00
|
|
|
if (! $this->hasBeenLoadedFromDb() && $this->get('priority') === null) {
|
2017-08-20 15:14:37 +02:00
|
|
|
$this->setNextPriority('source_id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function onInsert()
|
|
|
|
{
|
|
|
|
$this->refreshPriortyProperty();
|
|
|
|
}
|
2015-07-23 11:45:07 +02:00
|
|
|
}
|