Browse Source

add API version check #13, #14

main
ghost 1 year ago
parent
commit
fe2a7a575f
  1. 2
      example/environment/env.example.php
  2. 4
      src/config/bootstrap.php
  3. 2
      src/crontab/export/feed.php
  4. 13
      src/crontab/import/feed.php

2
example/environment/env.example.php

@ -165,8 +165,6 @@ define('NODE_RULE_SUBJECT', 'Common');
define('NODE_RULE_LANGUAGES', 'All'); define('NODE_RULE_LANGUAGES', 'All');
// API // API
define('API_VERSION', '1.0.0');
define('API_USER_AGENT', WEBSITE_NAME); define('API_USER_AGENT', WEBSITE_NAME);
/// Export /// Export

4
src/config/bootstrap.php

@ -3,6 +3,10 @@
// PHP // PHP
declare(strict_types=1); declare(strict_types=1);
// Application
define('APP_VERSION', '2.0.0');
define('API_VERSION', APP_VERSION);
// Init environment // Init environment
if (!file_exists(__DIR__ . '/.env')) if (!file_exists(__DIR__ . '/.env'))
{ {

2
src/crontab/export/feed.php

@ -59,6 +59,7 @@ try
$manifest = $manifest =
[ [
'updated' => time(), 'updated' => time(),
'version' => (string) API_VERSION,
'settings' => (object) 'settings' => (object)
[ [
@ -119,7 +120,6 @@ try
'MAGNET_STOP_WORDS_SIMILAR' => (object) MAGNET_STOP_WORDS_SIMILAR, 'MAGNET_STOP_WORDS_SIMILAR' => (object) MAGNET_STOP_WORDS_SIMILAR,
'API_VERSION' => (string) API_VERSION,
'API_USER_AGENT' => (string) API_USER_AGENT, 'API_USER_AGENT' => (string) API_USER_AGENT,
'API_EXPORT_ENABLED' => (bool) API_EXPORT_ENABLED, 'API_EXPORT_ENABLED' => (bool) API_EXPORT_ENABLED,

13
src/crontab/import/feed.php

@ -135,6 +135,19 @@ try
continue; 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)) if (empty($manifest->export))
{ {
array_push( array_push(

Loading…
Cancel
Save