switch config table to key/value store

This commit is contained in:
Mathias Kresin 2015-01-28 05:26:36 +01:00
parent 525048bbb2
commit 8241177556
5 changed files with 53 additions and 15 deletions

View File

@ -39,10 +39,7 @@ function auth()
}
}
$credentials = Database::get('db')->table('config')
->columns('username', 'fever_token')
->findOne();
$credentials = Database::get('db')->hashtable('settings')->get('username', 'fever_token');
$api_key = md5($credentials['username'].':'.$credentials['fever_token']);
$response = array(

View File

@ -238,14 +238,14 @@ function new_tokens()
'fever_token' => substr(generate_token(), 0, 8),
);
return Database::get('db')->table('config')->update($values);
return Database::get('db')->hashtable('settings')->put($values);
}
// Get a config value from the DB or from the session
function get($name)
{
if (! isset($_SESSION)) {
return Database::get('db')->table('config')->findOneColumn($name);
return current(Database::get('db')->hashtable('settings')->get($name));
}
else {
@ -264,9 +264,7 @@ function get($name)
// Get all config parameters
function get_all()
{
$config = Database::get('db')
->table('config')
->findOne();
$config = Database::get('db')->hashtable('settings')->get();
unset($config['password']);
@ -322,7 +320,7 @@ function save(array $values)
Database::get('db')->table('items')->update(array('content' => ''));
}
if (Database::get('db')->table('config')->update($values)) {
if (Database::get('db')->hashtable('settings')->put($values)) {
reload();
return true;
}

View File

@ -26,7 +26,7 @@ function create($filename, $username, $password)
'password' => password_hash($password, PASSWORD_BCRYPT)
);
$db->table('config')->update($credentials);
$db->hashtable('settings')->put($credentials);
return true;
}

View File

@ -5,7 +5,51 @@ namespace Schema;
use PDO;
use Model\Config;
const VERSION = 34;
const VERSION = 35;
function version_35($pdo)
{
$pdo->exec('DELETE FROM favicons WHERE icon = ""');
$pdo->exec('
CREATE TABLE settings (
"key" TEXT NOT NULL UNIQUE,
"value" TEXT Default NULL,
PRIMARY KEY(key)
)
');
$pdo->exec("
INSERT INTO settings (key,value)
SELECT 'username', username FROM config UNION
SELECT 'password', password FROM config UNION
SELECT 'language', language FROM config UNION
SELECT 'autoflush', autoflush FROM config UNION
SELECT 'nocontent', nocontent FROM config UNION
SELECT 'items_per_page', items_per_page FROM config UNION
SELECT 'theme', theme FROM config UNION
SELECT 'api_token', api_token FROM config UNION
SELECT 'feed_token', feed_token FROM config UNION
SELECT 'items_sorting_direction', items_sorting_direction FROM config UNION
SELECT 'redirect_nothing_to_read', redirect_nothing_to_read FROM config UNION
SELECT 'timezone', timezone FROM config UNION
SELECT 'auto_update_url', auto_update_url FROM config UNION
SELECT 'bookmarklet_token', bookmarklet_token FROM config UNION
SELECT 'items_display_mode', items_display_mode FROM config UNION
SELECT 'fever_token', fever_token FROM config UNION
SELECT 'autoflush_unread', autoflush_unread FROM config UNION
SELECT 'pinboard_enabled', pinboard_enabled FROM config UNION
SELECT 'pinboard_token', pinboard_token FROM config UNION
SELECT 'pinboard_tags', pinboard_tags FROM config UNION
SELECT 'instapaper_enabled', instapaper_enabled FROM config UNION
SELECT 'instapaper_username', instapaper_username FROM config UNION
SELECT 'instapaper_password', instapaper_password FROM config UNION
SELECT 'image_proxy', image_proxy FROM config UNION
SELECT 'favicons', favicons FROM config
");
$pdo->exec('DROP TABLE config');
}
function version_34($pdo)
{

View File

@ -27,9 +27,8 @@ function logout()
function getCredentials()
{
return Database::get('db')
->table('config')
->columns('username', 'password')
->findOne();
->hashtable('settings')
->get('username', 'password');
}
// Validate authentication