-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessTextSynthesisConfig.php
More file actions
116 lines (97 loc) · 3.37 KB
/
ProcessTextSynthesisConfig.php
File metadata and controls
116 lines (97 loc) · 3.37 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
<?php
namespace ProcessWire;
class ProcessTextSynthesisConfig extends ModuleConfig {
public bool $hasLazyCron = false;
public function __construct() {
parent::__construct();
$this->hasLazyCron = modules()->isInstalled('LazyCron');
}
/**
* @return array
* @throws WirePermissionException
*/
public function getDefaults(): array {
// get schedules from Lazy Cron (if installed)
if($this->hasLazyCron) {
/** @var LazyCron $lazyCronInstance */
$lazyCronInstance = modules()->get('LazyCron');
$getTimeFuncsFunction = function(){ return $this->timeFuncs; };
}
return [
'endpoint' => 'https://texttospeech.googleapis.com/v1beta1/',
'apiKey' => '',
'cronSchedule' => 300,
'cronParallelCalls' => 3,
'deleteCompleted' => true,
'deleteCompletedAfter' => 86400,
'timeFuncs' => $this->hasLazyCron ? $getTimeFuncsFunction->call($lazyCronInstance) : []
];
}
public function getInputfields(): InputfieldWrapper {
$inputfields = parent::getInputfields();
$inputfields->add([
'type' => 'Url',
'name' => 'endpoint',
'label' => __('API URL'),
'description' => __('Insert the Google API URL.'),
'columnWidth' => 50
]);
$inputfields->add([
'type' => 'text',
'name' => 'apiKey',
'label' => __('API Key'),
'description' => __('Enter your API key here. If you do not yet have an API key, you can generate one in the [Credentials area](https://console.cloud.google.com/apis/credentials) of the Google Cloud Console.'),
'columnWidth' => 50
]);
$fieldset = new InputfieldFieldset();
$fieldset->label = __('LazyCron');
if($this->hasLazyCron) {
/** @var InputfieldSelect */
$fieldset->add([
'type' => 'Select',
'name' => 'cronSchedule',
'label' => __('Schedule'),
'description' => __('If selected, the LazyCron will process the jobs in the queue.'),
'options' => $this->get('timeFuncs'),
'columnWidth' => 50
]);
/** @var InputfieldInteger */
$fieldset->add([
'type' => 'Integer',
'name' => 'cronParallelCalls',
'label' => __('Parallel calls'),
'min' => 0,
'max' => 1000,
'attr' => ['style' => 'width: -webkit-fill-available'],
'inputType' => 'number',
'description' => __('Number of job executions per cron call. 0 means all.'),
'columnWidth' => 50
]);
} else {
$fieldset->description = __('Install the LazyCron core module to automatically process the synthesis queue or use another automatic trigger to call the `ProcessTextSynthesis::runQueue()` function.');
$fieldset->appendMarkup = '<a href="'.config()->urls->admin . 'module/installConfirm?name=LazyCron'.'" class="">'.__('Click to install LazyCron').'</a>';
}
$inputfields->add($fieldset);
/** @var InputfieldInteger */
$inputfields->add([
'type' => 'Checkbox',
'name' => 'deleteCompleted',
'label' => __('Should completed jobs be deleted?'),
'checkboxLabel' => __('Delete completed jobs'),
'columnWidth' => 50
]);
/** @var InputfieldInteger */
$inputfields->add([
'type' => 'Integer',
'name' => 'deleteCompletedAfter',
'label' => __('Seconds after completed jobs are deleted.'),
'notes' => __("0 sec. immediately \n3600 sec. 1 hour \n86400 sec. 1 day \n604800 sec. 1 week"),
'min' => 0,
'attr' => ['style' => 'width: -webkit-fill-available'],
'inputType' => 'number',
'showIf' => 'deleteCompleted=1',
'columnWidth' => 50
]);
return $inputfields;
}
}