Repository navigation
Expand file tree
/
Copy pathUrlModuleUpdate.php
More file actions
136 lines (113 loc) · 3.89 KB
/
Copy pathUrlModuleUpdate.php
File metadata and controls
136 lines (113 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2026 webtrees development team
* <http://webtrees.net>
*
* CustomModuleManager (webtrees custom module):
* Copyright (C) 2026 Markus Hemprich
* <http://www.familienforschung-hemprich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
* CustomModuleManager
*
* A weebtrees(https://webtrees.net) 2.2 custom module to manage custom modules
*
*/
declare(strict_types=1);
namespace Jefferson49\Webtrees\Module\CustomModuleManager\ModuleUpdates;
use Fisharebest\Webtrees\I18N;
use Jefferson49\Webtrees\Module\CustomModuleManager\Exceptions\CustomModuleManagerException;
/**
* Update API for a custom module, which is based on a simple download URL
*/
class UrlModuleUpdate extends AbstractModuleUpdate implements CustomModuleUpdateInterface
{
const NAME = 'URL';
//The download URL
protected string $download_url;
//The documentation URL
protected string $documentation_url;
/**
* @param string $module_name The custom module name
* @param array $params The configuration parameters of the update service
*
* @return void
*/
public function __construct(string $module_name, array $params) {
$this->module_name = $module_name;
if (array_key_exists('conflicts', $params)) {
$this->conflicts = $params['conflicts'];
}
else {
$this->conflicts = [];
}
if (array_key_exists('download_url', $params)) {
$this->download_url = $params['download_url'];
}
else {
throw new CustomModuleManagerException(I18N::translate('Could not create the %s update service. Configuration parameter "%s" missing.', basename(str_replace('\\', '/', __CLASS__)) , 'download_url'));
}
if (array_key_exists('documentation_url', $params)) {
$this->documentation_url = $params['documentation_url'];
}
else {
$this->documentation_url = '';
}
$this->category = self::identifyCategoryFromConfig($module_name, $params);
}
/**
* The name of the module update service
*
* @return string
*/
public function name(): string {
return self::NAME;
}
/**
* Where can we download the module
*
* @param string $version The version of the module; latest version if empty
* @return string
*/
public function downloadurl(/sitelet?url=https%3A%2F%2Fgithub.com%2FJefferson49%2FCustomModuleManager%2Fblob%2Fmain%2Fsrc%2FModuleUpdates%2Fstring%2520%24version%2520%3D%2520%26%23039%3B%26%23039%3B): string
{
return $this->download_url;
}
/**
* Where can we find a documentation for the module
*
* @return string
*/
public function documentationurl(): string
{
return $this->documentation_url;
}
/**
* Get the package name (for custom module list)
*
* @return bool
*/
public function getPackageName(): string {
if (strpos($this->download_url,'codeberg') !== false) {
$package_name = str_replace('https://codeberg.org/', '', $this->download_url);
$slash_position1 = strpos($package_name, '/', 0);
$slash_position2 = strpos($package_name, '/', $slash_position1 + 1);
return substr($package_name, 0, $slash_position2);
}
else {
return $this->name();
}
}
}