miniflux-legacy/models/schema.php

402 lines
11 KiB
PHP
Raw Normal View History

2013-02-18 03:48:21 +01:00
<?php
namespace Schema;
2014-10-30 02:28:23 +01:00
use PDO;
use Helper;
2014-10-30 02:28:23 +01:00
use Model\Config;
const VERSION = 44;
function version_44(PDO $pdo)
{
$pdo->exec('INSERT INTO settings ("key", "value") VALUES ("item_title_link", "full")');
}
2016-01-10 01:04:42 +01:00
function version_43(PDO $pdo)
{
$pdo->exec('DROP TABLE favicons');
$pdo->exec(
'CREATE TABLE favicons (
id INTEGER PRIMARY KEY,
hash TEXT UNIQUE,
type TEXT
)'
);
$pdo->exec('
CREATE TABLE "favicons_feeds" (
feed_id INTEGER NOT NULL,
favicon_id INTEGER NOT NULL,
PRIMARY KEY(feed_id, favicon_id)
FOREIGN KEY(favicon_id) REFERENCES favicons(id) ON DELETE CASCADE
FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE
)
');
}
2015-12-07 14:18:27 +01:00
function version_42(PDO $pdo)
{
$pdo->exec('DROP TABLE favicons');
$pdo->exec(
'CREATE TABLE favicons (
feed_id INTEGER UNIQUE,
link TEXT,
file TEXT,
type TEXT,
FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE
)'
);
}
2015-10-20 03:21:18 +02:00
function version_41(PDO $pdo)
{
$pdo->exec('
CREATE TABLE "groups" (
id INTEGER PRIMARY KEY,
title TEXT
)
');
$pdo->exec('
CREATE TABLE "feeds_groups" (
feed_id INTEGER NOT NULL,
group_id INTEGER NOT NULL,
PRIMARY KEY(feed_id, group_id)
FOREIGN KEY(group_id) REFERENCES groups(id) ON DELETE CASCADE
FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE
)
');
}
2015-02-07 17:49:55 +01:00
2015-10-20 03:21:18 +02:00
function version_40(PDO $pdo)
2015-02-07 17:49:55 +01:00
{
$pdo->exec('UPDATE settings SET "value"="https://github.com/miniflux/miniflux/archive/master.zip" WHERE "key"="auto_update_url"');
}
2015-10-20 03:21:18 +02:00
function version_39(PDO $pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN cloak_referrer INTEGER DEFAULT 0');
}
2015-10-20 03:21:18 +02:00
function version_38(PDO $pdo)
{
$pdo->exec('INSERT INTO settings ("key", "value") VALUES ("original_marks_read", 1)');
}
2015-10-20 03:21:18 +02:00
function version_37(PDO $pdo)
{
$pdo->exec('INSERT INTO settings ("key", "value") VALUES ("debug_mode", 0)');
}
implement frontend autoupdate Only the unread counter is updated right know. The AutoUpdate Feature is designed on the premise of don't wasting resources. A distinction is made between updates when Miniflux is visible or hidden. To determine the visibility status, the Page Visibility API is used. The API is available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API] As IE9 returns an undefined, it doesn't break the compatibility at least. If Miniflux is visible, the unread counter on the web page is updated as soon as a mismatch between the counter and the number of unread articles in the database is found. If Miniflux is hidden, the timestamp of the most recent article from each feed is compared with the value from the last run. We have an update If the timestamp of the latest article is greater than the stored one and the latest article is unread. The web page title is updated with a ? symbol to notify the user and the update check pauses till Miniflux gets visible again. If Miniflux gets visible again, the number of unread articles is queried from the database, the unread counter on the web page is updated and finally the ? symbol is removed from the web page title. This way I can use my fever API client to read new articles (or at least the latest article) while Miniflux is hidden and as I've seen the new articles already a new articles notification is prevented. It's intentionally that the page does not reload automatically as long as articles are visible. If I'm in hurry, I only scroll through the articles to spot something interesting. Most of the time I don't reach the last article. If the page is reloaded while I'm away, I would have to scan from the top again. If we're on a nothing_to_read page and have unread articles in the database, a redirect to the unread page will be done. The default update check interval is 10 minutes and can be changed on the settings page. A zero value disables the update check entirely. fixes #213
2014-11-27 22:36:04 +01:00
2015-10-20 03:21:18 +02:00
function version_36(PDO $pdo)
implement frontend autoupdate Only the unread counter is updated right know. The AutoUpdate Feature is designed on the premise of don't wasting resources. A distinction is made between updates when Miniflux is visible or hidden. To determine the visibility status, the Page Visibility API is used. The API is available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API] As IE9 returns an undefined, it doesn't break the compatibility at least. If Miniflux is visible, the unread counter on the web page is updated as soon as a mismatch between the counter and the number of unread articles in the database is found. If Miniflux is hidden, the timestamp of the most recent article from each feed is compared with the value from the last run. We have an update If the timestamp of the latest article is greater than the stored one and the latest article is unread. The web page title is updated with a ? symbol to notify the user and the update check pauses till Miniflux gets visible again. If Miniflux gets visible again, the number of unread articles is queried from the database, the unread counter on the web page is updated and finally the ? symbol is removed from the web page title. This way I can use my fever API client to read new articles (or at least the latest article) while Miniflux is hidden and as I've seen the new articles already a new articles notification is prevented. It's intentionally that the page does not reload automatically as long as articles are visible. If I'm in hurry, I only scroll through the articles to spot something interesting. Most of the time I don't reach the last article. If the page is reloaded while I'm away, I would have to scan from the top again. If we're on a nothing_to_read page and have unread articles in the database, a redirect to the unread page will be done. The default update check interval is 10 minutes and can be changed on the settings page. A zero value disables the update check entirely. fixes #213
2014-11-27 22:36:04 +01:00
{
$pdo->exec('INSERT INTO settings ("key", "value") VALUES ("frontend_updatecheck_interval", 10)');
}
2015-01-28 05:26:36 +01:00
2015-10-20 03:21:18 +02:00
function version_35(PDO $pdo)
2015-01-28 05:26:36 +01:00
{
$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');
}
2014-12-24 23:54:27 +01:00
2015-10-20 03:21:18 +02:00
function version_34(PDO $pdo)
2014-12-24 23:54:27 +01:00
{
$pdo->exec('ALTER TABLE config ADD COLUMN favicons INTEGER DEFAULT 0');
$pdo->exec(
'CREATE TABLE favicons (
feed_id INTEGER UNIQUE,
link TEXT,
icon TEXT,
FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE
)'
);
}
2015-10-20 03:21:18 +02:00
function version_33(PDO $pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN image_proxy INTEGER DEFAULT 0');
}
2015-10-20 03:21:18 +02:00
function version_32(PDO $pdo)
2014-12-24 19:50:20 +01:00
{
$pdo->exec('ALTER TABLE config ADD COLUMN instapaper_enabled INTEGER DEFAULT 0');
$pdo->exec('ALTER TABLE config ADD COLUMN instapaper_username TEXT');
$pdo->exec('ALTER TABLE config ADD COLUMN instapaper_password TEXT');
}
2015-10-20 03:21:18 +02:00
function version_31(PDO $pdo)
2014-12-24 16:47:24 +01:00
{
$pdo->exec('ALTER TABLE config ADD COLUMN pinboard_enabled INTEGER DEFAULT 0');
$pdo->exec('ALTER TABLE config ADD COLUMN pinboard_token TEXT');
$pdo->exec('ALTER TABLE config ADD COLUMN pinboard_tags TEXT DEFAULT "miniflux"');
}
2015-10-20 03:21:18 +02:00
function version_30(PDO $pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN autoflush_unread INTEGER DEFAULT 45');
}
2015-10-20 03:21:18 +02:00
function version_29(PDO $pdo)
2014-10-30 02:28:23 +01:00
{
$pdo->exec('ALTER TABLE config ADD COLUMN fever_token INTEGER DEFAULT "'.substr(Helper\generate_token(), 0, 8).'"');
2014-10-30 02:28:23 +01:00
}
2015-10-20 03:21:18 +02:00
function version_28(PDO $pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN rtl INTEGER DEFAULT 0');
}
2015-10-20 03:21:18 +02:00
function version_27(PDO $pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN items_display_mode TEXT DEFAULT "summaries"');
}
2014-05-27 02:47:40 +02:00
2015-10-20 03:21:18 +02:00
function version_26(PDO $pdo)
2014-05-28 22:44:25 +02:00
{
$pdo->exec('ALTER TABLE config ADD COLUMN bookmarklet_token TEXT DEFAULT "'.Helper\generate_token().'"');
2014-05-28 22:44:25 +02:00
}
2015-10-20 03:21:18 +02:00
function version_25(PDO $pdo)
2014-05-27 02:47:40 +02:00
{
$pdo->exec(
'CREATE TABLE remember_me (
id INTEGER PRIMARY KEY,
username TEXT,
ip TEXT,
user_agent TEXT,
token TEXT,
sequence TEXT,
expiration INTEGER,
date_creation INTEGER
)'
);
}
2015-10-20 03:21:18 +02:00
function version_24(PDO $pdo)
2014-03-30 21:59:26 +02:00
{
$pdo->exec("ALTER TABLE config ADD COLUMN auto_update_url TEXT DEFAULT 'https://github.com/fguillot/miniflux/archive/master.zip'");
}
2015-10-20 03:21:18 +02:00
function version_23(PDO $pdo)
2014-03-17 02:35:57 +01:00
{
$pdo->exec('ALTER TABLE items ADD COLUMN language TEXT');
}
2015-10-20 03:21:18 +02:00
function version_22(PDO $pdo)
2014-02-26 01:03:46 +01:00
{
$pdo->exec("ALTER TABLE config ADD COLUMN timezone TEXT DEFAULT 'UTC'");
}
2015-10-20 03:21:18 +02:00
function version_21(PDO $pdo)
{
$pdo->exec('ALTER TABLE items ADD COLUMN enclosure TEXT');
2014-02-18 04:04:49 +01:00
$pdo->exec('ALTER TABLE items ADD COLUMN enclosure_type TEXT');
}
2015-10-20 03:21:18 +02:00
function version_20(PDO $pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN redirect_nothing_to_read TEXT DEFAULT "feeds"');
}
2015-10-20 03:21:18 +02:00
function version_19(PDO $pdo)
{
$rq = $pdo->prepare('SELECT autoflush FROM config');
$rq->execute();
$value = (int) $rq->fetchColumn();
// Change default value of autoflush to 15 days to avoid very large database
if ($value <= 0) {
$rq = $pdo->prepare('UPDATE config SET autoflush=?');
$rq->execute(array(15));
}
}
2015-10-20 03:21:18 +02:00
function version_18(PDO $pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN parsing_error INTEGER DEFAULT 0');
}
2015-10-20 03:21:18 +02:00
function version_17(PDO $pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN items_sorting_direction TEXT DEFAULT "desc"');
}
2015-10-20 03:21:18 +02:00
function version_16(PDO $pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN auth_google_token TEXT DEFAULT ""');
$pdo->exec('ALTER TABLE config ADD COLUMN auth_mozilla_token TEXT DEFAULT ""');
}
2015-10-20 03:21:18 +02:00
function version_15(PDO $pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN download_content INTEGER DEFAULT 0');
}
2015-10-20 03:21:18 +02:00
function version_14(PDO $pdo)
2013-08-10 04:23:57 +02:00
{
$pdo->exec('ALTER TABLE config ADD COLUMN feed_token TEXT DEFAULT "'.Helper\generate_token().'"');
2013-08-10 04:23:57 +02:00
}
2015-10-20 03:21:18 +02:00
function version_13(PDO $pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN enabled INTEGER DEFAULT 1');
}
2015-10-20 03:21:18 +02:00
function version_12(PDO $pdo)
2013-07-28 21:44:51 +02:00
{
$pdo->exec('ALTER TABLE config ADD COLUMN api_token TEXT DEFAULT "'.Helper\generate_token().'"');
2013-07-28 21:44:51 +02:00
}
2015-10-20 03:21:18 +02:00
function version_11(PDO $pdo)
{
$rq = $pdo->prepare('
SELECT
items.id, items.url AS item_url, feeds.site_url
FROM items
LEFT JOIN feeds ON feeds.id=items.feed_id
');
$rq->execute();
2014-10-30 02:28:23 +01:00
$items = $rq->fetchAll(PDO::FETCH_ASSOC);
foreach ($items as $item) {
if ($item['id'] !== $item['item_url']) {
$id = hash('crc32b', $item['id'].$item['site_url']);
2016-04-18 01:44:45 +02:00
} else {
$id = hash('crc32b', $item['item_url'].$item['site_url']);
}
$rq = $pdo->prepare('UPDATE items SET id=? WHERE id=?');
$rq->execute(array($id, $item['id']));
}
}
2015-10-20 03:21:18 +02:00
function version_10(PDO $pdo)
2013-07-17 03:58:11 +02:00
{
$pdo->exec('ALTER TABLE config ADD COLUMN theme TEXT DEFAULT "original"');
}
2015-10-20 03:21:18 +02:00
function version_9(PDO $pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN items_per_page INTEGER DEFAULT 100');
}
2015-10-20 03:21:18 +02:00
function version_8(PDO $pdo)
{
2013-06-15 05:12:08 +02:00
$pdo->exec('ALTER TABLE items ADD COLUMN bookmark INTEGER DEFAULT 0');
}
2015-10-20 03:21:18 +02:00
function version_7(PDO $pdo)
{
2013-06-11 04:09:51 +02:00
$pdo->exec('ALTER TABLE config ADD COLUMN nocontent INTEGER DEFAULT 0');
}
2013-05-26 19:09:34 +02:00
2015-10-20 03:21:18 +02:00
function version_6(PDO $pdo)
{
2013-05-26 19:09:34 +02:00
$pdo->exec('ALTER TABLE config ADD COLUMN autoflush INTEGER DEFAULT 0');
}
2015-10-20 03:21:18 +02:00
function version_5(PDO $pdo)
2013-05-18 20:35:16 +02:00
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN last_checked INTEGER');
}
2015-10-20 03:21:18 +02:00
function version_4(PDO $pdo)
2013-04-23 04:41:20 +02:00
{
2013-06-15 05:12:08 +02:00
$pdo->exec('CREATE INDEX idx_status ON items(status)');
2013-04-23 04:41:20 +02:00
}
2015-10-20 03:21:18 +02:00
function version_3(PDO $pdo)
2013-04-13 03:08:55 +02:00
{
$pdo->exec("ALTER TABLE config ADD COLUMN language TEXT DEFAULT 'en_US'");
}
2015-10-20 03:21:18 +02:00
function version_2(PDO $pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN last_modified TEXT');
$pdo->exec('ALTER TABLE feeds ADD COLUMN etag TEXT');
}
2015-10-20 03:21:18 +02:00
function version_1(PDO $pdo)
2013-02-18 03:48:21 +01:00
{
$pdo->exec("
CREATE TABLE config (
username TEXT DEFAULT 'admin',
password TEXT
2013-02-18 03:48:21 +01:00
)
");
$pdo->exec("
INSERT INTO config
(password)
VALUES ('".\password_hash('admin', PASSWORD_BCRYPT)."')
2013-02-18 03:48:21 +01:00
");
$pdo->exec('
CREATE TABLE feeds (
id INTEGER PRIMARY KEY,
site_url TEXT,
feed_url TEXT UNIQUE,
2013-07-10 03:31:46 +02:00
title TEXT COLLATE NOCASE
2013-02-18 03:48:21 +01:00
)
');
$pdo->exec('
CREATE TABLE items (
id TEXT PRIMARY KEY,
url TEXT,
title TEXT,
author TEXT,
content TEXT,
updated INTEGER,
2013-02-18 03:48:21 +01:00
status TEXT,
feed_id INTEGER,
FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE
)
');
}