load the sqlite helper
public _getDB ( ) : helper_plugin_sqlite | false | ||
return | helper_plugin_sqlite | false | plugin or false if failed |
public function setUp() { parent::setUp(); $this->action = new action_plugin_data(); $this->helper = plugin_load('helper', 'data'); $this->db = $this->helper->_getDB(); $this->db->query('INSERT INTO pages ( pid, page, title , class , lastmod) VALUES (?, ?, ?, ?, ?)', 1, 'test', 'title', 'class', time()); }
public function testAliases() { $helper = new helper_plugin_data(); $db = $helper->_getDB(); $this->assertTrue($db !== false); $db->query("INSERT INTO aliases (name, type, prefix, postfix, enum) VALUES (?,?,?,?,?)", 'alias', 'wiki', '[[', ']]', ''); $expect = array('alias' => array('type' => 'wiki', 'prefix' => '[[', 'postfix' => ']]')); $this->assertEquals($expect, $helper->_aliases()); }
/** * Carry out required processing */ public function handle() { if (!isset($_REQUEST['data_go']) || !checkSecurityToken()) { return; } $sqlite = $this->dthlp->_getDB(); if (!$sqlite) { return; } $res = $sqlite->query("SELECT pid, page FROM pages"); $rows = $sqlite->res2arr($res); $count = 0; foreach ($rows as $row) { if (!page_exists($row['page'])) { $sqlite->query('DELETE FROM data WHERE pid = ?', $row['pid']); $sqlite->query('DELETE FROM pages WHERE pid = ?', $row['pid']); $count++; } } msg(sprintf($this->getLang('pages_del'), $count), 1); }
/** * Handles the page write event and removes the database info * when the plugin code is no longer in the source * * @param Doku_Event $event * @param null $param */ function _handle(Doku_Event $event, $param) { $data = $event->data; if (strpos($data[0][1], 'dataentry') !== false) { return; } // plugin seems still to be there $sqlite = $this->dthlp->_getDB(); if (!$sqlite) { return; } $id = ltrim($data[1] . ':' . $data[2], ':'); // get page id $res = $sqlite->query('SELECT pid FROM pages WHERE page = ?', $id); $pid = (int) $sqlite->res2single($res); if (!$pid) { return; } // we have no data for this page $sqlite->query('DELETE FROM data WHERE pid = ?', $pid); $sqlite->query('DELETE FROM pages WHERE pid = ?', $pid); }
/** * Output html of the admin page */ public function html() { $sqlite = $this->dthlp->_getDB(); if (!$sqlite) { return; } echo $this->locale_xhtml('admin_intro'); $sql = "SELECT * FROM aliases ORDER BY name"; $res = $sqlite->query($sql); $rows = $sqlite->res2arr($res); $form = new Doku_Form(array('method' => 'post')); $form->addHidden('page', 'data_aliases'); $form->addElement('<table class="inline">' . '<tr>' . '<th>' . $this->getLang('name') . '</th>' . '<th>' . $this->getLang('type') . '</th>' . '<th>' . $this->getLang('prefix') . '</th>' . '<th>' . $this->getLang('postfix') . '</th>' . '<th>' . $this->getLang('enum') . '</th>' . '</tr>'); // add empty row for adding a new entry $rows[] = array('name' => '', 'type' => '', 'prefix' => '', 'postfix' => '', 'enum' => ''); $cur = 0; foreach ($rows as $row) { $form->addElement('<tr>'); $form->addElement('<td>'); $form->addElement(form_makeTextField('d[' . $cur . '][name]', $row['name'], '')); $form->addElement('</td>'); $form->addElement('<td>'); $form->addElement(form_makeMenuField('d[' . $cur . '][type]', array('', 'page', 'title', 'mail', 'url', 'dt', 'wiki', 'tag', 'hidden', 'img'), $row['type'], '')); $form->addElement('</td>'); $form->addElement('<td>'); $form->addElement(form_makeTextField('d[' . $cur . '][prefix]', $row['prefix'], '')); $form->addElement('</td>'); $form->addElement('<td>'); $form->addElement(form_makeTextField('d[' . $cur . '][postfix]', $row['postfix'], '')); $form->addElement('</td>'); $form->addElement('<td>'); $form->addElement(form_makeTextField('d[' . $cur . '][enum]', $row['enum'], '')); $form->addElement('</td>'); $form->addElement('</tr>'); $cur++; } $form->addElement('</table>'); $form->addElement(form_makeButton('submit', 'admin', $this->getLang('submit'))); $form->printForm(); }
public function testNoSqlPlugin() { $helper = new helper_plugin_data(); plugin_disable('sqlite'); $this->assertFalse($helper->_getDB()); }