Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions db.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/*
SQLite driver for YOURLS.
Version: 1.1
This driver requires YOURLS 1.7.3 -- not before -- not after!
Version: 1.2
This driver requires YOURLS 1.7.4 -- not before -- not after!
Author: Ozh
*/

Expand Down Expand Up @@ -43,7 +43,7 @@ function yourls_db_sqlite_connect() {
$ydb->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' );
Expand All @@ -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' );
Expand Down Expand Up @@ -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();
}
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# 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!).

If you notice something that doesn't work as expected, please open an issue with details on how to reproduce and wait for someone to submit a pull request to fix. If you can both submit the issue and the pull request, you're the boss!

## 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

Expand Down