Просмотр исходного кода

Merge pull request #1447 from Alkarex/CLI-bugs

Fix CLI bugs
Alexandre Alapetite 9 лет назад
Родитель
Сommit
6bbe89e9bc

+ 6 - 0
CHANGELOG.md

@@ -8,13 +8,19 @@
 	* Share with GNU social [#1422](https://github.com/FreshRSS/FreshRSS/issues/1422)
 * CLI
 	* New command `./cli/reconfigure.php` to update an existing installation [#1439](https://github.com/FreshRSS/FreshRSS/pull/1439)
+	* Many CLI improvements [#1447](https://github.com/FreshRSS/FreshRSS/pull/1447)
+		* More information (number of feeds, articles, etc.) in `./cli/user-info.php`
+		* Better idempotency of `./cli/do-install.php` and language parameter [#1449](https://github.com/FreshRSS/FreshRSS/issues/1449) 
 * UI
 	* New theme *Origine-compact* [#1388](https://github.com/FreshRSS/FreshRSS/pull/1388)
 	* Chrome parity with Firefox: auto-focus tab when clicking on notification [#1409](https://github.com/FreshRSS/FreshRSS/pull/1409)
 * Bug fixing
 	* Fix PostgreSQL bugs with API and feed modifications [#1417](https://github.com/FreshRSS/FreshRSS/pull/1417)
+	* Fix several CLI issues [#1445](https://github.com/FreshRSS/FreshRSS/issues/1445)
+		* Fix CLI install bugs with SQLite [#1443](https://github.com/FreshRSS/FreshRSS/issues/1443), [#1448](https://github.com/FreshRSS/FreshRSS/issues/1448)
 	* Allow empty strings in CLI do-install [#1435](https://github.com/FreshRSS/FreshRSS/pull/1435)
 	* Do not mark as read in anonymous mode [#1431](https://github.com/FreshRSS/FreshRSS/issues/1431)
+	* Fix Favicons warning [#59dfc64](https://github.com/FreshRSS/FreshRSS/pull/1447/commits/59dfc64512372eaba7609d84500d943bb7274399)
 * Security
 	* Sanitize feed Web site URL [#1434](https://github.com/FreshRSS/FreshRSS/issues/1434)
 	* No version number for anonymous users [#1404](https://github.com/FreshRSS/FreshRSS/issues/1404)

+ 5 - 2
app/Controllers/userController.php

@@ -115,6 +115,7 @@ class FreshRSS_user_Controller extends Minz_ActionController {
 		}
 
 		$ok = self::checkUsername($new_user_name);
+		$homeDir = join_path(DATA_PATH, 'users', $new_user_name);
 
 		if ($ok) {
 			$languages = Minz_Translate::availableLanguages();
@@ -124,7 +125,7 @@ class FreshRSS_user_Controller extends Minz_ActionController {
 
 			$ok &= !in_array(strtoupper($new_user_name), array_map('strtoupper', listUsers()));	//Not an existing user, case-insensitive
 
-			$configPath = join_path(DATA_PATH, 'users', $new_user_name, 'config.php');
+			$configPath = join_path($homeDir, 'config.php');
 			$ok &= !file_exists($configPath);
 		}
 		if ($ok) {
@@ -141,7 +142,9 @@ class FreshRSS_user_Controller extends Minz_ActionController {
 			}
 		}
 		if ($ok) {
-			mkdir(join_path(DATA_PATH, 'users', $new_user_name));
+			if (!is_dir($homeDir)) {
+				mkdir($homeDir);
+			}
 			$userConfig['passwordHash'] = $passwordHash;
 			$userConfig['apiPasswordHash'] = $apiPasswordHash;
 			$ok &= (file_put_contents($configPath, "<?php\n return " . var_export($userConfig, true) . ';') !== false);

+ 4 - 2
cli/README.md

@@ -32,10 +32,11 @@ Options in parenthesis are optional.
 ```sh
 cd /usr/share/FreshRSS
 
-./cli/do-install.php --default_user admin ( --auth_type form --environment production --base_url https://rss.example.net/ --title FreshRSS --allow_anonymous --api_enabled --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123 --db-base freshrss --db-prefix freshrss )
+./cli/do-install.php --default_user admin ( --auth_type form --environment production --base_url https://rss.example.net/ --language en --title FreshRSS --allow_anonymous --api_enabled --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123 --db-base freshrss --db-prefix freshrss )
 # --auth_type can be: 'form' (default), 'http_auth' (using the Web server access control), 'none' (dangerous)
 # --db-type can be: 'sqlite' (default), 'mysql' (MySQL or MariaDB), 'pgsql' (PostgreSQL)
 # --environment can be: 'production' (default), 'development' (for additional log messages)
+# --language can be: 'en' (default), 'fr', or one of the [supported languages](../app/i18n/)
 # --db-prefix is an optional prefix in front of the names of the tables. We suggest using 'freshrss_'
 # This command does not create the default user. Do that with ./cli/create-user.php
 
@@ -62,7 +63,8 @@ cd /usr/share/FreshRSS
 ./cli/user-info.php -h --user username
 # -h is to use a human-readable format
 # --user can be a username, or '*' to loop on all users
-# Returns a * if the user is admin, the name of the user, the date/time of last action, and the size occupied
+# Returns a * if the user is admin, the name of the user, the date/time of last action, the size occupied,
+#  and the number of: feeds, read articles, unread articles, and favourites
 ```
 
 

+ 6 - 1
cli/do-install.php

@@ -3,9 +3,14 @@
 require('_cli.php');
 require(LIB_PATH . '/lib_install.php');
 
+if (!file_exists(DATA_PATH . '/do-install.txt')) {
+	fail('FreshRSS looks to be already installed! Please use `./cli/reconfigure.php` instead.');
+}
+
 $params = array(
 		'environment:',
 		'base_url:',
+		'language:',
 		'title:',
 		'default_user:',
 		'allow_anonymous',
@@ -30,7 +35,7 @@ $options = getopt('', array_merge($params, $dBparams));
 if (empty($options['default_user'])) {
 	fail('Usage: ' . basename(__FILE__) . " --default_user admin ( --auth_type form" .
 		" --environment production --base_url https://rss.example.net/" .
-		" --title FreshRSS --allow_anonymous --api_enabled" .
+		" --language en --title FreshRSS --allow_anonymous --api_enabled" .
 		" --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123" .
 		" --db-base freshrss --db-prefix freshrss_ --disable_update )");
 }

+ 1 - 1
cli/list-users.php

@@ -4,7 +4,7 @@ require('_cli.php');
 
 $users = listUsers();
 sort($users);
-if (FreshRSS_Context::$system_conf->default_user !== '') {
+if (FreshRSS_Context::$system_conf->default_user !== '' && in_array(FreshRSS_Context::$system_conf->default_user, $users, true)) {
 	array_unshift($users, FreshRSS_Context::$system_conf->default_user);
 	$users = array_unique($users);
 }

+ 1 - 0
cli/reconfigure.php

@@ -5,6 +5,7 @@ require('_cli.php');
 $params = array(
 		'environment:',
 		'base_url:',
+		'language:',
 		'title:',
 		'default_user:',
 		'allow_anonymous',

+ 15 - 1
cli/user-info.php

@@ -14,22 +14,36 @@ $users = $options['user'] === '*' ? listUsers() : array($options['user']);
 
 foreach ($users as $username) {
 	$username = cliInitUser($username);
+	echo $username === FreshRSS_Context::$system_conf->default_user ? '*' : ' ', "\t";
 
+	$catDAO = new FreshRSS_CategoryDAO();
+	$feedDAO = FreshRSS_Factory::createFeedDao($username);
 	$entryDAO = FreshRSS_Factory::createEntryDao($username);
 
-	echo $username === FreshRSS_Context::$system_conf->default_user ? '*' : ' ', "\t";
+	$nbEntries = $entryDAO->countUnreadRead();
+	$nbFavorites = $entryDAO->countUnreadReadFavorites();
 
 	if (isset($options['h'])) {	//Human format
 		echo
 			$username, "\t",
 			date('c', FreshRSS_UserDAO::mtime($username)), "\t",
 			format_bytes($entryDAO->size()), "\t",
+			$catDAO->count(), " categories\t",
+			count($feedDAO->listFeedsIds()), " feeds\t",
+			$nbEntries['read'], " reads\t",
+			$nbEntries['unread'], " unreads\t",
+			$nbFavorites['all'], " favourites\t",
 			"\n";
 	} else {
 		echo
 			$username, "\t",
 			FreshRSS_UserDAO::mtime($username), "\t",
 			$entryDAO->size(), "\t",
+			$catDAO->count(), "\t",
+			count($feedDAO->listFeedsIds()), "\t",
+			$nbEntries['read'], "\t",
+			$nbEntries['unread'], "\t",
+			$nbFavorites['all'], "\t",
 			"\n";
 	}
 }

+ 26 - 26
lib/Favicon/DataAccess.php

@@ -9,33 +9,33 @@ namespace Favicon;
  **/
 class DataAccess {
 	public function retrieveUrl($url) {
-	    $this->set_context();
-	    return @file_get_contents($url);
+		$this->set_context();
+		return @file_get_contents($url);
 	}
-	
+
 	public function retrieveHeader($url) {
-	    $this->set_context();
+		$this->set_context();
 		$headers = @get_headers($url, 1);
-		return $headers ? array_change_key_case($headers) : array();
+		return is_array($headers) ? array_change_key_case($headers) : array();
+	}
+
+	public function saveCache($file, $data) {
+		file_put_contents($file, $data);
+	}
+
+	public function readCache($file) {
+		return file_get_contents($file);
+	}
+
+	private function set_context() {
+		stream_context_set_default(
+			array(
+				'http' => array(
+					'method' => 'GET',
+					'timeout' => 10,
+					'header' => "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:20.0; Favicon; +https://github.com/ArthurHoaro/favicon) Gecko/20100101 Firefox/32.0\r\n",
+				)
+			)
+		);
 	}
-	
-    public function saveCache($file, $data) {
-        file_put_contents($file, $data);
-    }
-    
-    public function readCache($file) {
-    	return file_get_contents($file);
-    }
-    
-    private function set_context() {
-        stream_context_set_default(
-            array(
-                'http' => array(
-                    'method' => 'GET',
-                    'timeout' => 10,
-                    'header' => "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:20.0; Favicon; +https://github.com/ArthurHoaro/favicon) Gecko/20100101 Firefox/32.0\r\n",
-                )
-            )
-        );
-    }
-}
+}

+ 1 - 3
lib/lib_rss.php

@@ -299,13 +299,11 @@ function listUsers() {
 		scandir($base_path),
 		array('..', '.', '_')
 	));
-
 	foreach ($dir_list as $file) {
-		if (is_dir(join_path($base_path, $file))) {
+		if ($file[0] !== '.' && is_dir(join_path($base_path, $file)) && file_exists(join_path($base_path, $file, 'config.php'))) {
 			$final_list[] = $file;
 		}
 	}
-
 	return $final_list;
 }