Skip to content

Commit

Permalink
Merge pull request #86 from cosmocode/gh-tests
Browse files Browse the repository at this point in the history
Update GitHub workflows
  • Loading branch information
splitbrain authored Jan 25, 2024
2 parents 34d20bc + c76618f commit 9ac2cb9
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 117 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/dokuwiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: DokuWiki Default Tasks
on:
push:
pull_request:
schedule:
- cron: '55 14 8 * *'


jobs:
all:
uses: dokuwiki/github-action/.github/workflows/all.yml@main
52 changes: 0 additions & 52 deletions .github/workflows/phpTestLinux.yml

This file was deleted.

15 changes: 6 additions & 9 deletions Functions.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php

/**
* @noinspection PhpUndefinedMethodInspection
* @noinspection PhpComposerExtensionStubsInspection
*/


namespace dokuwiki\plugin\sqlite;

/**
* SQLite registered functions
*/
class Functions
{

/**
* Register all standard functions
*
Expand All @@ -22,8 +21,8 @@ public static function register($pdo)
{
$pdo->sqliteCreateAggregate(
'GROUP_CONCAT_DISTINCT',
[Functions::class, 'GroupConcatStep'],
[Functions::class, 'GroupConcatFinalize']
[Functions::class, 'groupConcatStep'],
[Functions::class, 'groupConcatFinalize']
);

$pdo->sqliteCreateFunction('GETACCESSLEVEL', [Functions::class, 'getAccessLevel'], 1);
Expand All @@ -43,7 +42,7 @@ public static function register($pdo)
* @param string $string column value
* @param string $separator separator added between values
*/
public static function GroupConcatStep(&$context, $rownumber, $string, $separator = ',')
public static function groupConcatStep(&$context, $rownumber, $string, $separator = ',')
{
if (is_null($context)) {
$context = [
Expand All @@ -65,7 +64,7 @@ public static function GroupConcatStep(&$context, $rownumber, $string, $separato
* @param int $rownumber number of rows over which the aggregate was performed.
* @return null|string
*/
public static function GroupConcatFinalize(&$context, $rownumber)
public static function groupConcatFinalize(&$context, $rownumber)
{
if (!is_array($context)) {
return null;
Expand All @@ -74,7 +73,7 @@ public static function GroupConcatFinalize(&$context, $rownumber)
if (empty($context['data'][0])) {
return null;
}
return join($context['sep'], $context['data']);
return implode($context['sep'], $context['data']);
}


Expand Down Expand Up @@ -119,7 +118,6 @@ public static function pageExists($pageid)
static $cache = [];
if (!isset($cache[$pageid])) {
$cache[$pageid] = page_exists($pageid);

}
return (int)$cache[$pageid];
}
Expand Down Expand Up @@ -157,5 +155,4 @@ public static function resolvePage($page, $context)
resolve_pageid($ns, $page, $exists);
return $page;
}

}
1 change: 0 additions & 1 deletion QuerySaver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class QuerySaver
{

protected $db;
protected $upstream;

Expand Down
20 changes: 10 additions & 10 deletions SQLiteDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class SQLiteDB
{
const FILE_EXTENSION = '.sqlite3';
public const FILE_EXTENSION = '.sqlite3';

/** @var \PDO */
protected $pdo;
Expand Down Expand Up @@ -254,8 +254,10 @@ public function saveRecord($table, $data, $replace = true)
}

/** @noinspection SqlResolve */
$sql = $command . ' INTO "' . $table . '" (' . join(',', $columns) . ') VALUES (' . join(',',
$placeholders) . ')';
$sql = $command . ' INTO "' . $table . '" (' . implode(',', $columns) . ') VALUES (' . implode(
',',
$placeholders
) . ')';
$stm = $this->query($sql, $values);
$success = $stm->rowCount();
$stm->closeCursor();
Expand Down Expand Up @@ -386,7 +388,7 @@ public function dumpToFile($filename)
$sql = "SELECT * FROM " . $table['name'];
$res = $this->query($sql);
while ($row = $res->fetch(\PDO::FETCH_ASSOC)) {
$values = join(',', array_map(function ($value) {
$values = implode(',', array_map(function ($value) {
if ($value === null) return 'NULL';
return $this->pdo->quote($value);
}, $row));
Expand Down Expand Up @@ -430,7 +432,7 @@ protected function applyMigrations()
'sqlite' => $this->helper,
'adapter' => $this,
];
$event = new \Doku_Event('PLUGIN_SQLITE_DATABASE_UPGRADE', $data);
$event = new Event('PLUGIN_SQLITE_DATABASE_UPGRADE', $data);

$this->pdo->beginTransaction();
try {
Expand All @@ -440,11 +442,9 @@ protected function applyMigrations()
foreach ($sql as $query) {
$this->pdo->exec($query);
}
} else {
if (!$event->result) {
// advise before returned false, but the result was false
throw new \PDOException('Plugin event did not signal success');
}
} elseif (!$event->result) {
// advise before returned false, but the result was false
throw new \PDOException('Plugin event did not signal success');
}
$this->setOpt('dbversion', $newVersion);
$this->pdo->commit();
Expand Down
35 changes: 18 additions & 17 deletions Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace dokuwiki\plugin\sqlite;

class Tools {

class Tools
{
/**
* Split sql queries on semicolons, unless when semicolons are quoted
*
Expand All @@ -13,36 +13,37 @@ class Tools {
* @param string $sql
* @return string[] sql queries
*/
public static function SQLstring2array($sql) {
$statements = array();
public static function SQLstring2array($sql)
{
$statements = [];
$len = strlen($sql);

// Simple state machine to "parse" sql into single statements
$in_str = false;
$in_com = false;
$statement = '';
for($i=0; $i<$len; $i++){
$prev = $i ? $sql[$i-1] : "\n";
for ($i = 0; $i < $len; $i++) {
$prev = $i ? $sql[$i - 1] : "\n";
$char = $sql[$i];
$next = $i < ($len - 1) ? $sql[$i+1] : '';
$next = $i < ($len - 1) ? $sql[$i + 1] : '';

// in comment? ignore everything until line end
if($in_com){
if($char == "\n"){
if ($in_com) {
if ($char == "\n") {
$in_com = false;
}
continue;
}

// handle strings
if($in_str){
if($char == "'"){
if($next == "'"){
if ($in_str) {
if ($char == "'") {
if ($next == "'") {
// current char is an escape for the next
$statement .= $char . $next;
$i++;
continue;
}else{
} else {
// end of string
$statement .= $char;
$in_str = false;
Expand All @@ -55,20 +56,20 @@ public static function SQLstring2array($sql) {
}

// new comment?
if($char == '-' && $next == '-' && $prev == "\n"){
if ($char == '-' && $next == '-' && $prev == "\n") {
$in_com = true;
continue;
}

// new string?
if($char == "'"){
if ($char == "'") {
$in_str = true;
$statement .= $char;
continue;
}

// the real delimiter
if($char == ';'){
if ($char == ';') {
$statements[] = trim($statement);
$statement = '';
continue;
Expand All @@ -77,7 +78,7 @@ public static function SQLstring2array($sql) {
// some standard query stuff
$statement .= $char;
}
if($statement) $statements[] = trim($statement);
if ($statement) $statements[] = trim($statement);

return array_filter($statements); // remove empty statements
}
Expand Down
21 changes: 13 additions & 8 deletions admin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use dokuwiki\Extension\AdminPlugin;
use dokuwiki\Form\Form;
use dokuwiki\Form\InputElement;
use dokuwiki\plugin\sqlite\QuerySaver;
Expand All @@ -12,13 +13,13 @@
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/
class admin_plugin_sqlite extends DokuWiki_Admin_Plugin
class admin_plugin_sqlite extends AdminPlugin
{
/** @var SQLiteDB */
protected $db = null;
protected $db;

/** @var QuerySaver */
protected $querySaver = null;
protected $querySaver;

/** @inheritdoc */
public function getMenuSort()
Expand Down Expand Up @@ -89,7 +90,10 @@ public function handle()
case 'download':
$file = $this->db->getDbFile();
header('Content-Type: application/vnd.sqlite3');
header('Content-Disposition: attachment; filename="' . $this->db->getDbName() . SQLiteDB::FILE_EXTENSION . '"');
header(
'Content-Disposition: attachment; filename="'
. $this->db->getDbName() . SQLiteDB::FILE_EXTENSION . '"'
);
readfile($file);
exit(0);
}
Expand Down Expand Up @@ -148,12 +152,12 @@ public function getTOC()
$dbfiles = glob($conf['metadir'] . '/*.sqlite3');
if (is_array($dbfiles)) foreach ($dbfiles as $file) {
$db = basename($file, '.sqlite3');
$toc[] = array(
'link' => wl($ID, array('do' => 'admin', 'page' => 'sqlite', 'db' => $db, 'sectok' => getSecurityToken())),
$toc[] = [
'link' => wl($ID, ['do' => 'admin', 'page' => 'sqlite', 'db' => $db, 'sectok' => getSecurityToken()]),
'title' => $db,
'level' => 2,
'type' => 'ul',
);
];
}

return $toc;
Expand Down Expand Up @@ -238,7 +242,8 @@ protected function selfLink($form = true, $params = [])
'page' => 'sqlite',
'db' => $this->db ? $this->db->getDBName() : '',
'sectok' => getSecurityToken(),
], $params
],
$params
);

return wl($ID, $params, false, $form ? '&' : '&amp;');
Expand Down
Loading

0 comments on commit 9ac2cb9

Please sign in to comment.