Skip to content
Snippets Groups Projects
Commit 03c36eb1 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

add link to installation documentation and increase filesize speed, fixes #45

parent 27b9ff56
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ final class ReleasesController extends \TracToGitlab\Controller ...@@ -4,6 +4,7 @@ final class ReleasesController extends \TracToGitlab\Controller
const CACHE_KEY = 'studip-releases'; const CACHE_KEY = 'studip-releases';
private static $curl_handle = null; private static $curl_handle = null;
private $filesize_cache;
public function before_filter(&$action, &$args) public function before_filter(&$action, &$args)
{ {
...@@ -26,7 +27,18 @@ final class ReleasesController extends \TracToGitlab\Controller ...@@ -26,7 +27,18 @@ final class ReleasesController extends \TracToGitlab\Controller
Icon::create('link2'), Icon::create('link2'),
['target' => '_blank'] ['target' => '_blank']
); );
$widget->addLink(
_('Installationsanleitung'),
'https://hilfe.studip.de/admin/Admins/Installationsanleitung',
Icon::create('rescue'),
['target' => '_blank']
);
Sidebar::get()->addWidget($widget); Sidebar::get()->addWidget($widget);
$this->filesize_cache = new StudipCachedArray(
self::CACHE_KEY . '/filesizes',
strtotime('+10 years')
);
} }
public function after_filter($action, $args) public function after_filter($action, $args)
...@@ -40,7 +52,7 @@ final class ReleasesController extends \TracToGitlab\Controller ...@@ -40,7 +52,7 @@ final class ReleasesController extends \TracToGitlab\Controller
public function index_action() public function index_action()
{ {
$version = Request::get('version'); $version = Request::get('version', Request::get('v'));
$this->releases = $this->getReleases(); $this->releases = $this->getReleases();
...@@ -58,6 +70,7 @@ final class ReleasesController extends \TracToGitlab\Controller ...@@ -58,6 +70,7 @@ final class ReleasesController extends \TracToGitlab\Controller
{ {
if ($this->isAdmin()) { if ($this->isAdmin()) {
StudipCacheFactory::getCache()->expire(self::CACHE_KEY); StudipCacheFactory::getCache()->expire(self::CACHE_KEY);
$this->filesize_cache->expire();
} }
$this->relocate($this->indexURL()); $this->relocate($this->indexURL());
...@@ -159,37 +172,41 @@ final class ReleasesController extends \TracToGitlab\Controller ...@@ -159,37 +172,41 @@ final class ReleasesController extends \TracToGitlab\Controller
return $hardcoded_size; return $hardcoded_size;
} }
// Init curl if necessary if (!isset($this->filesize_cache[$url])) {
if (self::$curl_handle === null) { // Init curl if necessary
self::$curl_handle = curl_init(null); if (self::$curl_handle === null) {
self::$curl_handle = curl_init(null);
curl_setopt(self::$curl_handle, CURLOPT_HEADER, true); curl_setopt(self::$curl_handle, CURLOPT_HEADER, true);
curl_setopt(self::$curl_handle, CURLOPT_NOBODY, true); curl_setopt(self::$curl_handle, CURLOPT_NOBODY, true);
curl_setopt(self::$curl_handle, CURLOPT_RETURNTRANSFER, true); curl_setopt(self::$curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt(self::$curl_handle, CURLOPT_FOLLOWLOCATION, true); curl_setopt(self::$curl_handle, CURLOPT_FOLLOWLOCATION, true);
} }
// Set url and send request // Set url and send request
curl_setopt(self::$curl_handle, CURLOPT_URL, $url); curl_setopt(self::$curl_handle, CURLOPT_URL, $url);
$response = curl_exec(self::$curl_handle); $response = curl_exec(self::$curl_handle);
// Get status // Get status
$line = strtok($response, "\r\n"); $line = strtok($response, "\r\n");
$status = trim($line); $status = trim($line);
// Parse headers // Parse headers
$headers = []; $headers = [];
while (($line = strtok("\r\n")) !== false) { while (($line = strtok("\r\n")) !== false) {
$chunks = explode(':', $line, 2); $chunks = explode(':', $line, 2);
if ($chunks !== false && count($chunks) === 2) { if ($chunks !== false && count($chunks) === 2) {
$headers[$chunks[0]] = $chunks[1]; $headers[$chunks[0]] = $chunks[1];
}
} }
}
// TODO: Check status // TODO: Check status
// Get filesize by Content-Length header
$this->filesize_cache[$url] = (int) ($headers['Content-Length'] ?? -1);
}
// Get filesize by Content-Length header return $this->filesize_cache[$url];
return (int) ($headers['Content-Length'] ?? -1);
} }
private function addVersionFilter(array $releases, ?string $version): void private function addVersionFilter(array $releases, ?string $version): void
......
...@@ -2,5 +2,5 @@ pluginname=Trac to gitlab converter ...@@ -2,5 +2,5 @@ pluginname=Trac to gitlab converter
pluginclassname=TracToGitlabPlugin pluginclassname=TracToGitlabPlugin
pluginclassname=StudipReleasesPlugin pluginclassname=StudipReleasesPlugin
origin=UOL origin=UOL
version=1.4.2 version=1.4.3
studipMinVersion=5.0 studipMinVersion=5.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment