mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 05:43:55 -07:00
Updated
This commit is contained in:
parent
eb24dc1c85
commit
204d196ba5
4 changed files with 100 additions and 129 deletions
84
common.php
84
common.php
|
@ -348,96 +348,12 @@ function sys(string $param)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns version code
|
||||
*
|
||||
* Notice: Compatible only with SemVer versioning!
|
||||
*
|
||||
* @param string $version
|
||||
* @return int
|
||||
*/
|
||||
function version_code(string $version): int
|
||||
{
|
||||
$finalVersionCode = [];
|
||||
$finalVersionCode['releaseType'] = 0;
|
||||
$finalVersionCode['releaseTypeIndex'] = 0;
|
||||
|
||||
$version = trim($version);
|
||||
$version = ltrim($version, 'v');
|
||||
|
||||
/**
|
||||
* Get version parts
|
||||
*
|
||||
* - Example: 2.0.0-rc.1
|
||||
* -- versionCode: 2.0.0
|
||||
* -- releaseType: rc.1
|
||||
*/
|
||||
if (str_contains($version, '-')) {
|
||||
$versionParts = explode('-', $version);
|
||||
[$versionCode, $releaseType] = $versionParts;
|
||||
} else {
|
||||
$versionCode = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get version code parts (major, minor, path)
|
||||
*
|
||||
* - Example: 2.0.0
|
||||
* -- majorVerIndex: 2
|
||||
* -- minorVerIndex: 0
|
||||
* -- pathVerIndex: 0
|
||||
*/
|
||||
$versionCodeParts = explode('.', $versionCode);
|
||||
[$majorVerIndex, $minorVerIndex, $pathVerIndex] = $versionCodeParts;
|
||||
|
||||
/**
|
||||
* Get release type
|
||||
*
|
||||
* - Example:
|
||||
* -- releaseTypeName: alpha, beta, rc
|
||||
* -- releaseTypeIndex: 1, 2, 3...
|
||||
*/
|
||||
if (!empty($releaseType)) {
|
||||
$releaseTypeParts = explode('.', $releaseType);
|
||||
[$releaseTypeName, $releaseTypeIndex] = $releaseTypeParts;
|
||||
|
||||
switch ($releaseTypeName) {
|
||||
case 'alpha':
|
||||
$finalVersionCode['releaseType'] = 1;
|
||||
break;
|
||||
case 'beta':
|
||||
$finalVersionCode['releaseType'] = 2;
|
||||
break;
|
||||
case 'rc':
|
||||
$finalVersionCode['releaseType'] = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
$minorVerIndex -= 1;
|
||||
$finalVersionCode['releaseTypeIndex'] = (int)$releaseTypeIndex;
|
||||
}
|
||||
|
||||
$finalVersionCode['major'] = (int)$majorVerIndex;
|
||||
$finalVersionCode['minor'] = (int)$minorVerIndex;
|
||||
$finalVersionCode['path'] = (int)$pathVerIndex;
|
||||
|
||||
return
|
||||
$finalVersionCode['major'] .
|
||||
$finalVersionCode['minor'] .
|
||||
$finalVersionCode['path'] .
|
||||
$finalVersionCode['releaseType'] .
|
||||
$finalVersionCode['releaseTypeIndex'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Some shared defines
|
||||
*/
|
||||
// Initialize demo mode
|
||||
define('IN_DEMO_MODE', env('APP_DEMO_MODE', false));
|
||||
|
||||
// Version code
|
||||
define('VERSION_CODE', version_code($bb_cfg['tp_version']));
|
||||
|
||||
// Ratio status
|
||||
define('RATIO_ENABLED', TR_RATING_LIMITS && MIN_DL_FOR_RATIO > 0);
|
||||
|
||||
|
|
|
@ -72,7 +72,8 @@
|
|||
"symfony/mime": "^6.4",
|
||||
"symfony/mailer": "^6.4",
|
||||
"symfony/polyfill": "v1.31.0",
|
||||
"vlucas/phpdotenv": "^5.5"
|
||||
"vlucas/phpdotenv": "^5.5",
|
||||
"phlak/semver": "^6.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^6.4"
|
||||
|
|
120
composer.lock
generated
120
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "5cd54867fb93869122d1d00ee6f2764b",
|
||||
"content-hash": "de75685b481f8d8694cba90f09ad8b2b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "arokettu/bencode",
|
||||
|
@ -1791,12 +1791,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/matthiasmullie/scrapbook.git",
|
||||
"reference": "510129d83dd21b29d0fde6886a7a08d435d1ae65"
|
||||
"reference": "6ca64d54d7106deffbb98cb9c6a6f5fdb13ce1f1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/matthiasmullie/scrapbook/zipball/510129d83dd21b29d0fde6886a7a08d435d1ae65",
|
||||
"reference": "510129d83dd21b29d0fde6886a7a08d435d1ae65",
|
||||
"url": "https://api.github.com/repos/matthiasmullie/scrapbook/zipball/6ca64d54d7106deffbb98cb9c6a6f5fdb13ce1f1",
|
||||
"reference": "6ca64d54d7106deffbb98cb9c6a6f5fdb13ce1f1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1875,7 +1875,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/matthiasmullie/scrapbook/issues",
|
||||
"source": "https://github.com/matthiasmullie/scrapbook/tree/master"
|
||||
"source": "https://github.com/matthiasmullie/scrapbook/tree/1.5.4"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -1883,7 +1883,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2024-05-30T09:05:39+00:00"
|
||||
"time": "2024-12-20T11:47:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
|
@ -2040,6 +2040,64 @@
|
|||
},
|
||||
"time": "2024-03-19T20:45:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phlak/semver",
|
||||
"version": "6.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHLAK/SemVer.git",
|
||||
"reference": "59dc259f7b734bcdf17c2072c35131e0b0e250d3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHLAK/SemVer/zipball/59dc259f7b734bcdf17c2072c35131e0b0e250d3",
|
||||
"reference": "59dc259f7b734bcdf17c2072c35131e0b0e250d3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.1 || ^8.2 || ^8.3 || ^8.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phlak/coding-standards": "^4.0",
|
||||
"phpstan/phpstan": "^2.0",
|
||||
"yoast/phpunit-polyfills": "^3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/Support/helpers.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"PHLAK\\SemVer\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Chris Kankiewicz",
|
||||
"email": "Chris@ChrisKankiewicz.com"
|
||||
}
|
||||
],
|
||||
"description": "Semantic versioning helper library",
|
||||
"support": {
|
||||
"issues": "https://github.com/PHLAK/SemVer/issues",
|
||||
"source": "https://github.com/PHLAK/SemVer/tree/6.1.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/sponsors/PHLAK",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://paypal.me/ChrisKankiewicz",
|
||||
"type": "paypal"
|
||||
}
|
||||
],
|
||||
"time": "2024-12-11T16:29:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "php-curl-class/php-curl-class",
|
||||
"version": "11.0.0",
|
||||
|
@ -2809,12 +2867,12 @@
|
|||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/contracts",
|
||||
"name": "symfony/contracts"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-main": "3.5-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -2957,12 +3015,12 @@
|
|||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/contracts",
|
||||
"name": "symfony/contracts"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-main": "3.5-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -3081,16 +3139,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/finder",
|
||||
"version": "v6.4.13",
|
||||
"version": "v6.4.17",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/finder.git",
|
||||
"reference": "daea9eca0b08d0ed1dc9ab702a46128fd1be4958"
|
||||
"reference": "1d0e8266248c5d9ab6a87e3789e6dc482af3c9c7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/finder/zipball/daea9eca0b08d0ed1dc9ab702a46128fd1be4958",
|
||||
"reference": "daea9eca0b08d0ed1dc9ab702a46128fd1be4958",
|
||||
"url": "https://api.github.com/repos/symfony/finder/zipball/1d0e8266248c5d9ab6a87e3789e6dc482af3c9c7",
|
||||
"reference": "1d0e8266248c5d9ab6a87e3789e6dc482af3c9c7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -3125,7 +3183,7 @@
|
|||
"description": "Finds files and directories via an intuitive fluent interface",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/finder/tree/v6.4.13"
|
||||
"source": "https://github.com/symfony/finder/tree/v6.4.17"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -3141,7 +3199,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-10-01T08:30:56+00:00"
|
||||
"time": "2024-12-29T13:51:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/mailer",
|
||||
|
@ -3225,16 +3283,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/mime",
|
||||
"version": "v6.4.13",
|
||||
"version": "v6.4.17",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/mime.git",
|
||||
"reference": "1de1cf14d99b12c7ebbb850491ec6ae3ed468855"
|
||||
"reference": "ea87c8850a54ff039d3e0ab4ae5586dd4e6c0232"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/mime/zipball/1de1cf14d99b12c7ebbb850491ec6ae3ed468855",
|
||||
"reference": "1de1cf14d99b12c7ebbb850491ec6ae3ed468855",
|
||||
"url": "https://api.github.com/repos/symfony/mime/zipball/ea87c8850a54ff039d3e0ab4ae5586dd4e6c0232",
|
||||
"reference": "ea87c8850a54ff039d3e0ab4ae5586dd4e6c0232",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -3290,7 +3348,7 @@
|
|||
"mime-type"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/mime/tree/v6.4.13"
|
||||
"source": "https://github.com/symfony/mime/tree/v6.4.17"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -3306,7 +3364,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-10-25T15:07:50+00:00"
|
||||
"time": "2024-12-02T11:09:41+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill",
|
||||
|
@ -3447,12 +3505,12 @@
|
|||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/contracts",
|
||||
"name": "symfony/contracts"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-main": "3.5-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -3690,6 +3748,6 @@
|
|||
"platform": {
|
||||
"php": "^8.1 | ^8.2 | ^8.3 | ^8.4"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
|
|
@ -23,27 +23,23 @@ $updaterDownloader = new \TorrentPier\Updater();
|
|||
$updaterDownloader = $updaterDownloader->getLastVersion($bb_cfg['tp_updater_settings']['allow_pre_releases']);
|
||||
|
||||
$getVersion = $updaterDownloader['tag_name'];
|
||||
$versionCodeActual = version_code($getVersion);
|
||||
$versionActual = new PHLAK\SemVer\Version($getVersion);
|
||||
$currentVersion = new PHLAK\SemVer\Version($bb_cfg['tp_version']);
|
||||
|
||||
// Has update!
|
||||
if (VERSION_CODE < $versionCodeActual) {
|
||||
if ($versionActual->gt($currentVersion)) {
|
||||
$latestBuildFileLink = $updaterDownloader['assets'][0]['browser_download_url'];
|
||||
|
||||
// Check updater file
|
||||
$updater_file = readUpdaterFile();
|
||||
$updater_need_replaced = !empty($updater_file) && ($updater_file['latest_version']['short_code'] < $versionCodeActual);
|
||||
$updaterFile = readUpdaterFile();
|
||||
$versionFromUpdaterFile = new PHLAK\SemVer\Version($updaterFile['latest_version']);
|
||||
$updaterNeedReplaced = !empty($updaterFile) && ($versionActual->gt($versionFromUpdaterFile));
|
||||
|
||||
// Save current version & latest available
|
||||
if (!is_file(UPDATER_FILE) || $updater_need_replaced) {
|
||||
if (!is_file(UPDATER_FILE) || $updaterNeedReplaced) {
|
||||
file_write(json_encode([
|
||||
'previous_version' => [
|
||||
'short_code' => VERSION_CODE,
|
||||
'version' => $bb_cfg['tp_version']
|
||||
],
|
||||
'latest_version' => [
|
||||
'short_code' => $versionCodeActual,
|
||||
'version' => $getVersion
|
||||
]
|
||||
'previous_version' => $bb_cfg['tp_version'],
|
||||
'latest_version' => $getVersion
|
||||
]), UPDATER_FILE, replace_content: true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue