2015-07-21 15:18:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Import;
|
|
|
|
|
2015-12-03 13:36:33 +01:00
|
|
|
use Icinga\Data\Db\DbConnection;
|
2015-07-30 09:46:14 +02:00
|
|
|
use Icinga\Module\Director\Util;
|
2015-07-21 15:18:16 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
|
|
|
use Icinga\Module\Director\Web\Hook\ImportSourceHook;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-07-30 09:46:14 +02:00
|
|
|
Util::addDbResourceFormElement($form, 'resource');
|
2015-07-22 11:36:43 +02:00
|
|
|
$form->addElement('textarea', 'query', array(
|
2015-07-21 15:18:16 +02:00
|
|
|
'label' => 'DB Query',
|
|
|
|
'required' => true,
|
2015-07-30 09:46:14 +02:00
|
|
|
'rows' => 15,
|
2015-07-21 15:18:16 +02:00
|
|
|
));
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function db()
|
|
|
|
{
|
|
|
|
if ($this->db === null) {
|
|
|
|
$this->db = DbConnection::fromResourceName($this->settings['resource'])->getDbAdapter();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->db;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|