switch config table to key/value store
This commit is contained in:
parent
525048bbb2
commit
8241177556
@ -39,10 +39,7 @@ function auth()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$credentials = Database::get('db')->table('config')
|
$credentials = Database::get('db')->hashtable('settings')->get('username', 'fever_token');
|
||||||
->columns('username', 'fever_token')
|
|
||||||
->findOne();
|
|
||||||
|
|
||||||
$api_key = md5($credentials['username'].':'.$credentials['fever_token']);
|
$api_key = md5($credentials['username'].':'.$credentials['fever_token']);
|
||||||
|
|
||||||
$response = array(
|
$response = array(
|
||||||
|
@ -238,14 +238,14 @@ function new_tokens()
|
|||||||
'fever_token' => substr(generate_token(), 0, 8),
|
'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
|
// Get a config value from the DB or from the session
|
||||||
function get($name)
|
function get($name)
|
||||||
{
|
{
|
||||||
if (! isset($_SESSION)) {
|
if (! isset($_SESSION)) {
|
||||||
return Database::get('db')->table('config')->findOneColumn($name);
|
return current(Database::get('db')->hashtable('settings')->get($name));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
@ -264,9 +264,7 @@ function get($name)
|
|||||||
// Get all config parameters
|
// Get all config parameters
|
||||||
function get_all()
|
function get_all()
|
||||||
{
|
{
|
||||||
$config = Database::get('db')
|
$config = Database::get('db')->hashtable('settings')->get();
|
||||||
->table('config')
|
|
||||||
->findOne();
|
|
||||||
|
|
||||||
unset($config['password']);
|
unset($config['password']);
|
||||||
|
|
||||||
@ -322,7 +320,7 @@ function save(array $values)
|
|||||||
Database::get('db')->table('items')->update(array('content' => ''));
|
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();
|
reload();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ function create($filename, $username, $password)
|
|||||||
'password' => password_hash($password, PASSWORD_BCRYPT)
|
'password' => password_hash($password, PASSWORD_BCRYPT)
|
||||||
);
|
);
|
||||||
|
|
||||||
$db->table('config')->update($credentials);
|
$db->hashtable('settings')->put($credentials);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,51 @@ namespace Schema;
|
|||||||
use PDO;
|
use PDO;
|
||||||
use Model\Config;
|
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)
|
function version_34($pdo)
|
||||||
{
|
{
|
||||||
|
@ -27,9 +27,8 @@ function logout()
|
|||||||
function getCredentials()
|
function getCredentials()
|
||||||
{
|
{
|
||||||
return Database::get('db')
|
return Database::get('db')
|
||||||
->table('config')
|
->hashtable('settings')
|
||||||
->columns('username', 'password')
|
->get('username', 'password');
|
||||||
->findOne();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate authentication
|
// Validate authentication
|
||||||
|
Loading…
Reference in New Issue
Block a user