From fe2a7a575f71ac9963afb6ffaa8d4113b742e5f6 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 21 Sep 2023 15:22:02 +0300 Subject: [PATCH] add API version check #13, #14 --- example/environment/env.example.php | 2 -- src/config/bootstrap.php | 4 ++++ src/crontab/export/feed.php | 4 ++-- src/crontab/import/feed.php | 13 +++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/example/environment/env.example.php b/example/environment/env.example.php index 134afc5..0a2d22f 100644 --- a/example/environment/env.example.php +++ b/example/environment/env.example.php @@ -165,8 +165,6 @@ define('NODE_RULE_SUBJECT', 'Common'); define('NODE_RULE_LANGUAGES', 'All'); // API -define('API_VERSION', '1.0.0'); - define('API_USER_AGENT', WEBSITE_NAME); /// Export diff --git a/src/config/bootstrap.php b/src/config/bootstrap.php index 906adf0..70679bd 100644 --- a/src/config/bootstrap.php +++ b/src/config/bootstrap.php @@ -3,6 +3,10 @@ // PHP declare(strict_types=1); +// Application +define('APP_VERSION', '2.0.0'); +define('API_VERSION', APP_VERSION); + // Init environment if (!file_exists(__DIR__ . '/.env')) { diff --git a/src/crontab/export/feed.php b/src/crontab/export/feed.php index f895dd2..be41107 100644 --- a/src/crontab/export/feed.php +++ b/src/crontab/export/feed.php @@ -58,7 +58,8 @@ try // Manifest $manifest = [ - 'updated' => time(), + 'updated' => time(), + 'version' => (string) API_VERSION, 'settings' => (object) [ @@ -119,7 +120,6 @@ try 'MAGNET_STOP_WORDS_SIMILAR' => (object) MAGNET_STOP_WORDS_SIMILAR, - 'API_VERSION' => (string) API_VERSION, 'API_USER_AGENT' => (string) API_USER_AGENT, 'API_EXPORT_ENABLED' => (bool) API_EXPORT_ENABLED, diff --git a/src/crontab/import/feed.php b/src/crontab/import/feed.php index a1c657e..0cefd3b 100644 --- a/src/crontab/import/feed.php +++ b/src/crontab/import/feed.php @@ -135,6 +135,19 @@ try continue; } + if (empty($manifest->version) || $manifest->version !== API_VERSION) + { + array_push( + $debug['dump'], + sprintf( + _('Manifest API not compatible with local version "%s"'), + API_VERSION + ) + ); + + continue; + } + if (empty($manifest->export)) { array_push(