From f632a346269100d6a93bef318ffa66c97f16f6fa Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 12 Oct 2017 20:11:06 +0200 Subject: CLI optimize database (#1663) CLI optimize database https://github.com/FreshRSS/FreshRSS/issues/1583 And VACUUM in SQLite https://github.com/FreshRSS/FreshRSS/issues/918 Add VACUUM for PostgreSQL (Not tested yet) --- cli/README.md | 3 +++ cli/db-optimize.php | 20 ++++++++++++++++++++ cli/user-info.php | 5 +++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100755 cli/db-optimize.php (limited to 'cli') diff --git a/cli/README.md b/cli/README.md index ce1be10a7..6f907566c 100644 --- a/cli/README.md +++ b/cli/README.md @@ -69,6 +69,9 @@ cd /usr/share/FreshRSS # Returns: 1) a * iff the user is admin, 2) the name of the user, # 3) the date/time of last user action, 4) the size occupied, # and the number of: 5) categories, 6) feeds, 7) read articles, 8) unread articles, and 9) favourites + +./cli/db-optimize.php --user username +# Optimize database (reduces the size) for a given user (perform `OPTIMIZE TABLE` in MySQL, `VACUUM` in SQLite) ``` diff --git a/cli/db-optimize.php b/cli/db-optimize.php new file mode 100755 index 000000000..83123a669 --- /dev/null +++ b/cli/db-optimize.php @@ -0,0 +1,20 @@ +#!/usr/bin/php +optimize(); + +done($ok); diff --git a/cli/user-info.php b/cli/user-info.php index aa3e239b8..41b95cbf3 100755 --- a/cli/user-info.php +++ b/cli/user-info.php @@ -19,6 +19,7 @@ foreach ($users as $username) { $catDAO = new FreshRSS_CategoryDAO(); $feedDAO = FreshRSS_Factory::createFeedDao($username); $entryDAO = FreshRSS_Factory::createEntryDao($username); + $databaseDAO = FreshRSS_Factory::createDatabaseDAO($username); $nbEntries = $entryDAO->countUnreadRead(); $nbFavorites = $entryDAO->countUnreadReadFavorites(); @@ -27,7 +28,7 @@ foreach ($users as $username) { echo $username, "\t", date('c', FreshRSS_UserDAO::mtime($username)), "\t", - format_bytes($entryDAO->size()), "\t", + format_bytes($databaseDAO->size()), "\t", $catDAO->count(), " categories\t", count($feedDAO->listFeedsIds()), " feeds\t", $nbEntries['read'], " reads\t", @@ -38,7 +39,7 @@ foreach ($users as $username) { echo $username, "\t", FreshRSS_UserDAO::mtime($username), "\t", - $entryDAO->size(), "\t", + $databaseDAO->size(), "\t", $catDAO->count(), "\t", count($feedDAO->listFeedsIds()), "\t", $nbEntries['read'], "\t", -- cgit v1.2.3 From 05b1901fcdbb051077d12f776980484d3b782970 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sat, 4 Nov 2017 21:17:08 +0100 Subject: Move translation tools into the cli folder (#1673) Translation tools must be used on cli. It is better to have them in the cli folder. --- .travis.yml | 2 +- cli/check.translation.php | 106 +++++++++++++++++++++++++++++++ cli/i18n/I18nCompletionValidator.php | 49 +++++++++++++++ cli/i18n/I18nData.php | 118 +++++++++++++++++++++++++++++++++++ cli/i18n/I18nFile.php | 92 +++++++++++++++++++++++++++ cli/i18n/I18nUsageValidator.php | 47 ++++++++++++++ cli/i18n/I18nValidatorInterface.php | 26 ++++++++ cli/i18n/ignore/en.php | 105 +++++++++++++++++++++++++++++++ cli/i18n/ignore/fr.php | 55 ++++++++++++++++ cli/manipulate.translation.php | 79 +++++++++++++++++++++++ tools/I18nCompletionValidator.php | 49 --------------- tools/I18nData.php | 118 ----------------------------------- tools/I18nFile.php | 92 --------------------------- tools/I18nUsageValidator.php | 47 -------------- tools/I18nValidatorInterface.php | 26 -------- tools/check.translation.php | 106 ------------------------------- tools/ignore/en.php | 105 ------------------------------- tools/ignore/fr.php | 55 ---------------- tools/manipulate.translation.php | 79 ----------------------- 19 files changed, 678 insertions(+), 678 deletions(-) create mode 100644 cli/check.translation.php create mode 100644 cli/i18n/I18nCompletionValidator.php create mode 100644 cli/i18n/I18nData.php create mode 100644 cli/i18n/I18nFile.php create mode 100644 cli/i18n/I18nUsageValidator.php create mode 100644 cli/i18n/I18nValidatorInterface.php create mode 100644 cli/i18n/ignore/en.php create mode 100644 cli/i18n/ignore/fr.php create mode 100644 cli/manipulate.translation.php delete mode 100644 tools/I18nCompletionValidator.php delete mode 100644 tools/I18nData.php delete mode 100644 tools/I18nFile.php delete mode 100644 tools/I18nUsageValidator.php delete mode 100644 tools/I18nValidatorInterface.php delete mode 100644 tools/check.translation.php delete mode 100644 tools/ignore/en.php delete mode 100644 tools/ignore/fr.php delete mode 100644 tools/manipulate.translation.php (limited to 'cli') diff --git a/.travis.yml b/.travis.yml index 945e77a74..7bfefd8ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ script: fi - | if [[ $CHECK_TRANSLATION == yes ]]; then - php tools/check.translation.php -r + php cli/check.translation.php -r fi env: diff --git a/cli/check.translation.php b/cli/check.translation.php new file mode 100644 index 000000000..6ebd12973 --- /dev/null +++ b/cli/check.translation.php @@ -0,0 +1,106 @@ +load(); + +$options = getopt("dhl:r"); + +if (array_key_exists('h', $options)) { + help(); +} +if (array_key_exists('l', $options)) { + $languages = array($options['l']); +} else { + $languages = $i18nData->getAvailableLanguages(); +} +$displayResults = array_key_exists('d', $options); +$displayReport = array_key_exists('r', $options); + +$isValidated = true; +$result = array(); +$report = array(); + +foreach ($languages as $language) { + if ($language === $i18nData::REFERENCE_LANGUAGE) { + $i18nValidator = new I18nUsageValidator($i18nData->getReferenceLanguage(), findUsedTranslations()); + $isValidated = $i18nValidator->validate(include __DIR__ . '/i18n/ignore/' . $language . '.php') && $isValidated; + } else { + $i18nValidator = new I18nCompletionValidator($i18nData->getReferenceLanguage(), $i18nData->getLanguage($language)); + if (file_exists(__DIR__ . '/i18n/ignore/' . $language . '.php')) { + $isValidated = $i18nValidator->validate(include __DIR__ . '/i18n/ignore/' . $language . '.php') && $isValidated; + } else { + $isValidated = $i18nValidator->validate(null) && $isValidated; + } + } + + $report[$language] = sprintf('%-5s - %s', $language, $i18nValidator->displayReport()); + $result[$language] = $i18nValidator->displayResult(); +} + +if ($displayResults) { + foreach ($result as $lang => $value) { + echo 'Language: ', $lang, PHP_EOL; + print_r($value); + echo PHP_EOL; + } +} + +if ($displayReport) { + foreach ($report as $value) { + echo $value; + } +} + +if (!$isValidated) { + exit(1); +} + +/** + * Find used translation keys in the project + * + * Iterates through all php and phtml files in the whole project and extracts all + * translation keys used. + * + * @return array + */ +function findUsedTranslations() { + $directory = new RecursiveDirectoryIterator(__DIR__ . '/..'); + $iterator = new RecursiveIteratorIterator($directory); + $regex = new RegexIterator($iterator, '/^.+\.(php|phtml)$/i', RecursiveRegexIterator::GET_MATCH); + $usedI18n = array(); + foreach (array_keys(iterator_to_array($regex)) as $file) { + $fileContent = file_get_contents($file); + preg_match_all('/_t\([\'"](?P[^\'"]+)[\'"]/', $fileContent, $matches); + $usedI18n = array_merge($usedI18n, $matches['strings']); + } + return $usedI18n; +} + +/** + * Output help message. + */ +function help() { + $help = <<reference = $reference; + $this->language = $language; + } + + public function displayReport() { + return sprintf('Translation is %5.1f%% complete.', $this->passEntries / $this->totalEntries * 100) . PHP_EOL; + } + + public function displayResult() { + return $this->result; + } + + public function validate($ignore) { + foreach ($this->reference as $file => $data) { + foreach ($data as $key => $value) { + $this->totalEntries++; + if (is_array($ignore) && in_array($key, $ignore)) { + $this->passEntries++; + continue; + } + if (!array_key_exists($key, $this->language[$file])) { + $this->result .= sprintf('Missing key %s', $key) . PHP_EOL; + continue; + } + if ($value === $this->language[$file][$key]) { + $this->result .= sprintf('Untranslated key %s - %s', $key, $value) . PHP_EOL; + continue; + } + $this->passEntries++; + } + } + + return $this->totalEntries === $this->passEntries; + } + +} diff --git a/cli/i18n/I18nData.php b/cli/i18n/I18nData.php new file mode 100644 index 000000000..cd8ba0765 --- /dev/null +++ b/cli/i18n/I18nData.php @@ -0,0 +1,118 @@ +data = $data; + $this->originalData = $data; + } + + public function getData() { + return $this->data; + } + + /** + * Return the available languages + * + * @return array + */ + public function getAvailableLanguages() { + $languages = array_keys($this->data); + sort($languages); + + return $languages; + } + + /** + * Add a new language. It's a copy of the reference language. + * + * @param string $language + */ + public function addLanguage($language) { + if (array_key_exists($language, $this->data)) { + throw new Exception('The selected language already exist.'); + } + $this->data[$language] = $this->data[static::REFERENCE_LANGUAGE]; + } + + /** + * Add a key in the reference language + * + * @param string $key + * @param string $value + */ + public function addKey($key, $value) { + if (array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { + throw new Exception('The selected key already exist.'); + } + $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)][$key] = $value; + } + + /** + * Duplicate a key from the reference language to all other languages + * + * @param string $key + */ + public function duplicateKey($key) { + if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { + throw new Exception('The selected key does not exist.'); + } + $value = $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)][$key]; + foreach ($this->getAvailableLanguages() as $language) { + if (static::REFERENCE_LANGUAGE === $language) { + continue; + } + if (array_key_exists($key, $this->data[$language][$this->getFilenamePrefix($key)])) { + throw new Exception(sprintf('The selected key already exist in %s.', $language)); + } + $this->data[$language][$this->getFilenamePrefix($key)][$key] = $value; + } + } + + /** + * Remove a key in all languages + * + * @param string $key + */ + public function removeKey($key) { + if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { + throw new Exception('The selected key does not exist.'); + } + foreach ($this->getAvailableLanguages() as $language) { + if (array_key_exists($key, $this->data[$language][$this->getFilenamePrefix($key)])) { + unset($this->data[$language][$this->getFilenamePrefix($key)][$key]); + } + } + } + + /** + * Check if the data has changed + * + * @return bool + */ + public function hasChanged() { + return $this->data !== $this->originalData; + } + + public function getLanguage($language) { + return $this->data[$language]; + } + + public function getReferenceLanguage() { + return $this->getLanguage(static::REFERENCE_LANGUAGE); + } + + /** + * @param string $key + * @return string + */ + private function getFilenamePrefix($key) { + return preg_replace('/\..*/', '.php', $key); + } + +} diff --git a/cli/i18n/I18nFile.php b/cli/i18n/I18nFile.php new file mode 100644 index 000000000..d6489ee21 --- /dev/null +++ b/cli/i18n/I18nFile.php @@ -0,0 +1,92 @@ +i18nPath = __DIR__ . '/../../app/i18n'; + } + + public function load() { + $dirs = new DirectoryIterator($this->i18nPath); + foreach ($dirs as $dir) { + if ($dir->isDot()) { + continue; + } + $files = new DirectoryIterator($dir->getPathname()); + foreach ($files as $file) { + if (!$file->isFile()) { + continue; + } + $i18n[$dir->getFilename()][$file->getFilename()] = $this->flatten(include $file->getPathname(), $file->getBasename('.php')); + } + } + + return new I18nData($i18n); + } + + public function dump(I18nData $i18n) { + foreach ($i18n->getData() as $language => $file) { + $dir = $this->i18nPath . DIRECTORY_SEPARATOR . $language; + if (!file_exists($dir)) { + mkdir($dir); + } + foreach ($file as $name => $content) { + $filename = $dir . DIRECTORY_SEPARATOR . $name; + $fullContent = var_export($this->unflatten($content), true); + file_put_contents($filename, sprintf(' $value) { + if (is_array($value)) { + $a += $this->flatten($value, $prefix . $key); + } else { + $a[$prefix . $key] = $value; + } + } + + return $a; + } + + /** + * Unflatten an array of translation + * + * The first key is dropped since it represents the filename and we have + * no use of it. + * + * @param array $translation + * @return array + */ + private function unflatten($translation) { + $a = array(); + + ksort($translation); + foreach ($translation as $compoundKey => $value) { + $keys = explode('.', $compoundKey); + array_shift($keys); + eval("\$a['" . implode("']['", $keys) . "'] = '" . $value . "';"); + } + + return $a; + } + +} diff --git a/cli/i18n/I18nUsageValidator.php b/cli/i18n/I18nUsageValidator.php new file mode 100644 index 000000000..8ab934971 --- /dev/null +++ b/cli/i18n/I18nUsageValidator.php @@ -0,0 +1,47 @@ +code = $code; + $this->reference = $reference; + } + + public function displayReport() { + return sprintf('%5.1f%% of translation keys are unused.', $this->failedEntries / $this->totalEntries * 100) . PHP_EOL; + } + + public function displayResult() { + return $this->result; + } + + public function validate($ignore) { + foreach ($this->reference as $file => $data) { + foreach ($data as $key => $value) { + $this->totalEntries++; + if (preg_match('/\._$/', $key) && in_array(preg_replace('/\._$/', '', $key), $this->code)) { + continue; + } + if (is_array($ignore) && in_array($key, $ignore)) { + continue; + } + if (!in_array($key, $this->code)) { + $this->result .= sprintf('Unused key %s - %s', $key, $value) . PHP_EOL; + $this->failedEntries++; + continue; + } + } + } + + return 0 === $this->failedEntries; + } + +} diff --git a/cli/i18n/I18nValidatorInterface.php b/cli/i18n/I18nValidatorInterface.php new file mode 100644 index 000000000..edfe7aac0 --- /dev/null +++ b/cli/i18n/I18nValidatorInterface.php @@ -0,0 +1,26 @@ +load(); + +switch ($argv[1]) { + case 'add_language' : + $i18nData->addLanguage($argv[2]); + break; + case 'add_key' : + if (3 === $argc) { + help(); + } + $i18nData->addKey($argv[2], $argv[3]); + break; + case 'duplicate_key' : + $i18nData->duplicateKey($argv[2]); + break; + case 'delete_key' : + $i18nData->removeKey($argv[2]); + break; + default : + help(); +} + +if ($i18nData->hasChanged()) { + $i18nFile->dump($i18nData); +} + +/** + * Output help message. + */ +function help() { + $help = <<reference = $reference; - $this->language = $language; - } - - public function displayReport() { - return sprintf('Translation is %5.1f%% complete.', $this->passEntries / $this->totalEntries * 100) . PHP_EOL; - } - - public function displayResult() { - return $this->result; - } - - public function validate($ignore) { - foreach ($this->reference as $file => $data) { - foreach ($data as $key => $value) { - $this->totalEntries++; - if (is_array($ignore) && in_array($key, $ignore)) { - $this->passEntries++; - continue; - } - if (!array_key_exists($key, $this->language[$file])) { - $this->result .= sprintf('Missing key %s', $key) . PHP_EOL; - continue; - } - if ($value === $this->language[$file][$key]) { - $this->result .= sprintf('Untranslated key %s - %s', $key, $value) . PHP_EOL; - continue; - } - $this->passEntries++; - } - } - - return $this->totalEntries === $this->passEntries; - } - -} diff --git a/tools/I18nData.php b/tools/I18nData.php deleted file mode 100644 index cd8ba0765..000000000 --- a/tools/I18nData.php +++ /dev/null @@ -1,118 +0,0 @@ -data = $data; - $this->originalData = $data; - } - - public function getData() { - return $this->data; - } - - /** - * Return the available languages - * - * @return array - */ - public function getAvailableLanguages() { - $languages = array_keys($this->data); - sort($languages); - - return $languages; - } - - /** - * Add a new language. It's a copy of the reference language. - * - * @param string $language - */ - public function addLanguage($language) { - if (array_key_exists($language, $this->data)) { - throw new Exception('The selected language already exist.'); - } - $this->data[$language] = $this->data[static::REFERENCE_LANGUAGE]; - } - - /** - * Add a key in the reference language - * - * @param string $key - * @param string $value - */ - public function addKey($key, $value) { - if (array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { - throw new Exception('The selected key already exist.'); - } - $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)][$key] = $value; - } - - /** - * Duplicate a key from the reference language to all other languages - * - * @param string $key - */ - public function duplicateKey($key) { - if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { - throw new Exception('The selected key does not exist.'); - } - $value = $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)][$key]; - foreach ($this->getAvailableLanguages() as $language) { - if (static::REFERENCE_LANGUAGE === $language) { - continue; - } - if (array_key_exists($key, $this->data[$language][$this->getFilenamePrefix($key)])) { - throw new Exception(sprintf('The selected key already exist in %s.', $language)); - } - $this->data[$language][$this->getFilenamePrefix($key)][$key] = $value; - } - } - - /** - * Remove a key in all languages - * - * @param string $key - */ - public function removeKey($key) { - if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { - throw new Exception('The selected key does not exist.'); - } - foreach ($this->getAvailableLanguages() as $language) { - if (array_key_exists($key, $this->data[$language][$this->getFilenamePrefix($key)])) { - unset($this->data[$language][$this->getFilenamePrefix($key)][$key]); - } - } - } - - /** - * Check if the data has changed - * - * @return bool - */ - public function hasChanged() { - return $this->data !== $this->originalData; - } - - public function getLanguage($language) { - return $this->data[$language]; - } - - public function getReferenceLanguage() { - return $this->getLanguage(static::REFERENCE_LANGUAGE); - } - - /** - * @param string $key - * @return string - */ - private function getFilenamePrefix($key) { - return preg_replace('/\..*/', '.php', $key); - } - -} diff --git a/tools/I18nFile.php b/tools/I18nFile.php deleted file mode 100644 index d8c16a6eb..000000000 --- a/tools/I18nFile.php +++ /dev/null @@ -1,92 +0,0 @@ -i18nPath = __DIR__ . '/../app/i18n'; - } - - public function load() { - $dirs = new DirectoryIterator($this->i18nPath); - foreach ($dirs as $dir) { - if ($dir->isDot()) { - continue; - } - $files = new DirectoryIterator($dir->getPathname()); - foreach ($files as $file) { - if (!$file->isFile()) { - continue; - } - $i18n[$dir->getFilename()][$file->getFilename()] = $this->flatten(include $file->getPathname(), $file->getBasename('.php')); - } - } - - return new I18nData($i18n); - } - - public function dump(I18nData $i18n) { - foreach ($i18n->getData() as $language => $file) { - $dir = $this->i18nPath . DIRECTORY_SEPARATOR . $language; - if (!file_exists($dir)) { - mkdir($dir); - } - foreach ($file as $name => $content) { - $filename = $dir . DIRECTORY_SEPARATOR . $name; - $fullContent = var_export($this->unflatten($content), true); - file_put_contents($filename, sprintf(' $value) { - if (is_array($value)) { - $a += $this->flatten($value, $prefix . $key); - } else { - $a[$prefix . $key] = $value; - } - } - - return $a; - } - - /** - * Unflatten an array of translation - * - * The first key is dropped since it represents the filename and we have - * no use of it. - * - * @param array $translation - * @return array - */ - private function unflatten($translation) { - $a = array(); - - ksort($translation); - foreach ($translation as $compoundKey => $value) { - $keys = explode('.', $compoundKey); - array_shift($keys); - eval("\$a['" . implode("']['", $keys) . "'] = '" . $value . "';"); - } - - return $a; - } - -} diff --git a/tools/I18nUsageValidator.php b/tools/I18nUsageValidator.php deleted file mode 100644 index 8ab934971..000000000 --- a/tools/I18nUsageValidator.php +++ /dev/null @@ -1,47 +0,0 @@ -code = $code; - $this->reference = $reference; - } - - public function displayReport() { - return sprintf('%5.1f%% of translation keys are unused.', $this->failedEntries / $this->totalEntries * 100) . PHP_EOL; - } - - public function displayResult() { - return $this->result; - } - - public function validate($ignore) { - foreach ($this->reference as $file => $data) { - foreach ($data as $key => $value) { - $this->totalEntries++; - if (preg_match('/\._$/', $key) && in_array(preg_replace('/\._$/', '', $key), $this->code)) { - continue; - } - if (is_array($ignore) && in_array($key, $ignore)) { - continue; - } - if (!in_array($key, $this->code)) { - $this->result .= sprintf('Unused key %s - %s', $key, $value) . PHP_EOL; - $this->failedEntries++; - continue; - } - } - } - - return 0 === $this->failedEntries; - } - -} diff --git a/tools/I18nValidatorInterface.php b/tools/I18nValidatorInterface.php deleted file mode 100644 index edfe7aac0..000000000 --- a/tools/I18nValidatorInterface.php +++ /dev/null @@ -1,26 +0,0 @@ -load(); - -$options = getopt("dhl:r"); - -if (array_key_exists('h', $options)) { - help(); -} -if (array_key_exists('l', $options)) { - $languages = array($options['l']); -} else { - $languages = $i18nData->getAvailableLanguages(); -} -$displayResults = array_key_exists('d', $options); -$displayReport = array_key_exists('r', $options); - -$isValidated = true; -$result = array(); -$report = array(); - -foreach ($languages as $language) { - if ($language === $i18nData::REFERENCE_LANGUAGE) { - $i18nValidator = new I18nUsageValidator($i18nData->getReferenceLanguage(), findUsedTranslations()); - $isValidated = $i18nValidator->validate(include __DIR__ . '/ignore/' . $language . '.php') && $isValidated; - } else { - $i18nValidator = new I18nCompletionValidator($i18nData->getReferenceLanguage(), $i18nData->getLanguage($language)); - if (file_exists(__DIR__ . '/ignore/' . $language . '.php')) { - $isValidated = $i18nValidator->validate(include __DIR__ . '/ignore/' . $language . '.php') && $isValidated; - } else { - $isValidated = $i18nValidator->validate(null) && $isValidated; - } - } - - $report[$language] = sprintf('%-5s - %s', $language, $i18nValidator->displayReport()); - $result[$language] = $i18nValidator->displayResult(); -} - -if ($displayResults) { - foreach ($result as $lang => $value) { - echo 'Language: ', $lang, PHP_EOL; - print_r($value); - echo PHP_EOL; - } -} - -if ($displayReport) { - foreach ($report as $value) { - echo $value; - } -} - -if (!$isValidated) { - exit(1); -} - -/** - * Find used translation keys in the project - * - * Iterates through all php and phtml files in the whole project and extracts all - * translation keys used. - * - * @return array - */ -function findUsedTranslations() { - $directory = new RecursiveDirectoryIterator(__DIR__ . '/..'); - $iterator = new RecursiveIteratorIterator($directory); - $regex = new RegexIterator($iterator, '/^.+\.(php|phtml)$/i', RecursiveRegexIterator::GET_MATCH); - $usedI18n = array(); - foreach (array_keys(iterator_to_array($regex)) as $file) { - $fileContent = file_get_contents($file); - preg_match_all('/_t\([\'"](?P[^\'"]+)[\'"]/', $fileContent, $matches); - $usedI18n = array_merge($usedI18n, $matches['strings']); - } - return $usedI18n; -} - -/** - * Output help message. - */ -function help() { - $help = <<load(); - -switch ($argv[1]) { - case 'add_language' : - $i18nData->addLanguage($argv[2]); - break; - case 'add_key' : - if (3 === $argc) { - help(); - } - $i18nData->addKey($argv[2], $argv[3]); - break; - case 'duplicate_key' : - $i18nData->duplicateKey($argv[2]); - break; - case 'delete_key' : - $i18nData->removeKey($argv[2]); - break; - default : - help(); -} - -if ($i18nData->hasChanged()) { - $i18nFile->dump($i18nData); -} - -/** - * Output help message. - */ -function help() { - $help = << Date: Sat, 2 Dec 2017 13:43:28 +0100 Subject: Documentation updates (#1697) * added documentation about updating FreshRSS moved Installation to admin directory linked some already existing documentation files --- README.md | 2 + cli/README.md | 50 +----------- docs/en/admins/01_Index.md | 8 ++ docs/en/admins/02_Installation.md | 147 +++++++++++++++++++++++++++++++++++ docs/en/admins/03_Updating.md | 90 +++++++++++++++++++++ docs/en/contributing.md | 7 +- docs/en/developers/01_First_steps.md | 4 + docs/en/index.md | 8 +- docs/en/users/01_Installation.md | 144 ---------------------------------- docs/en/users/02_First_steps.md | 4 +- docs/en/users/06_Mobile_access.md | 4 +- 11 files changed, 267 insertions(+), 201 deletions(-) create mode 100644 docs/en/admins/01_Index.md create mode 100644 docs/en/admins/02_Installation.md create mode 100644 docs/en/admins/03_Updating.md delete mode 100644 docs/en/users/01_Installation.md (limited to 'cli') diff --git a/README.md b/README.md index e59d553cf..1cf66a688 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ We are a friendly community. 6. Advanced configuration settings can be seen in [config.default.php](./config.default.php) and modified in `data/config.php`. 7. When using Apache, enable [`AllowEncodedSlashes`](http://httpd.apache.org/docs/trunk/mod/core.html#allowencodedslashes) for better compatibility with mobile clients. +More information about installation and server configuration can be found in [our documentation](https://freshrss.github.io/FreshRSS/en/admins/02_Installation.html). + ## Automated install * [![Install on Cloudron](https://cloudron.io/img/button.svg)](https://cloudron.io/button.html?app=org.freshrss.cloudronapp) * [![DP deploy](https://raw.githubusercontent.com/DFabric/DPlatform-ShellCore/gh-pages/img/deploy.png)](https://dfabric.github.io/DPlatform-ShellCore) diff --git a/cli/README.md b/cli/README.md index 6f907566c..b7e8ac7f5 100644 --- a/cli/README.md +++ b/cli/README.md @@ -99,51 +99,5 @@ Example to get the number of feeds of a given user: # Install and updates -## Using git - -If you manage FreshRSS via command line, then installing and updating FreshRSS can be done via git: - -```sh -# If your local user does not have write access, prefix all commands by sudo: -sudo ... - -# Install FreshRSS -cd /usr/share/ -git clone https://github.com/FreshRSS/FreshRSS.git - -# Perform all commands below in your FreshRSS directory: -cd /usr/share/FreshRSS - -# Use the development version of FreshRSS -git checkout -b dev origin/dev - -# Check out a specific version of FreshRSS -# See release names on https://github.com/FreshRSS/FreshRSS/releases -# You will then need to manually change version -# or checkout master or dev branch to get new versions -git checkout 1.7.0 - -# Verify what branch is used -git branch - -# Check whether there is a new version of FreshRSS, -# assuming you are on the /master or /dev branch -git fetch --all -git status - -# Discard manual changes (do a backup before) -git reset --hard -# Then re-delete the file forcing the setup wizard -rm data/do-install.txt - -# Delete manual additions (do a backup before) -git clean -f -d - -# Update to a newer version of FreshRSS, -# assuming you are on the /master or /dev branch -git pull - -# Set the rights so that your Web server can access the files -# (Example for Debian / Ubuntu) -chown -R :www-data . && chmod -R g+r . && chmod -R g+w ./data/ -``` +If you want to administrate FreshRSS using git, please read our [installation docs](https://freshrss.github.io/FreshRSS/en/admins/02_Installation.html) +and [update guidelines](https://freshrss.github.io/FreshRSS/en/users/08_Updating.html). \ No newline at end of file diff --git a/docs/en/admins/01_Index.md b/docs/en/admins/01_Index.md new file mode 100644 index 000000000..446780060 --- /dev/null +++ b/docs/en/admins/01_Index.md @@ -0,0 +1,8 @@ +# FreshRSS administration + +Learn how to install, update and backup FreshRSS and how to use the command line tools. + +* [Install FreshRSS](02_Installation.md) on your server +* [Update your installation](03_Updating.md) to the latest stable or dev version +* [The command line interface](https://github.com/FreshRSS/FreshRSS/tree/master/cli) can be used to administrate feeds and users +* [Automatic feed updates](https://github.com/FreshRSS/FreshRSS#automatic-feed-update) using cron is the preferred way to get the latest feeds entries diff --git a/docs/en/admins/02_Installation.md b/docs/en/admins/02_Installation.md new file mode 100644 index 000000000..ef6531bd0 --- /dev/null +++ b/docs/en/admins/02_Installation.md @@ -0,0 +1,147 @@ +# Server requirements + +FreshRSS is a web application. This means you’ll need a web server to run it. FreshRSS requirements are really low, so it could run on most shared host servers. + +You need to verify that your server can run FreshRSS before installing it. If your server has the proper requirements and FreshRSS does not work, please contact us to find a solution. + +| Software | Recommended | Works also with | +| ----------- | ---------------- | ----------------------------- | +| Web server | **Apache 2** | Nginx | +| PHP | **PHP 5.5+** | PHP 5.3.8+ | +| PHP modules | Required: libxml, cURL, PDO_MySQL, PCRE and ctype. \\ Required (32-bit only): GMP \\Recommanded: JSON, Zlib, mbstring, iconv, ZipArchive | | +| Database | **MySQL 5.0.3+** | SQLite 3.7.4+ | +| Browser | **Firefox** | Chrome, Opera, Safari, or IE11+ | + +## Important notice + +FreshRSS **CAN** work with PHP 5.3.8+. To do so, we are using specific functions available in the [''password_compat'' library](https://github.com/ircmaxell/password_compat#requirements) for the form authentication. + + +# Getting the appropriate version of FreshRSS + +FreshRSS has three different releases or branches. Each branch has its own release frequency. So it is better if you spend some time to understand the purpose of each release. + +## Stable release + +[Download](https://github.com/FreshRSS/FreshRSS/archive/master.zip) + +This release is done when we consider that our goal concerning the new features and the stability is reached. It could happen that we make two releases in a really short time if we have a really good coding pace. In reality, we are all working on our spare time, so we release every few months. But this version is really stable, tested thoroughly and you should not face any major bugs. + +## Development release + +[Download](https://github.com/FreshRSS/FreshRSS/archive/dev.zip) + +As its name suggests, it is the working release for developers. **This release is unstable!** If you want to keep track of enhancements on a daily basis, you can use it. But keep in mind that you need to follow the branch activity on Github (via [the branch RSS feed](https://github.com/FreshRSS/FreshRSS/commits/dev.atom) for instance). Some say that the main developers use it on a daily basis without problem. They may know what they are doing… + +# Apache installation + +This is an example Apache virtual hosts configuration file. It covers HTTP and HTTPS configuration. + +``` + + DocumentRoot /var/www/html/ + + #Default site... + + ErrorLog ${APACHE_LOG_DIR}/error.default.log + CustomLog ${APACHE_LOG_DIR}/access.default.log vhost_combined + + + + ServerName rss.example.net + DocumentRoot /path/to/FreshRSS/p/ + + + AllowOverride AuthConfig FileInfo Indexes Limit + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/freshrss_error.log + CustomLog ${APACHE_LOG_DIR}/freshrss_access.log combined + + AllowEncodedSlashes On + + + + + ServerName rss.example.net + DocumentRoot /path/to/FreshRSS/p/ + + + AllowOverride AuthConfig FileInfo Indexes Limit + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/freshrss_error.log + CustomLog ${APACHE_LOG_DIR}/freshrss_access.log combined + + + Protocols h2 http/1.1 + + + # For the API + AllowEncodedSlashes On + + SSLEngine on + SSLCompression off + SSLCertificateFile /path/to/server.crt + SSLCertificateKeyFile /path/to/server.key + # Additional SSL configuration, e.g. with LetsEncrypt + + +``` + +# Nginx installation + +This is an example nginx configuration file. It covers HTTP, HTTP, and php-fpm configuration. + +_You can find simpler config file but they may be incompatible with FreshRSS API._ + +``` +server { + listen 80; + listen 443 ssl; + + # HTTPS configuration + ssl on; + ssl_certificate /etc/nginx/server.crt; + ssl_certificate_key /etc/nginx/server.key; + + # your server’s URL(s) + server_name rss.example.net; + + # the folder p of your FreshRSS installation + root /srv/FreshRSS/p/; + + index index.php index.html index.htm; + + # nginx log files + access_log /var/log/nginx/rss.access.log; + error_log /var/log/nginx/rss.error.log; + + # php files handling + # this regex is mandatory because of the API + location ~ ^.+?\.php(/.*)?$ { + fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + # By default, the variable PATH_INFO is not set under PHP-FPM + # But FreshRSS API greader.php need it. If you have a “Bad Request” error, double check this var! + fastcgi_param PATH_INFO $fastcgi_path_info; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } + + location / { + try_files $uri $uri/ index.php; + } +} +``` + +A step-by-step tutorial is available [in French](http://www.pihomeserver.fr/2013/05/08/raspberry-pi-home-server-installer-un-agregateur-de-flux-rss-pour-remplacer-google-reader/). + +# Security + +Make sure to expose only the `./p/` folder on the web, the other directories contain personal and sensitive data. +See the Apache and nginx config examples above. + +**TODO** diff --git a/docs/en/admins/03_Updating.md b/docs/en/admins/03_Updating.md new file mode 100644 index 000000000..4e1fdfa5d --- /dev/null +++ b/docs/en/admins/03_Updating.md @@ -0,0 +1,90 @@ + +First things first: we recommend to create a backup before updating: + +```sh +# Perform all commands below in your FreshRSS directory: +cd /usr/share/FreshRSS + +tar -czvf FreshRSS-backup.tgz . +``` + +The update process depends on your installation type, see below: + + +## Using the web admin panel + +Change to your installation at http://localhost/FreshRSS/p/i/?c=update and hit the "Check for new updates" button. + +If there is a new version you will be prompted again. + + +## Using git + +If you manage FreshRSS via command line, then installing and updating FreshRSS can be done via git: + +```sh +# If your local user does not have write access, prefix all commands by sudo: +sudo ... + +# Perform all commands below in your FreshRSS directory: +cd /usr/share/FreshRSS + +# Use the development version of FreshRSS +git checkout -b dev origin/dev + +# Check out a specific version of FreshRSS +# See release names on https://github.com/FreshRSS/FreshRSS/releases +# You will then need to manually change version +# or checkout master or dev branch to get new versions +git checkout 1.7.0 + +# Verify what branch is used +git branch + +# Check whether there is a new version of FreshRSS, +# assuming you are on the /master or /dev branch +git fetch --all +git status + +# Discard manual changes (do a backup before) +git reset --hard +# Then re-delete the file forcing the setup wizard +rm data/do-install.txt + +# Delete manual additions (do a backup before) +git clean -f -d + +# Update to a newer version of FreshRSS, +# assuming you are on the /master or /dev branch +git pull + +# Set the rights so that your Web server can access the files +# (Example for Debian / Ubuntu) +chown -R :www-data . && chmod -R g+r . && chmod -R g+w ./data/ +``` + + +## Using the zip archive + +Perform all commands in your FreshRSS directory: +```sh +cd /usr/share/FreshRSS +``` + +Commands intended to be executed in order (you can c/p the whole block if desired): + +```sh +wget https://github.com/FreshRSS/FreshRSS/archive/master.zip +unzip master.zip +cp -R FreshRSS-master/* . +chown -R :www-data . && chmod -R g+r . && chmod -R g+w ./data/ +rm -f master.zip +rm -f data/do-install.txt +rm -rf FreshRSS-master/ +``` + +Short explanation of the commands above: +* Download the latest version and unzip it +* Overwrite all your existing files with the new ones +* Fix possible permission issues +* Cleanup by deleting the downloaded zip, the file forcing the setup wizard and the temporary directory diff --git a/docs/en/contributing.md b/docs/en/contributing.md index 7f0c3da6c..19f9cb9b1 100644 --- a/docs/en/contributing.md +++ b/docs/en/contributing.md @@ -32,9 +32,9 @@ Did you want to fix a bug? To keep a great coordination between collaborators, y 3. [Create a new branch](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/). The name of the branch must be explicit and being prefixed by the related ticket id. For instance, `783-contributing-file` to fix [ticket #783](https://github.com/FreshRSS/FreshRSS/issues/783). 4. Make your changes to your fork and [send a pull request](https://help.github.com/articles/using-pull-requests/) on the **dev branch**. -If you have to write code, please follow [our coding style recommendations](http://doc2.freshrss.org/en/Developer_documentation/First_steps/Coding_style). +If you have to write code, please follow [our coding style recommendations](developers/01_First_steps.md). -**Tip:** if you are searching for bugs easy to fix, have a look at the « [New comers](https://github.com/FreshRSS/FreshRSS/labels/New%20comers) » ticket label. +**Tip:** if you are searching for easy-to-fix bugs, have a look at the « [good first issue](https://github.com/FreshRSS/FreshRSS/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) » ticket label. ## Submit an idea @@ -52,4 +52,5 @@ We are working on a better way to handle internationalization but don't hesitate ## Contribute to documentation -The documentation needs a lot of improvements in order to be more useful to new contributors and we are working on it. If you want to give some help, meet us on [the dedicated repository](https://github.com/FreshRSS/documentation)! +The documentation needs a lot of improvements in order to be more useful to new contributors and we are working on it. +If you want to give some help, meet us in the main repositories [docs directory](https://github.com/FreshRSS/FreshRSS/tree/master/docs)! diff --git a/docs/en/developers/01_First_steps.md b/docs/en/developers/01_First_steps.md index e35dbda12..adca4495b 100644 --- a/docs/en/developers/01_First_steps.md +++ b/docs/en/developers/01_First_steps.md @@ -6,6 +6,10 @@ **TODO** +# Extensions + +If you want to create your own FreshRSS extension, take a look at the [extension documentation](03_Backend/05_Extensions.md). + # Coding style If you want to contribute to the source code, it is important to follow the project coding style. The actual code does not follow it throughout the project, but every time we have an opportunity, we should fix it. diff --git a/docs/en/index.md b/docs/en/index.md index c2f12380b..a0c97a0d9 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -16,7 +16,9 @@ FreshRSS has a lot of features including: - Multi-users so you can host your friends and your family - And a lot more! -This documentation is splitted in two sections: +This documentation is split into four sections: -- [users documentation](users/02_First_steps.md) so you can discover all the power of FreshRSS -- [developers documentation](developers/01_First_steps.md) to guide you in the source code of FreshRSS and to help you if you want to contribute +- [user documentation](users/02_First_steps.md) so you can discover all the power of FreshRSS +- [developer documentation](developers/01_First_steps.md) to guide you in the source code of FreshRSS and to help you if you want to contribute +- [administrator documentation](admins/01_Index.md) to guide you in the source code of FreshRSS and to help you if you want to contribute +- [contributor guidelines](contributing.md) for all of you who want to help improving FreshRSS diff --git a/docs/en/users/01_Installation.md b/docs/en/users/01_Installation.md deleted file mode 100644 index 9d012f2b1..000000000 --- a/docs/en/users/01_Installation.md +++ /dev/null @@ -1,144 +0,0 @@ -# Server requirements - -FreshRSS is a web application. This means you’ll need a web server to run it. FreshRSS requirements are really low, so it could run on most shared host servers. - -You need to verify that your server can run FreshRSS before installing it. If your server has the proper requirements and FreshRSS does not work, please contact us to find a solution. - -| Software | Recommended | Works also with | -| ----------- | ---------------- | ----------------------------- | -| Web server | **Apache 2** | Nginx | -| PHP | **PHP 5.5+** | PHP 5.3.8+ | -| PHP modules | Required: libxml, cURL, PDO_MySQL, PCRE and ctype. \\ Required (32-bit only): GMP \\Recommanded: JSON, Zlib, mbstring, iconv, ZipArchive | | -| Database | **MySQL 5.0.3+** | SQLite 3.7.4+ | -| Browser | **Firefox** | Chrome, Opera, Safari, or IE11+ | - -## Important notice - -FreshRSS **CAN** work with PHP 5.3.8+. To do so, we are using specific functions available in the [''password_compat'' library](https://github.com/ircmaxell/password_compat#requirements) for the form authentication. - - -# Getting the appropriate version of FreshRSS - -FreshRSS has three different releases or branches. Each branch has its own release frequency. So it is better if you spend some time to understand the purpose of each release. - -## Stable release - -[Download](https://github.com/FreshRSS/FreshRSS/archive/master.zip) - -This release is done when we consider that our goal concerning the new features and the stability is reached. It could happen that we make two releases in a really short time if we have a really good coding pace. In reality, we are all working on our spare time, so we release every few months. But this version is really stable, tested thoroughly and you should not face any major bugs. - -## Development release - -[Download](https://github.com/FreshRSS/FreshRSS/archive/dev.zip) - -As its name suggests, it is the working release for developers. **This release is unstable!** If you want to keep track of enhancements on a daily basis, you can use it. But keep in mind that you need to follow the branch activity on Github (via [the branch RSS feed](https://github.com/FreshRSS/FreshRSS/commits/dev.atom) for instance). Some say that the main developers use it on a daily basis without problem. They may know what they are doing… - -# Apache installation - -This is an example Apache virtual hosts configuration file. It covers HTTP and HTTPS configuration. - -``` - - DocumentRoot /var/www/html/ - - #Default site... - - ErrorLog ${APACHE_LOG_DIR}/error.default.log - CustomLog ${APACHE_LOG_DIR}/access.default.log vhost_combined - - - - ServerName rss.example.net - DocumentRoot /path/to/FreshRSS/p/ - - - AllowOverride AuthConfig FileInfo Indexes Limit - Require all granted - - - ErrorLog ${APACHE_LOG_DIR}/freshrss_error.log - CustomLog ${APACHE_LOG_DIR}/freshrss_access.log combined - - AllowEncodedSlashes On - - - - - ServerName rss.example.net - DocumentRoot /path/to/FreshRSS/p/ - - - AllowOverride AuthConfig FileInfo Indexes Limit - Require all granted - - - ErrorLog ${APACHE_LOG_DIR}/freshrss_error.log - CustomLog ${APACHE_LOG_DIR}/freshrss_access.log combined - - - Protocols h2 http/1.1 - - - # For the API - AllowEncodedSlashes On - - SSLEngine on - SSLCompression off - SSLCertificateFile /path/to/server.crt - SSLCertificateKeyFile /path/to/server.key - # Additional SSL configuration, e.g. with LetsEncrypt - - -``` - -# Nginx installation - -This is an example nginx configuration file. It covers HTTP, HTTP, and php-fpm configuration. - -_You can find simpler config file but they may be incompatible with FreshRSS API._ - -``` -server { - listen 80; - listen 443 ssl; - - # HTTPS configuration - ssl on; - ssl_certificate /etc/nginx/server.crt; - ssl_certificate_key /etc/nginx/server.key; - - # your server’s URL(s) - server_name rss.example.net; - - # the folder p of your FreshRSS installation - root /srv/FreshRSS/p/; - - index index.php index.html index.htm; - - # nginx log files - access_log /var/log/nginx/rss.access.log; - error_log /var/log/nginx/rss.error.log; - - # php files handling - # this regex is mandatory because of the API - location ~ ^.+?\.php(/.*)?$ { - fastcgi_pass unix:/var/run/php5-fpm.sock; - fastcgi_split_path_info ^(.+\.php)(/.*)$; - # By default, the variable PATH_INFO is not set under PHP-FPM - # But FreshRSS API greader.php need it. If you have a “Bad Request” error, double check this var! - fastcgi_param PATH_INFO $fastcgi_path_info; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - } - - location / { - try_files $uri $uri/ index.php; - } -} -``` - -A step-by-step tutorial is available [in French](http://www.pihomeserver.fr/2013/05/08/raspberry-pi-home-server-installer-un-agregateur-de-flux-rss-pour-remplacer-google-reader/). - -# Security - -**TODO** diff --git a/docs/en/users/02_First_steps.md b/docs/en/users/02_First_steps.md index 96ee264a6..2fb1b7256 100644 --- a/docs/en/users/02_First_steps.md +++ b/docs/en/users/02_First_steps.md @@ -2,7 +2,7 @@ Learning how to handle a new application is not always easy. We build FreshRSS t This section guides you to the pages you need as a new comer. -[After you installed the application](01_Installation.md), the first step is to add one or more feeds. You have few options: +[After installing the application](../admins/02_Installation.md), the first step is to add some feeds. You have a few options: 1. [Add a feed manually](04_Subscriptions.md#adding-a-feed) 2. [Import an OPML or JSON file](04_Subscriptions.md#import-and-export) @@ -24,3 +24,5 @@ Now that you know the basic usages, it is time to configure FreshRSS to improve * [Filter articles](03_Main_view.md#filtering-articles) for a fast access to a selection * [Search an article](03_Main_view.md#searching-articles) published some time ago * [Access your feeds on a mobile device](06_Mobile_access.md) +* [Add some extensions](https://github.com/FreshRSS/Extensions) +* [Frequently asked questions](07_Frequently_Asked_Questions.md) diff --git a/docs/en/users/06_Mobile_access.md b/docs/en/users/06_Mobile_access.md index d935411eb..3472172b0 100644 --- a/docs/en/users/06_Mobile_access.md +++ b/docs/en/users/06_Mobile_access.md @@ -1,4 +1,4 @@ -This page assumes you have completed the [server setup](01_Installation.md). +This page assumes you have completed the [server setup](../admins/02_Installation.md). # Enable the API in FreshRSS @@ -27,7 +27,7 @@ This page assumes you have completed the [server setup](01_Installation.md). * With __Apache__: * If you get *FAIL getallheaders!*, the combination of your PHP version and your Web server does not provide access to [`getallheaders`](http://php.net/getallheaders) * Update to PHP 5.4+, or use PHP as module instead of CGI. Otherwise turn on Apache `mod_rewrite`: - * Allow [`FileInfo` in `.htaccess`](http://httpd.apache.org/docs/trunk/mod/core.html#allowoverride): see the [server setup](01_Installation.md) again. + * Allow [`FileInfo` in `.htaccess`](http://httpd.apache.org/docs/trunk/mod/core.html#allowoverride): see the [server setup](../admins/02_Installation.md) again. * Enable [`mod_rewrite`](http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html): * With Debian / Ubuntu: `sudo a2enmod rewrite` * With __nginx__: -- cgit v1.2.3 From 5c52d9b34bb1f1285f92dd557bb8b8cb222b50f4 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Sun, 10 Dec 2017 22:09:54 +0100 Subject: Check requirement in CLI script (#1711) * check requirements in actualize_script before executing, fixes #1710 * removed empty whiteline * testing all requirements * incorporated code review feedback * removed code that is already executed in _cli.php * added newline at eof * fixed include problems * fixed include problems --- app/actualize_script.php | 12 ++++-------- cli/_cli.php | 17 +++++++++++++++++ cli/do-install.php | 15 +-------------- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'cli') diff --git a/app/actualize_script.php b/app/actualize_script.php index deaa1bf7c..0bb1f166f 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -1,6 +1,5 @@ format('c') . "\n"); //Unbuffered } - // Set the header params ($_GET) to call the FRSS application. $_GET['c'] = 'feed'; $_GET['a'] = 'actualize'; @@ -20,15 +18,15 @@ $_GET['ajax'] = 1; $_GET['force'] = true; $_SERVER['HTTP_HOST'] = ''; - $log_file = join_path(USERS_PATH, '_', 'log.txt'); - $app = new FreshRSS(); $system_conf = Minz_Configuration::get('system'); $system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) -FreshRSS_Context::$isCli = true; + +// make sure the PHP setup of the CLI environment is compatible with FreshRSS as well +performRequirementCheck($system_conf->db['type']); // Create the list of users to actualize. // Users are processed in a random order but always start with admin @@ -39,7 +37,6 @@ if ($system_conf->default_user !== '') { $users = array_unique($users); } - $limits = $system_conf->limits; $min_last_activity = time() - $limits['max_inactivity']; foreach ($users as $user) { @@ -74,7 +71,6 @@ foreach ($users as $user) { } } - Minz_Log::notice('FreshRSS actualize done.', $log_file); if (defined('STDOUT')) { fwrite(STDOUT, 'Done.' . "\n"); diff --git a/cli/_cli.php b/cli/_cli.php index 1b26ea738..fb35c4afb 100644 --- a/cli/_cli.php +++ b/cli/_cli.php @@ -5,6 +5,7 @@ if (php_sapi_name() !== 'cli') { require(dirname(__FILE__) . '/../constants.php'); require(LIB_PATH . '/lib_rss.php'); +require(LIB_PATH . '/lib_install.php'); Minz_Configuration::register('system', DATA_PATH . '/config.php', @@ -47,3 +48,19 @@ function done($ok = true) { fwrite(STDERR, 'Result: ' . ($ok ? 'success' : 'fail') . "\n"); exit($ok ? 0 : 1); } + +function performRequirementCheck($databaseType) { + $requirements = checkRequirements($databaseType); + if ($requirements['all'] !== 'ok') { + $message = 'FreshRSS install failed requirements:' . "\n"; + foreach ($requirements as $requirement => $check) { + if ($check !== 'ok' && !in_array($requirement, array('all', 'pdo', 'message'))) { + $message .= '• ' . $requirement . "\n"; + } + } + if (!empty($requirements['message'])) { + $message .= '• ' . $requirements['message'] . "\n"; + } + fail($message); + } +} diff --git a/cli/do-install.php b/cli/do-install.php index 74bbdfcd4..37db85575 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -1,7 +1,6 @@ #!/usr/bin/php $check) { - if ($check !== 'ok' && !in_array($requirement, array('all', 'pdo', 'message'))) { - $message .= '• ' . $requirement . "\n"; - } - } - if (!empty($requirements['message'])) { - $message .= '• ' . $requirements['message'] . "\n"; - } - fail($message); -} +performRequirementCheck($config['db']['type']); if (!FreshRSS_user_Controller::checkUsername($options['default_user'])) { fail('FreshRSS error: invalid default username “' . $options['default_user'] -- cgit v1.2.3 From 52d09886558361bd818182da9ddc204e83f618ba Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 11 Dec 2017 21:11:34 +0100 Subject: Use __DIR__ for relative include and require For uniformity, and to avoid having PHP searching in include_path. http://php.net/manual/function.include.php https://github.com/FreshRSS/FreshRSS/pull/1715 https://github.com/FreshRSS/FreshRSS/pull/1711#issuecomment-350581350 --- cli/_cli.php | 2 +- cli/_update-or-create-user.php | 2 +- cli/actualize-user.php | 2 +- cli/create-user.php | 2 +- cli/db-optimize.php | 2 +- cli/delete-user.php | 2 +- cli/do-install.php | 2 +- cli/export-opml-for-user.php | 2 +- cli/export-zip-for-user.php | 2 +- cli/import-for-user.php | 2 +- cli/list-users.php | 2 +- cli/reconfigure.php | 2 +- cli/update-user.php | 2 +- cli/user-info.php | 2 +- lib/lib_rss.php | 4 ++-- p/api/greader.php | 2 +- p/api/index.php | 2 +- p/api/pshb.php | 2 +- p/ext.php | 2 +- p/f.php | 2 +- p/i/index.php | 2 +- tests/bootstrap.php | 2 +- 22 files changed, 23 insertions(+), 23 deletions(-) (limited to 'cli') diff --git a/cli/_cli.php b/cli/_cli.php index fb35c4afb..72629171c 100644 --- a/cli/_cli.php +++ b/cli/_cli.php @@ -3,7 +3,7 @@ if (php_sapi_name() !== 'cli') { die('FreshRSS error: This PHP script may only be invoked from command line!'); } -require(dirname(__FILE__) . '/../constants.php'); +require(__DIR__ . '/../constants.php'); require(LIB_PATH . '/lib_rss.php'); require(LIB_PATH . '/lib_install.php'); diff --git a/cli/_update-or-create-user.php b/cli/_update-or-create-user.php index 15397f1f6..a5960b58a 100644 --- a/cli/_update-or-create-user.php +++ b/cli/_update-or-create-user.php @@ -1,5 +1,5 @@ decode($var); @@ -12,7 +12,7 @@ if (!function_exists('json_decode')) { } if (!function_exists('json_encode')) { - require_once('JSON.php'); + require_once(__DIR__ . '/JSON.php'); function json_encode($var) { $JSON = new Services_JSON(); return $JSON->encodeUnsafe($var); diff --git a/p/api/greader.php b/p/api/greader.php index b27f5bd43..99304f4ec 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -20,7 +20,7 @@ Server-side API compatible with Google Reader API layer 2 * https://github.com/theoldreader/api */ -require('../../constants.php'); +require(__DIR__ . '/../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, 1048576); diff --git a/p/api/index.php b/p/api/index.php index 08f7b6b7b..429b25225 100644 --- a/p/api/index.php +++ b/p/api/index.php @@ -14,7 +14,7 @@
Your API address: