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
|
<?php
ConfigModule::registerModule(
ConfigModule_CustomModule::MODID, // ID
Dictionary::translateFile('config-module', 'custom_title'), // Title
Dictionary::translateFile('config-module', 'custom_description'), // Description
Dictionary::translateFile('config-module', 'group_generic'), // Group
false, // Only one per config?
900 // Sort order
);
class ConfigModule_CustomModule extends ConfigModule
{
const MODID = 'CustomModule';
const VERSION = 2;
/** @var false|string */
private $tmpFile = false;
protected function generateInternal(string $tgz, ?string $parent)
{
if (!$this->validateConfig()) {
// No temp file given from wizard
// Old archive still exists? pretend it worked...
if ($this->archive() === '' || !file_exists($this->archive()))
return false;
if ($this->currentVersion() == 1) {
// Need an upgrade
return Taskmanager::submit('RecompressArchive', array(
'inputFiles' => [$this->archive() => false],
'outputFile' => $tgz,
'forceRoot' => true, // Force this for old modules for backward compat
));
}
// Nothing to do
return true;
}
return Taskmanager::submit('MoveFile', array(
'source' => $this->tmpFile,
'destination' => $tgz,
'parentTask' => $parent,
'failOnParentFail' => false
));
}
protected function moduleVersion(): int
{
return self::VERSION;
}
protected function validateConfig(): bool
{
return $this->tmpFile !== false && file_exists($this->tmpFile);
}
public function setData(string $key, $value): bool
{
// Sets the temp file from the wizard, where it stored the processed archive
if ($key !== 'tmpFile' || !file_exists($value))
return false;
$this->tmpFile = $value;
return true;
}
public function getData(?string $key): bool
{
return false;
}
public function allowDownload(): bool
{
return true;
}
}
|