From c277e15141b99cdcb392f4a32126757d58b44423 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 2 Nov 2019 13:38:04 +0100 Subject: Git fetch+reset instead of clean+fetch+merge (#2625) Fix https://github.com/FreshRSS/FreshRSS/issues/2619 Avoid potentially dangerous git clean, and use more robust fetch + reset strategy instead --- app/Controllers/updateController.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index ebe5e4cc8..cc3aef9fd 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -29,20 +29,22 @@ class FreshRSS_update_Controller extends Minz_ActionController { public static function gitPull() { $cwd = getcwd(); chdir(FRESHRSS_PATH); - $output = array(); + $output = ''; $return = 1; try { - exec('git clean -f -d -f', $output, $return); + exec('git fetch', $output, $return); if ($return == 0) { - exec('git pull --ff-only', $output, $return); - } else { - $line = is_array($output) ? implode('; ', $output) : '' . $output; - Minz_Log::warning('git clean warning:' . $line); + exec('git reset --hard FETCH_HEAD', $output, $return); } } catch (Exception $e) { - Minz_Log::warning('git pull error:' . $e->getMessage()); + Minz_Log::warning('Git error:' . $e->getMessage()); + if ($output == '') { + $output = $e->getMessage(); + } + $return = 1; } chdir($cwd); + deleteInstall(); $line = is_array($output) ? implode('; ', $output) : '' . $output; return $return == 0 ? true : 'Git error: ' . $line; } @@ -52,6 +54,8 @@ class FreshRSS_update_Controller extends Minz_ActionController { Minz_Error::error(403); } + include_once(LIB_PATH . '/lib_install.php'); + invalidateHttpCache(); $this->view->update_to_apply = false; -- cgit v1.2.3 From 7819a43197d34ef7a6c5626e9e48d7db075c37c9 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 4 Nov 2019 17:45:15 +0100 Subject: Default or custom OPML (#2627) * Default or custom OPML Fix https://github.com/FreshRSS/FreshRSS/issues/2075 Replaces https://github.com/FreshRSS/FreshRSS/pull/2515 https://github.com/FreshRSS/FreshRSS/issues/2514 Uses the local ./data/opml.xml if it exists, otherwise ./opml.default.xml * Better message * Move to controller --- app/Controllers/userController.php | 16 +++++++++++++++- app/Models/UserDAO.php | 19 +++---------------- app/SQL/install.sql.mysql.php | 5 ----- app/SQL/install.sql.pgsql.php | 6 ------ app/SQL/install.sql.sqlite.php | 5 ----- config.default.php | 10 ---------- opml.default.xml | 14 ++++++++++++++ 7 files changed, 32 insertions(+), 43 deletions(-) create mode 100644 opml.default.xml (limited to 'app/Controllers') diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index 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.php index 4e824cf01..266c8bc0e 100644 --- a/app/Models/UserDAO.php +++ b/app/Models/UserDAO.php @@ -1,34 +1,21 @@ 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.php index 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.12 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; diff --git a/app/SQL/install.sql.pgsql.php b/app/SQL/install.sql.pgsql.php index 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.php index 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.php index 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.xml new file mode 100644 index 000000000..5814869b5 --- /dev/null +++ b/opml.default.xml @@ -0,0 +1,14 @@ + + + + + FreshRSS default OPML + Sat, 02 Nov 2019 12:00:00 + + + + + -- cgit v1.2.3 From 2495172a05725684fa4db2ed3417461d386c5cbf Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 4 Nov 2019 18:05:20 +0100 Subject: Better git fetch (#2626) Related to https://github.com/FreshRSS/FreshRSS/pull/2625 If for some reasons branches have diverged:, e.g.: ``` $ git status -sb --porcelain remote ## dev...origin/dev [ahead 4, behind 1] ``` --- app/Controllers/updateController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/Controllers') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index cc3aef9fd..c0c1ef1c8 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -23,7 +23,7 @@ class FreshRSS_update_Controller extends Minz_ActionController { } chdir($cwd); $line = is_array($output) ? implode('; ', $output) : '' . $output; - return strpos($line, '[behind') !== false; + return strpos($line, '[behind') !== false || strpos($line, '[ahead') !== false; } public static function gitPull() { -- cgit v1.2.3