From 9a026de610436f17451876c2e640cdf912cbaac3 Mon Sep 17 00:00:00 2001 From: Anna Dabrowska Date: Mon, 8 Jan 2024 14:51:42 +0100 Subject: [PATCH 1/4] Update Github Workflows --- .github/workflows/dokuwiki.yml | 11 +++++++ .github/workflows/phpTestLinux.yml | 52 ------------------------------ 2 files changed, 11 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/dokuwiki.yml delete mode 100644 .github/workflows/phpTestLinux.yml diff --git a/.github/workflows/dokuwiki.yml b/.github/workflows/dokuwiki.yml new file mode 100644 index 0000000..1c1f321 --- /dev/null +++ b/.github/workflows/dokuwiki.yml @@ -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 diff --git a/.github/workflows/phpTestLinux.yml b/.github/workflows/phpTestLinux.yml deleted file mode 100644 index 134fd24..0000000 --- a/.github/workflows/phpTestLinux.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: PHP Tests on Linux - -on: [push, pull_request] - -jobs: - testLinux: - name: PHP ${{ matrix.php-versions }} DokuWiki ${{ matrix.dokuwiki-branch }} - runs-on: ubuntu-latest - if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository - - strategy: - matrix: - php-versions: ['7.2', '7.3', '7.4', '8.0'] - dokuwiki-branch: [ 'master', 'stable'] - exclude: - - dokuwiki-branch: 'stable' - php-versions: '8.0' - fail-fast: false - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: mbstring, intl, PDO, pdo_sqlite, bz2 - - - name: Setup problem matchers - run: | - echo ::add-matcher::${{ runner.tool_cache }}/php.json - echo ::add-matcher::${{ runner.tool_cache }}/phpunit.json - - - name: Download DokuWiki Test-setup - run: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh - - - name: Run DokuWiki Test-setup - env: - CI_SERVER: 1 - DOKUWIKI: ${{ matrix.dokuwiki-branch }} - run: sh travis.sh - - - name: Setup PHPUnit - run: | - php _test/fetchphpunit.php - cd _test - - - name: Run PHPUnit - run: | - cd _test - php phpunit.phar --verbose --stderr --group plugin_sqlite From a7a40fb292e55f99ed1ae34981feed1314e2696b Mon Sep 17 00:00:00 2001 From: Anna Dabrowska Date: Thu, 25 Jan 2024 13:06:49 +0100 Subject: [PATCH 2/4] Automatic code style fixes --- Functions.php | 7 ++----- QuerySaver.php | 1 - SQLiteDB.php | 20 ++++++++++---------- Tools.php | 35 ++++++++++++++++++----------------- admin.php | 17 +++++++---------- helper.php | 42 +++++++++++++++++++++++------------------- helper/db.php | 5 +++-- plugin.info.txt | 1 + 8 files changed, 64 insertions(+), 64 deletions(-) diff --git a/Functions.php b/Functions.php index 5025a25..d383765 100644 --- a/Functions.php +++ b/Functions.php @@ -1,10 +1,10 @@ query($sql, $values); $success = $stm->rowCount(); $stm->closeCursor(); @@ -371,7 +373,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)); @@ -415,7 +417,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 { @@ -425,11 +427,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(); diff --git a/Tools.php b/Tools.php index 2ad21bf..d72ef6f 100644 --- a/Tools.php +++ b/Tools.php @@ -2,8 +2,8 @@ namespace dokuwiki\plugin\sqlite; -class Tools { - +class Tools +{ /** * Split sql queries on semicolons, unless when semicolons are quoted * @@ -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; @@ -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; @@ -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 } diff --git a/admin.php b/admin.php index d130345..8670031 100644 --- a/admin.php +++ b/admin.php @@ -1,5 +1,6 @@ */ -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() @@ -148,12 +149,7 @@ 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())), - 'title' => $db, - 'level' => 2, - 'type' => 'ul', - ); + $toc[] = ['link' => wl($ID, ['do' => 'admin', 'page' => 'sqlite', 'db' => $db, 'sectok' => getSecurityToken()]), 'title' => $db, 'level' => 2, 'type' => 'ul']; } return $toc; @@ -238,7 +234,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 ? '&' : '&'); diff --git a/helper.php b/helper.php index 52fff77..20bb454 100755 --- a/helper.php +++ b/helper.php @@ -6,22 +6,24 @@ * @noinspection PhpComposerExtensionStubsInspection */ +use dokuwiki\Extension\Plugin; use dokuwiki\plugin\sqlite\SQLiteDB; use dokuwiki\plugin\sqlite\Tools; - - /** * For compatibility with previous adapter implementation. */ -if(!defined('DOKU_EXT_PDO')) define('DOKU_EXT_PDO', 'pdo'); +if (!defined('DOKU_EXT_PDO')) define('DOKU_EXT_PDO', 'pdo'); class helper_plugin_sqlite_adapter_dummy { - public function getName() { + public function getName() + { return DOKU_EXT_PDO; } - public function setUseNativeAlter($set) {} + public function setUseNativeAlter($set) + { + } } /** @@ -31,10 +33,10 @@ public function setUseNativeAlter($set) {} * @author Andreas Gohr * @deprecated 2023-03-15 */ -class helper_plugin_sqlite extends DokuWiki_Plugin +class helper_plugin_sqlite extends Plugin { /** @var SQLiteDB|null */ - protected $adapter = null; + protected $adapter; /** @var array result cache */ protected $data; @@ -89,7 +91,7 @@ public function existsPDOSqlite() */ public function init($dbname, $updatedir) { - if(!defined('DOKU_UNITTEST')) { // for now we don't want to trigger the deprecation warning in the tests + if (!defined('DOKU_UNITTEST')) { // for now we don't want to trigger the deprecation warning in the tests dbg_deprecated(SQLiteDB::class); } @@ -108,7 +110,7 @@ public function init($dbname, $updatedir) * @param SQLiteDB $adapter * @return void */ - function setAdapter($adapter) + public function setAdapter($adapter) { $this->adapter = $adapter; } @@ -182,17 +184,18 @@ public function query() * @return bool|string * @throws Exception */ - public function prepareSql($args) { + public function prepareSql($args) + { $sql = trim(array_shift($args)); $sql = rtrim($sql, ';'); - if(!$sql) { + if (!$sql) { throw new \Exception('No SQL statement given', -1); } $argc = count($args); - if($argc > 0 && is_array($args[0])) { + if ($argc > 0 && is_array($args[0])) { $args = $args[0]; $argc = count($args); } @@ -201,10 +204,10 @@ public function prepareSql($args) { $qmc = substr_count($sql, '?'); if ($argc < $qmc) { throw new \Exception('Not enough arguments passed for statement. ' . - 'Expected '.$qmc.' got '. $argc.' - '.hsc($sql)); - } elseif($argc > $qmc) { + 'Expected ' . $qmc . ' got ' . $argc . ' - ' . hsc($sql)); + } elseif ($argc > $qmc) { throw new \Exception('Too much arguments passed for statement. ' . - 'Expected '.$qmc.' got '. $argc.' - '.hsc($sql)); + 'Expected ' . $qmc . ' got ' . $argc . ' - ' . hsc($sql)); } // explode at wildcard, then join again @@ -212,7 +215,7 @@ public function prepareSql($args) { $args = array_map([$this->adapter->getPdo(), 'quote'], $args); $sql = ''; - while(($part = array_shift($parts)) !== null) { + while (($part = array_shift($parts)) !== null) { $sql .= $part; $sql .= array_shift($args); } @@ -356,7 +359,7 @@ public function countChanges($res) public function quote_and_join($vals, $sep = ',') { $vals = array_map([$this->adapter->getPdo(), 'quote'], $vals); - return join($sep, $vals); + return implode($sep, $vals); } /** @@ -391,7 +394,7 @@ public function escape_string($str) */ public function SQLstring2array($sql) { - if(!DOKU_UNITTEST) { // for now we don't want to trigger the deprecation warning in the tests + if (!DOKU_UNITTEST) { // for now we don't want to trigger the deprecation warning in the tests dbg_deprecated(Tools::class . '::SQLstring2array'); } return Tools::SQLstring2array($sql); @@ -400,7 +403,8 @@ public function SQLstring2array($sql) /** * @deprecated needs to be fixed in stuct and structpublish */ - public function doTransaction($sql, $sqlpreparing = true) { + public function doTransaction($sql, $sqlpreparing = true) + { throw new \Exception( 'This method seems to never have done what it suggests. Please use the query() function instead.' ); diff --git a/helper/db.php b/helper/db.php index 0e80d92..5f4d49c 100644 --- a/helper/db.php +++ b/helper/db.php @@ -1,5 +1,7 @@ sqlite = plugin_load('helper', 'sqlite'); // initialize the database connection diff --git a/plugin.info.txt b/plugin.info.txt index 0ac4bb1..eceabee 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -5,3 +5,4 @@ date 2023-08-17 name sqlite plugin desc A helper plugin to easily access a SQLite database url http://www.dokuwiki.org/plugin:sqlite +minphp 7.3 From 14fe8e279910db76dc1446ba0e4f688190343c1a Mon Sep 17 00:00:00 2001 From: Anna Dabrowska Date: Thu, 25 Jan 2024 14:50:15 +0100 Subject: [PATCH 3/4] More style fixes --- Functions.php | 2 ++ admin.php | 12 ++++++++++-- helper.php | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Functions.php b/Functions.php index d383765..7e2a6e7 100644 --- a/Functions.php +++ b/Functions.php @@ -42,6 +42,7 @@ public static function register($pdo) * @param string $string column value * @param string $separator separator added between values */ + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps public static function GroupConcatStep(&$context, $rownumber, $string, $separator = ',') { if (is_null($context)) { @@ -64,6 +65,7 @@ public static function GroupConcatStep(&$context, $rownumber, $string, $separato * @param int $rownumber number of rows over which the aggregate was performed. * @return null|string */ + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps public static function GroupConcatFinalize(&$context, $rownumber) { if (!is_array($context)) { diff --git a/admin.php b/admin.php index 8670031..cbf4e0b 100644 --- a/admin.php +++ b/admin.php @@ -90,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); } @@ -149,7 +152,12 @@ public function getTOC() $dbfiles = glob($conf['metadir'] . '/*.sqlite3'); if (is_array($dbfiles)) foreach ($dbfiles as $file) { $db = basename($file, '.sqlite3'); - $toc[] = ['link' => wl($ID, ['do' => 'admin', 'page' => 'sqlite', 'db' => $db, 'sectok' => getSecurityToken()]), 'title' => $db, 'level' => 2, 'type' => 'ul']; + $toc[] = [ + 'link' => wl($ID, ['do' => 'admin', 'page' => 'sqlite', 'db' => $db, 'sectok' => getSecurityToken()]), + 'title' => $db, + 'level' => 2, + 'type' => 'ul', + ]; } return $toc; diff --git a/helper.php b/helper.php index 20bb454..a607e62 100755 --- a/helper.php +++ b/helper.php @@ -10,6 +10,9 @@ use dokuwiki\plugin\sqlite\SQLiteDB; use dokuwiki\plugin\sqlite\Tools; +// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols, PSR1.Classes.ClassDeclaration.MultipleClasses +// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps + /** * For compatibility with previous adapter implementation. */ From c76618fb80edaed34929d09bb56c69ab73a36b12 Mon Sep 17 00:00:00 2001 From: Anna Dabrowska Date: Thu, 25 Jan 2024 15:30:29 +0100 Subject: [PATCH 4/4] Rename methods to camelCase --- Functions.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Functions.php b/Functions.php index 7e2a6e7..71d4324 100644 --- a/Functions.php +++ b/Functions.php @@ -21,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); @@ -42,8 +42,7 @@ public static function register($pdo) * @param string $string column value * @param string $separator separator added between values */ - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps - public static function GroupConcatStep(&$context, $rownumber, $string, $separator = ',') + public static function groupConcatStep(&$context, $rownumber, $string, $separator = ',') { if (is_null($context)) { $context = [ @@ -65,8 +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 */ - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps - public static function GroupConcatFinalize(&$context, $rownumber) + public static function groupConcatFinalize(&$context, $rownumber) { if (!is_array($context)) { return null;