From 72d0fac80c0d88d015203578007260c338b40ece Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 18 Dec 2019 14:27:40 +0300 Subject: remove version.php and VERSION global constant, do version-related things in a slightly less ridiculous way --- include/functions.php | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index 9cd352833..e72a70c13 100644 --- a/include/functions.php +++ b/include/functions.php @@ -151,7 +151,6 @@ } require_once 'db-prefs.php'; - require_once 'version.php'; require_once 'controls.php'; define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . VERSION . ' (http://tt-rss.org/)'); @@ -1882,3 +1881,43 @@ return $ts; } + + /* for package maintainers who don't use git: if version_static.txt exists in tt-rss root + directory, its contents are displayed instead of git commit-based version, this could be generated + based on source git tree commit used when creating the package */ + + function get_version(&$git_commit = false, &$git_timestamp = false) { + global $ttrss_version; + + if (isset($ttrss_version)) + return $ttrss_version; + + $ttrss_version = "UNKNOWN (Unsupported)"; + + date_default_timezone_set('UTC'); + $root_dir = dirname(dirname(__FILE__)); + + if (file_exists("$root_dir/version_static.txt")) { + $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)"; + } else if (is_dir("$root_dir/.git")) { + $rc = 0; + $output = []; + + exec("git log --pretty=".escapeshellarg('%ct %h')." -n1 HEAD " . escapeshellarg($root_dir) . ' 2>&1', $output, $rc); + + if ($rc == 0) { + if (is_array($output) && count($output) > 0) { + list ($timestamp, $commit) = explode(" ", $output[0], 2); + + $git_commit = $commit; + $git_timestamp = $timestamp; + + $ttrss_version = strftime("%y.%m", $timestamp) . "-$commit"; + } + } else { + user_error("Unable to determine version: " . implode("\n", $output), E_USER_WARNING); + } + } + + return $ttrss_version; + } -- cgit v1.2.3-54-g00ecf From 72d8a34f748ca065e32c2e1f330f869e39e0d909 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 18 Dec 2019 15:29:12 +0300 Subject: get_version: don't pass useless root dir to git, instead log it in case of failure --- include/functions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index e72a70c13..97557ed95 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1903,7 +1903,11 @@ $rc = 0; $output = []; - exec("git log --pretty=".escapeshellarg('%ct %h')." -n1 HEAD " . escapeshellarg($root_dir) . ' 2>&1', $output, $rc); + $cwd = getcwd(); + + chdir($root_dir); + exec('git log --pretty='.escapeshellarg('%ct %h').' -n1 HEAD 2>&1', $output, $rc); + chdir($cwd); if ($rc == 0) { if (is_array($output) && count($output) > 0) { @@ -1915,7 +1919,7 @@ $ttrss_version = strftime("%y.%m", $timestamp) . "-$commit"; } } else { - user_error("Unable to determine version: " . implode("\n", $output), E_USER_WARNING); + user_error("Unable to determine version (using $root_dir): " . implode("\n", $output), E_USER_WARNING); } } -- cgit v1.2.3-54-g00ecf From c46c5e59fc8bec35a2a9adaae8501eda47d7d823 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 18 Dec 2019 15:56:27 +0300 Subject: SELF_USER_AGENT: switch to get_version() --- include/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index 97557ed95..da87588f0 100644 --- a/include/functions.php +++ b/include/functions.php @@ -153,7 +153,7 @@ require_once 'db-prefs.php'; require_once 'controls.php'; - define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . VERSION . ' (http://tt-rss.org/)'); + define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . get_version() . ' (http://tt-rss.org/)'); ini_set('user_agent', SELF_USER_AGENT); $schema_version = false; -- cgit v1.2.3-54-g00ecf From 74feef0f9d7258570a6c6a7a694fc1a0394843ca Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 18 Dec 2019 19:28:00 +0300 Subject: get_version: always return unsupported on windows --- include/functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index da87588f0..3b71eb0bd 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1897,7 +1897,9 @@ date_default_timezone_set('UTC'); $root_dir = dirname(dirname(__FILE__)); - if (file_exists("$root_dir/version_static.txt")) { + if ('\\' === DIRECTORY_SEPARATOR) { + $ttrss_version = "UNKNOWN (Unsupported, Windows)"; + } else if (file_exists("$root_dir/version_static.txt")) { $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)"; } else if (is_dir("$root_dir/.git")) { $rc = 0; -- cgit v1.2.3-54-g00ecf From c309856a976b230a56b1eb700590111bd2ad7451 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 19 Dec 2019 07:04:01 +0300 Subject: get_version: filter out Darwin --- include/functions.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index 3b71eb0bd..47dd9c73c 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1899,6 +1899,8 @@ if ('\\' === DIRECTORY_SEPARATOR) { $ttrss_version = "UNKNOWN (Unsupported, Windows)"; + } else if (PHP_OS === "Darwin") { + $ttrss_version = "UNKNOWN (Unsupported, Darwin)"; } else if (file_exists("$root_dir/version_static.txt")) { $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)"; } else if (is_dir("$root_dir/.git")) { -- cgit v1.2.3-54-g00ecf From 6439f7817d779f43437b79dfb04e5254f7e0bbf4 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 19 Dec 2019 08:37:19 +0300 Subject: force-disable php display_errors/display_startup_errors on startup --- include/functions.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index 47dd9c73c..f244b47b8 100644 --- a/include/functions.php +++ b/include/functions.php @@ -27,6 +27,9 @@ error_reporting(E_ALL & ~E_NOTICE); } + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + require_once 'config.php'; /** -- cgit v1.2.3-54-g00ecf