[Scummvm-git-logs] scummvm-web master -> 60e02dbf54b6628711031e1f1b87d410f8fecb15
Thunderforge
noreply at scummvm.org
Thu Nov 18 22:04:23 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm-web' repo located at https://github.com/scummvm/scummvm-web .
Summary:
60e02dbf54 DATA: Changing downloads table to use version column (#174)
Commit: 60e02dbf54b6628711031e1f1b87d410f8fecb15
https://github.com/scummvm/scummvm-web/commit/60e02dbf54b6628711031e1f1b87d410f8fecb15
Author: Thunderforge (wjherrmann at gmail.com)
Date: 2021-11-18T16:04:20-06:00
Commit Message:
DATA: Changing downloads table to use version column (#174)
In order to simplify the process of updating version downloads, [downloads spreadsheet table](https://docs.google.com/spreadsheets/d/1QzwFleEKXOsE59cYMOcQB7C2f0Np48uAQOCG8kicX_s/edit#gid=1057392663) now includes a `version` column and the `url` field is much simpler. In order to update a new version, simply change the value in the `version` field.
Further improvements can be made, but for now this is an improvement that keeps parity with the previous code.
Changed paths:
include/Constants.php
include/DataUtils.php
include/Models/DownloadsModel.php
include/Objects/File.php
include/OrmObjects/Download.php
schema.xml
diff --git a/include/Constants.php b/include/Constants.php
index f7d799ee..14aa6d10 100644
--- a/include/Constants.php
+++ b/include/Constants.php
@@ -47,7 +47,7 @@ class Constants
/* Downloads */
define('DOWNLOADS_BASE', 'https://downloads.scummvm.org');
- define('DOWNLOADS_URL', '/frs/scummvm/{$release}/');
+ define('DOWNLOADS_URL', '/frs/scummvm/{$version}/');
define('DOWNLOADS_DAILY_URL', '/frs/daily/');
define('DOWNLOADS_TOOLS_URL', '/frs/scummvm-tools/{$release_tools}/');
define('DOWNLOADS_EXTRAS_URL', '/frs/extras/');
diff --git a/include/DataUtils.php b/include/DataUtils.php
index 42ee7814..5788b60e 100644
--- a/include/DataUtils.php
+++ b/include/DataUtils.php
@@ -31,7 +31,7 @@ class DataUtils
'game_demos' => '713475305',
'series' => '1095671818',
'screenshots' => '1985243204',
- 'scummvm_downloads' => '373699606',
+ 'scummvm_downloads' => '1057392663',
'game_downloads' => '1287892109',
'director_demos' => '1256563740',
];
diff --git a/include/Models/DownloadsModel.php b/include/Models/DownloadsModel.php
index bce60eec..559547f2 100644
--- a/include/Models/DownloadsModel.php
+++ b/include/Models/DownloadsModel.php
@@ -21,8 +21,29 @@ class DownloadsModel extends BasicModel
$sections = [];
$sectionsData = $this->getSectionData();
foreach ($parsedData as $data) {
+ // Source and tools should be under the current section
+ // TODO Clean this up when we remove subcategories
+ if ($data->getVersion() == RELEASE) {
+ $category = 'current';
+ if ($data->getCategory() == 'source') {
+ $subCategory = 'source';
+ } elseif ($data->getCategory() == 'tools') {
+ $subCategory = 'tools';
+ } else {
+ $subCategory = 'release';
+ }
+ } elseif ($data->getVersion() == 'Daily') {
+ $category = 'daily';
+ $subCategory = 'daily_downloads';
+ } elseif ($data->getVersion() == null) {
+ $category = $data->getCategory();
+ $subCategory = $data->getSubcategory();
+ } else {
+ $category = 'legacy';
+ $subCategory = 'old';
+ }
+
// Create Sections
- $category = $data->getCategory();
if (!isset($sections[$category])) {
$sections[$category] = new DownloadsSection([
'anchor' => $category,
@@ -32,7 +53,6 @@ class DownloadsModel extends BasicModel
}
// Create Subsections
- $subCategory = $data->getSubcategory();
if (!isset($sections[$category]->getSubSections()[$subCategory])) {
$sections[$category]->addSubsection(new DownloadsSection([
'anchor' => $subCategory,
@@ -85,11 +105,15 @@ class DownloadsModel extends BasicModel
->setIgnoreCase(true)
->findByUserAgent($os['name']);
- foreach ($downloads as $download) {
- $url = str_replace('{$release}', RELEASE, $download->getURL());
- sscanf($url, "/frs/scummvm/%s", $versionStr);
- $version = substr($versionStr, 0, strpos($versionStr, "/"));
+ if (!empty($downloads)) {
+ $download = $downloads[0];
+
$name = strip_tags($download->getName());
+ // Construct the URL and fill in the version
+ $url = DOWNLOADS_BASE . DOWNLOADS_URL . $download->getURL();
+ $version = $download->getVersion();
+ $url = str_replace('{$version}', $version, $url);
+
$data = ""; //$download->getExtraInfo();
if (is_array($data)) {
$extra_text = $data['size'] . " ";
diff --git a/include/Objects/File.php b/include/Objects/File.php
index 93d4952d..f07eb19b 100644
--- a/include/Objects/File.php
+++ b/include/Objects/File.php
@@ -16,9 +16,9 @@ class File extends BasicObject
parent::__construct($data);
$this->category_icon = $data['category_icon'];
$this->extra_info = $data['extra_info'] ?? null;
+ $this->subcategory = $data['subcategory'] ?? null;
$this->user_agent = isset($data["user_agent"]) ? $data["user_agent"] : "";
-
- $fname = "";
+ $this->version = strtolower($data['version'] ?? null);
/* If it's not an array, we didn't get any attributes. */
if (!is_array($data['url'])) {
@@ -29,18 +29,23 @@ class File extends BasicObject
$attributes = $data['url']['@attributes'];
}
- if (!preg_match('/^((https?)|(ftp)):\/\//', $url)) {
- if ($baseUrl !== null) {
- $url = $baseUrl . $url;
+ if (preg_match('/^((https?)|(ftp)):\/\//', $url)) {
+ // If the URL is given, keep it as is
+ $this->url = $url;
+ } else {
+ // Construct the URL based on its type
+ if ($this->version == 'daily') {
+ $fname = DOWNLOADS_DAILY_URL . $url;
+ } elseif ($this->subcategory == 'tools') {
+ $fname = DOWNLOADS_TOOLS_URL . $url;
+ } elseif (str_starts_with($url, '/frs') || str_starts_with($url, 'http')) {
+ $fname = $url;
} else {
- $url = DOWNLOADS_URL . $url;
+ $fname = DOWNLOADS_URL . $url;
}
+ $fname = str_replace('{$version}', "$this->version", $fname);
- $fname = "." . $url;
- $fname = str_replace('{$release}', RELEASE, $fname);
- $fname = str_replace('{$release_tools}', RELEASE_TOOLS, $fname);
- $fname = str_replace('./frs', DIR_FRS, $fname);
-
+ // If the file is on this server, we can check file size etc.
if (is_file($fname) && is_readable($fname)) {
$this->extra_info = array();
$sz = round((@filesize($fname) / 1024));
@@ -77,8 +82,8 @@ class File extends BasicObject
$this->extra_info['ext'] = $ext;
$this->extra_info['msg'] = $data['extra_msg'];
}
+ $this->url = $fname;
}
- $this->url = $url;
/**
* Get the filesize/last modified information and put it in
* $this->extra_info.
diff --git a/include/OrmObjects/Download.php b/include/OrmObjects/Download.php
index 66275d01..3b14e7b0 100644
--- a/include/OrmObjects/Download.php
+++ b/include/OrmObjects/Download.php
@@ -15,5 +15,14 @@ use ScummVM\OrmObjects\Base\Download as BaseDownload;
*/
class Download extends BaseDownload
{
-
+ public function getName()
+ {
+ $name = parent::getName();
+ $version = $this->getVersion();
+ // If it's not the latest version, prefix with the version number
+ if ($version != RELEASE) {
+ return "$version $name";
+ }
+ return $name;
+ }
}
diff --git a/schema.xml b/schema.xml
index 61dbef8a..9e8c835e 100644
--- a/schema.xml
+++ b/schema.xml
@@ -110,6 +110,7 @@
<column name="enabled" type="boolean" />
<column name="user_agent" type="varchar" size="255"/>
<column name="url" type="varchar" size="255" required="true"/>
+ <column name="version" type="varchar" size="24" required="false"/>
</table>
<table name="game_downloads" phpName="GameDownload">
<column name="category" type="varchar" size="24" required="true"/>
More information about the Scummvm-git-logs
mailing list