mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2026-02-10 16:01:33 +00:00
move version-related stuff to Config; fix conditional feed requests
This commit is contained in:
@@ -49,7 +49,7 @@ class API extends Handler {
|
||||
}
|
||||
|
||||
function getVersion() {
|
||||
$rv = array("version" => get_version());
|
||||
$rv = array("version" => Config::get_version());
|
||||
$this->_wrap(self::STATUS_OK, $rv);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ class Config {
|
||||
|
||||
private $params = [];
|
||||
private $schema_version = null;
|
||||
private $version = [];
|
||||
|
||||
public static function get_instance() : Config {
|
||||
if (self::$instance == null)
|
||||
@@ -134,6 +135,78 @@ class Config {
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
|
||||
static function get_version(bool $as_string = true) {
|
||||
return self::get_instance()->_get_version($as_string);
|
||||
}
|
||||
|
||||
private function _get_version(bool $as_string = true) {
|
||||
$root_dir = dirname(__DIR__);
|
||||
|
||||
if (empty($this->version)) {
|
||||
$this->version["status"] = -1;
|
||||
|
||||
if (PHP_OS === "Darwin") {
|
||||
$ttrss_version["version"] = "UNKNOWN (Unsupported, Darwin)";
|
||||
} else if (file_exists("$root_dir/version_static.txt")) {
|
||||
$this->version["version"] = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)";
|
||||
} else if (is_dir("$root_dir/.git")) {
|
||||
$this->version = self::get_version_from_git($root_dir);
|
||||
|
||||
if ($this->version["status"] != 0) {
|
||||
user_error("Unable to determine version: " . $this->version["version"], E_USER_WARNING);
|
||||
|
||||
$this->version["version"] = "UNKNOWN (Unsupported, Git error)";
|
||||
}
|
||||
} else {
|
||||
$this->version["version"] = "UNKNOWN (Unsupported)";
|
||||
}
|
||||
}
|
||||
|
||||
return $as_string ? $this->version["version"] : $this->version;
|
||||
}
|
||||
|
||||
static function get_version_from_git(string $dir) {
|
||||
$descriptorspec = [
|
||||
1 => ["pipe", "w"], // STDOUT
|
||||
2 => ["pipe", "w"], // STDERR
|
||||
];
|
||||
|
||||
$rv = [
|
||||
"status" => -1,
|
||||
"version" => "",
|
||||
"commit" => "",
|
||||
"timestamp" => 0,
|
||||
];
|
||||
|
||||
$proc = proc_open("git --no-pager log --pretty=\"%ct %h\" -n1 HEAD",
|
||||
$descriptorspec, $pipes, $dir);
|
||||
|
||||
if (is_resource($proc)) {
|
||||
$stdout = trim(stream_get_contents($pipes[1]));
|
||||
$stderr = trim(stream_get_contents($pipes[2]));
|
||||
$status = proc_close($proc);
|
||||
|
||||
$rv["status"] = $status;
|
||||
|
||||
if ($status == 0) {
|
||||
list($timestamp, $commit) = explode(" ", $stdout);
|
||||
|
||||
$rv["version"] = strftime("%y.%m", (int)$timestamp) . "-$commit";
|
||||
$rv["commit"] = $commit;
|
||||
$rv["timestamp"] = $timestamp;
|
||||
|
||||
} else {
|
||||
$rv["version"] = T_sprintf("Git error [RC=%d]: %s", $status, $stderr);
|
||||
}
|
||||
}
|
||||
|
||||
return $rv;
|
||||
}
|
||||
|
||||
static function get_schema_version(bool $nocache = false) {
|
||||
return self::get_instance()->_schema_version($nocache);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class Handler_Public extends Handler {
|
||||
$tpl->readTemplateFromFile("generated_feed.txt");
|
||||
|
||||
$tpl->setVariable('FEED_TITLE', $feed_title, true);
|
||||
$tpl->setVariable('VERSION', get_version(), true);
|
||||
$tpl->setVariable('VERSION', Config::get_version(), true);
|
||||
$tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
|
||||
|
||||
$tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
|
||||
|
||||
@@ -1099,29 +1099,6 @@ class Pref_Prefs extends Handler_Protected {
|
||||
set_pref(Prefs::_ENABLED_PLUGINS, $plugins);
|
||||
}
|
||||
|
||||
function _get_version_from_git(string $dir) {
|
||||
$descriptorspec = [
|
||||
1 => ["pipe", "w"], // STDOUT
|
||||
2 => ["pipe", "w"], // STDERR
|
||||
];
|
||||
|
||||
$proc = proc_open("git --no-pager log --pretty=\"%ct %h\" -n1 HEAD",
|
||||
$descriptorspec, $pipes, $dir);
|
||||
|
||||
if (is_resource($proc)) {
|
||||
$stdout = stream_get_contents($pipes[1]);
|
||||
$stderr = stream_get_contents($pipes[2]);
|
||||
$status = proc_close($proc);
|
||||
|
||||
if ($status == 0) {
|
||||
list($timestamp, $commit) = explode(" ", $stdout);
|
||||
return trim(strftime("%y.%m", (int)$timestamp) . "-$commit");
|
||||
} else {
|
||||
return T_sprintf("Git error [RC=%d]: %s", $status, $stderr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _get_plugin_version(Plugin $plugin) {
|
||||
$about = $plugin->about();
|
||||
|
||||
@@ -1137,7 +1114,9 @@ class Pref_Prefs extends Handler_Protected {
|
||||
}
|
||||
|
||||
if (is_dir("$plugin_dir/.git")) {
|
||||
return T_sprintf("v%s, by %s", $this->_get_version_from_git($plugin_dir), $about[2]);
|
||||
$ver = Config::get_version_from_git($plugin_dir);
|
||||
|
||||
return $ver["status"] == 0 ? T_sprintf("v%s, by %s", $ver["version"], $about[2]) : $ver["version"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,10 +396,10 @@ class RPC extends Handler_Protected {
|
||||
function checkforupdates() {
|
||||
$rv = ["changeset" => [], "plugins" => []];
|
||||
|
||||
$git_timestamp = false;
|
||||
$git_commit = false;
|
||||
$version = Config::get_version();
|
||||
|
||||
get_version($git_commit, $git_timestamp);
|
||||
$git_timestamp = $version["timestamp"] ?? false;
|
||||
$git_commit = $version["commit"] ?? false;
|
||||
|
||||
if (Config::get(Config::CHECK_FOR_UPDATES) && $_SESSION["access_level"] >= 10 && $git_timestamp) {
|
||||
$content = @UrlHelper::fetch(["url" => "https://tt-rss.org/version.json"]);
|
||||
|
||||
@@ -458,8 +458,6 @@ class RSSUtils {
|
||||
Debug::log("local cache will not be used for this feed", Debug::$LOG_VERBOSE);
|
||||
}
|
||||
|
||||
global $fetch_last_modified;
|
||||
|
||||
// fetch feed from source
|
||||
if (!$feed_data) {
|
||||
Debug::log("last unconditional update request: $last_unconditional", Debug::$LOG_VERBOSE);
|
||||
@@ -490,11 +488,11 @@ class RSSUtils {
|
||||
|
||||
Debug::log("fetch done.", Debug::$LOG_VERBOSE);
|
||||
Debug::log("effective URL (after redirects): " . clean(UrlHelper::$fetch_effective_url) . " (IP: ".UrlHelper::$fetch_effective_ip_addr.")", Debug::$LOG_VERBOSE);
|
||||
Debug::log("source last modified: " . $fetch_last_modified, Debug::$LOG_VERBOSE);
|
||||
Debug::log("source last modified: " . UrlHelper::$fetch_last_modified, Debug::$LOG_VERBOSE);
|
||||
|
||||
if ($feed_data && $fetch_last_modified != $stored_last_modified) {
|
||||
if ($feed_data && UrlHelper::$fetch_last_modified != $stored_last_modified) {
|
||||
$sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?");
|
||||
$sth->execute([substr($fetch_last_modified, 0, 245), $feed]);
|
||||
$sth->execute([substr(UrlHelper::$fetch_last_modified, 0, 245), $feed]);
|
||||
}
|
||||
|
||||
// cache vanilla feed data for re-use
|
||||
|
||||
@@ -167,17 +167,6 @@ class UrlHelper {
|
||||
public static function fetch($options /* previously: 0: $url , 1: $type = false, 2: $login = false, 3: $pass = false,
|
||||
4: $post_query = false, 5: $timeout = false, 6: $timestamp = 0, 7: $useragent = false*/) {
|
||||
|
||||
/*
|
||||
global $fetch_last_error;
|
||||
global $fetch_last_error_code;
|
||||
global $fetch_last_error_content;
|
||||
global $fetch_last_content_type;
|
||||
global $fetch_last_modified;
|
||||
global $fetch_effective_url;
|
||||
global $fetch_effective_ip_addr;
|
||||
global $fetch_curl_used;
|
||||
*/
|
||||
|
||||
self::$fetch_last_error = false;
|
||||
self::$fetch_last_error_code = -1;
|
||||
self::$fetch_last_error_content = "";
|
||||
|
||||
Reference in New Issue
Block a user