A free, self-hostable news aggregator…
Default or custom OPML (#2627)
Alexandre Alapetite7819a43197d3
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.phpindex 6afc91b4e..7ce6b298a 100644--- a/app/Controllers/userController.php+++ b/app/Controllers/userController.php@@ -248,7 +248,21 @@ class FreshRSS_user_Controller extends Minz_ActionController {}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;diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.phpindex 4e824cf01..266c8bc0e 100644--- a/app/Models/UserDAO.php+++ b/app/Models/UserDAO.php@@ -1,34 +1,21 @@<?phpclass 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;}}diff --git a/app/SQL/install.sql.mysql.php b/app/SQL/install.sql.mysql.phpindex 1eabfae8b..f8972b186 100644--- a/app/SQL/install.sql.mysql.php+++ b/app/SQL/install.sql.mysql.php@@ -112,11 +112,6 @@ CREATE TABLE IF NOT EXISTS `_entrytag` ( -- v1.12ENGINE = 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;diff --git a/app/SQL/install.sql.pgsql.php b/app/SQL/install.sql.pgsql.phpindex 53afc8a17..c17a45127 100644--- a/app/SQL/install.sql.pgsql.php+++ b/app/SQL/install.sql.pgsql.php@@ -100,12 +100,6 @@ CREATE TABLE IF NOT EXISTS `_entrytag` (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;diff --git a/app/SQL/install.sql.sqlite.php b/app/SQL/install.sql.sqlite.phpindex 2a4763637..ff7c03354 100644--- a/app/SQL/install.sql.sqlite.php+++ b/app/SQL/install.sql.sqlite.php@@ -102,11 +102,6 @@ CREATE TABLE IF NOT EXISTS `entrytag` (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`;diff --git a/config.default.php b/config.default.phpindex d885a8dea..71f8d477c 100644--- a/config.default.php+++ b/config.default.php@@ -156,16 +156,6 @@ return array(],- # 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.diff --git a/opml.default.xml b/opml.default.xmlnew file mode 100644index 000000000..5814869b5--- /dev/null+++ b/opml.default.xml@@ -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>