From 5896afbb3216d6e724aeeb3789d95a41082ca5a6 Mon Sep 17 00:00:00 2001 From: erion Date: Fri, 18 Oct 2019 17:16:38 +0200 Subject: [PATCH 1/3] Update README. --- readme.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index ca0930c..35b2e75 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,8 @@ -# SQLite Driver for YOURLS 1.7.3 +# SQLite Driver for YOURLS 1.7.4 ## What -This is a custom DB layer that allows to use YOURLS with PDO + SQLite. This requires **YOURLS 1.7.3**, not before, not after. See [YOURLS releases](https://github.com/YOURLS/YOURLS/releases). +This is a custom DB layer that allows to use YOURLS with PDO + SQLite. This requires **YOURLS 1.7.4**, not before, not after. See [YOURLS releases](https://github.com/YOURLS/YOURLS/releases). This is experimental, mostly to show how it should be done, ie without [hacking core file](https://github.com/YOURLS/YOURLS/wiki/Dont-Hack-Core) - see [YOURLS issue #1337](https://github.com/YOURLS/YOURLS/issues/1337) (1337, for real!). @@ -10,7 +10,8 @@ If you notice something that doesn't work as expected, please open an issue with ## How -* Drop these files in `/user/`, next to your `config.php` (this is *not* a plugin) +* Enable either the **gmp** or the **bcmath** extension for PHP. +* Drop **db.php** in `/user/`, next to your `config.php` (this is *not* a plugin) * Load YOURLS: the first time, it will create a fresh SQlite DB in that same `user` directory * Have fun From f9810edf1227ad4bce4398ec6b1b411b000e437d Mon Sep 17 00:00:00 2001 From: erion Date: Fri, 18 Oct 2019 17:19:40 +0200 Subject: [PATCH 2/3] Fix notice and create_function deprecation for PHP 7.2 and above. Compatible with YOURLS 1.7.4. --- db.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) mode change 100644 => 100755 db.php diff --git a/db.php b/db.php old mode 100644 new mode 100755 index 646f126..6a1bdd8 --- a/db.php +++ b/db.php @@ -1,8 +1,8 @@ init(); // Past this point, we're connected - yourls_debug_log(sprintf('Opened database %s ', $dbname, $dbhost)); + yourls_debug_log(sprintf('Opened database %s ', $dbname)); // Custom tables to be created upon install yourls_add_filter( 'shunt_yourls_create_sql_tables', 'yourls_create_sqlite_tables' ); @@ -52,11 +52,11 @@ function yourls_db_sqlite_connect() { yourls_add_filter( 'stat_query_dates', 'yourls_sqlite_stat_query_dates' ); // Custom stat query to get last 24 hours hits - yourls_add_filter( 'stat_query_last24h', create_function( '', 'return "SELECT 1;";') ); // just bypass original query + yourls_add_filter( 'stat_query_last24h', function() { return "SELECT 1;"; }); // just bypass original query yourls_add_filter( 'pre_yourls_info_last_24h', 'yourls_sqlite_last_24h_hits' ); // use this one instead // Return version for compat - yourls_add_filter( 'shunt_get_database_version', create_function( '', 'return "5.0";') ); + yourls_add_filter( 'shunt_get_database_version', function() { return "5.0";} ); // Shunt get_all_options to prevent error from SHOW TABLES query yourls_add_filter( 'shunt_all_options', 'yourls_sqlite_get_all_options' ); From e9eb727204f032f740b1009491a780e37476a5ec Mon Sep 17 00:00:00 2001 From: erion Date: Sat, 9 May 2020 07:43:15 +0200 Subject: [PATCH 3/3] Add yourls_get_db() helper function. The driver is now only compatible with 1.7.10 and possibly above. --- db.php | 18 +++++++++++++----- readme.md | 4 ++-- 2 files changed, 15 insertions(+), 7 deletions(-) mode change 100644 => 100755 db.php diff --git a/db.php b/db.php old mode 100644 new mode 100755 index 646f126..398b75e --- a/db.php +++ b/db.php @@ -1,8 +1,8 @@ init(); // Past this point, we're connected - yourls_debug_log(sprintf('Opened database %s ', $dbname, $dbhost)); + yourls_debug_log(sprintf('Opened database %s ', $dbname)); // Custom tables to be created upon install yourls_add_filter( 'shunt_yourls_create_sql_tables', 'yourls_create_sqlite_tables' ); @@ -52,11 +52,11 @@ function yourls_db_sqlite_connect() { yourls_add_filter( 'stat_query_dates', 'yourls_sqlite_stat_query_dates' ); // Custom stat query to get last 24 hours hits - yourls_add_filter( 'stat_query_last24h', create_function( '', 'return "SELECT 1;";') ); // just bypass original query + yourls_add_filter( 'stat_query_last24h', function() { return "SELECT 1;"; }); // just bypass original query yourls_add_filter( 'pre_yourls_info_last_24h', 'yourls_sqlite_last_24h_hits' ); // use this one instead // Return version for compat - yourls_add_filter( 'shunt_get_database_version', create_function( '', 'return "5.0";') ); + yourls_add_filter( 'shunt_get_database_version', function() { return "5.0";} ); // Shunt get_all_options to prevent error from SHOW TABLES query yourls_add_filter( 'shunt_all_options', 'yourls_sqlite_get_all_options' ); @@ -281,3 +281,11 @@ function yourls_create_sqlite_tables() { return array( 'success' => $success_msg, 'error' => $error_msg ); } + +/** + * @return \YOURLS\Database\YDB + */ +function yourls_get_db() { + global $ydb; + return ( $ydb instanceof \YOURLS\Database\YDB ) ? $ydb : yourls_db_connect(); +} diff --git a/readme.md b/readme.md index ca0930c..acbd2cf 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,8 @@ -# SQLite Driver for YOURLS 1.7.3 +# SQLite Driver for YOURLS 1.7.10 ## What -This is a custom DB layer that allows to use YOURLS with PDO + SQLite. This requires **YOURLS 1.7.3**, not before, not after. See [YOURLS releases](https://github.com/YOURLS/YOURLS/releases). +This is a custom DB layer that allows to use YOURLS with PDO + SQLite. This requires **YOURLS 1.7.10**, not before, not after. See [YOURLS releases](https://github.com/YOURLS/YOURLS/releases). This is experimental, mostly to show how it should be done, ie without [hacking core file](https://github.com/YOURLS/YOURLS/wiki/Dont-Hack-Core) - see [YOURLS issue #1337](https://github.com/YOURLS/YOURLS/issues/1337) (1337, for real!).