Skip to content

Commit

Permalink
Default or custom OPML (FreshRSS#2627)
Browse files Browse the repository at this point in the history
* Default or custom OPML

Fix FreshRSS#2075
Replaces FreshRSS#2515
FreshRSS#2514

Uses the local ./data/opml.xml if it exists, otherwise
./opml.default.xml

* Better message

* Move to controller
  • Loading branch information
Alkarex authored Nov 4, 2019
1 parent 67fc72f commit 7819a43
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 43 deletions.
16 changes: 15 additions & 1 deletion app/Controllers/userController.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,21 @@ public static function createUser($new_user_name, $email, $passwordPlain, $apiPa
}
if ($ok) {
$newUserDAO = FreshRSS_Factory::createUserDao($new_user_name);
$ok &= $newUserDAO->createUser($insertDefaultFeeds);
$ok &= $newUserDAO->createUser();

if ($ok && $insertDefaultFeeds) {
$opmlPath = DATA_PATH . '/opml.xml';
if (!file_exists($opmlPath)) {
$opmlPath = FRESHRSS_PATH . '/opml.default.xml';
}
$importController = new FreshRSS_importExport_Controller();
try {
$importController->importFile($opmlPath, $opmlPath, $new_user_name);
} catch (Exception $e) {
Minz_Log::error('Error while importing default OPML for user ' . $new_user_name . ': ' . $e->getMessage());
}
}

$ok &= self::updateUser($new_user_name, $email, $passwordPlain, $apiPasswordPlain);
}
return $ok;
Expand Down
19 changes: 3 additions & 16 deletions app/Models/UserDAO.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
<?php

class FreshRSS_UserDAO extends Minz_ModelPdo {
public function createUser($insertDefaultFeeds = false) {
public function createUser() {
require(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');

try {
$sql = $SQL_CREATE_TABLES . $SQL_CREATE_TABLE_ENTRYTMP . $SQL_CREATE_TABLE_TAGS;
$ok = $this->pdo->exec($sql) !== false; //Note: Only exec() can take multiple statements safely.
if ($ok && $insertDefaultFeeds) {
$default_feeds = FreshRSS_Context::$system_conf->default_feeds;
$stm = $this->pdo->prepare($SQL_INSERT_FEED);
foreach ($default_feeds as $feed) {
$parameters = [
':url' => $feed['url'],
':name' => $feed['name'],
':website' => $feed['website'],
':description' => $feed['description'],
];
$ok &= ($stm && $stm->execute($parameters));
}
}
} catch (Exception $e) {
Minz_Log::error('Error while creating database for user: ' . $e->getMessage());
Minz_Log::error('Error while creating database for user ' . $this->current_user . ': ' . $e->getMessage());
}

if ($ok) {
return true;
} else {
$info = empty($stm) ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error(__METHOD__ . ' error: ' . $info[2]);
Minz_Log::error(__METHOD__ . ' error: ' . json_encode($info));
return false;
}
}
Expand Down
5 changes: 0 additions & 5 deletions app/SQL/install.sql.mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@
ENGINE = INNODB;
SQL;

$SQL_INSERT_FEED = <<<'SQL'
INSERT IGNORE INTO `_feed` (url, category, name, website, description, ttl)
VALUES(:url, 1, :name, :website, :description, 86400);
SQL;

$SQL_DROP_TABLES = <<<'SQL'
DROP TABLE IF EXISTS `_entrytag`, `_tag`, `_entrytmp`, `_entry`, `_feed`, `_category`;
SQL;
Expand Down
6 changes: 0 additions & 6 deletions app/SQL/install.sql.pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@
CREATE INDEX IF NOT EXISTS `_entrytag_id_entry_index` ON `_entrytag` ("id_entry");
SQL;

$SQL_INSERT_FEED = <<<'SQL'
INSERT INTO `_feed` (url, category, name, website, description, ttl)
SELECT :url::VARCHAR, 1, :name, :website, :description, 86400
WHERE NOT EXISTS (SELECT id FROM `_feed` WHERE url = :url);
SQL;

$SQL_DROP_TABLES = <<<'SQL'
DROP TABLE IF EXISTS `_entrytag`, `_tag`, `_entrytmp`, `_entry`, `_feed`, `_category`;
SQL;
5 changes: 0 additions & 5 deletions app/SQL/install.sql.sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@
CREATE INDEX IF NOT EXISTS entrytag_id_entry_index ON `entrytag` (`id_entry`);
SQL;

$SQL_INSERT_FEED = <<<'SQL'
INSERT OR IGNORE INTO `feed` (url, category, name, website, description, ttl)
VALUES(:url, 1, :name, :website, :description, 86400);
SQL;

$SQL_DROP_TABLES = <<<'SQL'
DROP TABLE IF EXISTS `entrytag`;
DROP TABLE IF EXISTS `tag`;
Expand Down
10 changes: 0 additions & 10 deletions config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,6 @@

],

# Configure the default feeds to which users will automatically be subscribed.
'default_feeds' => array(
array(
'url' => 'https://github.com/FreshRSS/FreshRSS/releases.atom',
'name' => 'FreshRSS releases',
'website' => 'https://github.com/FreshRSS/FreshRSS/',
'description' => 'FreshRSS releases @ GitHub',
),
),

# Configuration to send emails. Be aware that PHP < 5.5 are not supported.
# These options are basically a mapping of the PHPMailer class attributes
# from the PHPMailer library.
Expand Down
14 changes: 14 additions & 0 deletions opml.default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Configure the default feeds to which users will automatically be subscribed.
Do not edit this file but instead create your own ./data/opml.xml
-->
<opml version="2.0">
<head>
<title>FreshRSS default OPML</title>
<dateCreated>Sat, 02 Nov 2019 12:00:00</dateCreated>
</head>
<body>
<outline text="FreshRSS releases" type="rss" xmlUrl="https://github.com/FreshRSS/FreshRSS/releases.atom" htmlUrl="https://github.com/FreshRSS/FreshRSS/" description="FreshRSS releases @ GitHub"/>
</body>
</opml>

0 comments on commit 7819a43

Please sign in to comment.