mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 08:14:04 +02:00
ImportSourceHook: use new static factory
This commit is contained in:
parent
6f3d07f729
commit
a943b0c70f
@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Hook;
|
namespace Icinga\Module\Director\Hook;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Objects\ImportSource;
|
||||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
|
||||||
abstract class ImportSourceHook
|
abstract class ImportSourceHook
|
||||||
{
|
{
|
||||||
protected $settings = array();
|
protected $settings = [];
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
@ -28,6 +29,30 @@ abstract class ImportSourceHook
|
|||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function forImportSource(ImportSource $source)
|
||||||
|
{
|
||||||
|
$db = $source->getDb();
|
||||||
|
$settings = $db->fetchPairs(
|
||||||
|
$db->select()->from(
|
||||||
|
'import_source_setting',
|
||||||
|
['setting_name', 'setting_value']
|
||||||
|
)->where('source_id = ?', $source->getId())
|
||||||
|
);
|
||||||
|
|
||||||
|
$className = $source->get('provider_class');
|
||||||
|
if (! class_exists($className)) {
|
||||||
|
throw new ConfigurationError(
|
||||||
|
'Cannot load import provider class %s',
|
||||||
|
$className
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var ImportSourceHook $obj */
|
||||||
|
$obj = new $className;
|
||||||
|
$obj->setSettings($settings);
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
public static function loadByName($name, Db $db)
|
public static function loadByName($name, Db $db)
|
||||||
{
|
{
|
||||||
$db = $db->getDbAdapter();
|
$db = $db->getDbAdapter();
|
||||||
|
@ -140,9 +140,9 @@ class Import
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checksum of all available rows
|
* All rows
|
||||||
*
|
*
|
||||||
* @return string
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function & checksummedRows()
|
protected function & checksummedRows()
|
||||||
{
|
{
|
||||||
@ -161,9 +161,8 @@ class Import
|
|||||||
protected function & rawData()
|
protected function & rawData()
|
||||||
{
|
{
|
||||||
if ($this->data === null) {
|
if ($this->data === null) {
|
||||||
$this->data = ImportSourceHook::loadByName(
|
$this->data = ImportSourceHook::forImportSource(
|
||||||
$this->source->get('source_name'),
|
$this->source
|
||||||
$this->connection
|
|
||||||
)->fetchData();
|
)->fetchData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user