mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-26 11:19:16 +02:00
In case you already implemented such you have to adjust your implementations. Just replace Director/Web/Hook with Director/Hook. Sorry for the inconvenience. Compat classes would have been possible, but as Director isn't stable yet I'd like to avoid doing so.
45 lines
1.0 KiB
PHP
45 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Icinga\Module\Director\Import;
|
|
|
|
use Icinga\Data\Db\DbConnection;
|
|
use Icinga\Module\Director\Hook\ImportSourceHook;
|
|
use Icinga\Module\Director\Util;
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
|
|
|
class ImportSourceSql extends ImportSourceHook
|
|
{
|
|
protected $db;
|
|
|
|
public function fetchData()
|
|
{
|
|
return $this->db()->fetchAll($this->settings['query']);
|
|
}
|
|
|
|
public function listColumns()
|
|
{
|
|
return array_keys((array) current($this->fetchData()));
|
|
}
|
|
|
|
public static function addSettingsFormFields(QuickForm $form)
|
|
{
|
|
Util::addDbResourceFormElement($form, 'resource');
|
|
$form->addElement('textarea', 'query', array(
|
|
'label' => 'DB Query',
|
|
'required' => true,
|
|
'rows' => 15,
|
|
));
|
|
return $form;
|
|
}
|
|
|
|
protected function db()
|
|
{
|
|
if ($this->db === null) {
|
|
$this->db = DbConnection::fromResourceName($this->settings['resource'])->getDbAdapter();
|
|
}
|
|
|
|
return $this->db;
|
|
}
|
|
|
|
}
|