ImportSourceHook: use new static factory
This commit is contained in:
parent
6f3d07f729
commit
a943b0c70f
|
@ -2,13 +2,14 @@
|
|||
|
||||
namespace Icinga\Module\Director\Hook;
|
||||
|
||||
use Icinga\Module\Director\Objects\ImportSource;
|
||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
abstract class ImportSourceHook
|
||||
{
|
||||
protected $settings = array();
|
||||
protected $settings = [];
|
||||
|
||||
public function getName()
|
||||
{
|
||||
|
@ -28,6 +29,30 @@ abstract class ImportSourceHook
|
|||
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)
|
||||
{
|
||||
$db = $db->getDbAdapter();
|
||||
|
|
|
@ -140,9 +140,9 @@ class Import
|
|||
}
|
||||
|
||||
/**
|
||||
* Checksum of all available rows
|
||||
* All rows
|
||||
*
|
||||
* @return string
|
||||
* @return array
|
||||
*/
|
||||
protected function & checksummedRows()
|
||||
{
|
||||
|
@ -161,9 +161,8 @@ class Import
|
|||
protected function & rawData()
|
||||
{
|
||||
if ($this->data === null) {
|
||||
$this->data = ImportSourceHook::loadByName(
|
||||
$this->source->get('source_name'),
|
||||
$this->connection
|
||||
$this->data = ImportSourceHook::forImportSource(
|
||||
$this->source
|
||||
)->fetchData();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue