-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTasks.php
More file actions
72 lines (61 loc) · 1.84 KB
/
Tasks.php
File metadata and controls
72 lines (61 loc) · 1.84 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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
declare(strict_types=1);
namespace Piwik\Plugins\OpenApiDocs;
use Piwik\Config;
use Piwik\Log\LoggerInterface;
use Piwik\Plugins\OpenApiDocs\Generation\SpecGenerationService;
class Tasks extends \Piwik\Plugin\Tasks
{
/**
* @var SpecGenerationService
*/
private $specGenerationService;
/**
* @var LoggerInterface
*/
private $logger;
public function __construct(SpecGenerationService $specGenerationService, LoggerInterface $logger)
{
$this->specGenerationService = $specGenerationService;
$this->logger = $logger;
}
public function schedule()
{
if ($this->isSpecGenerationEnabled()) {
$this->daily('generateConfiguredPluginSpecs');
}
}
public function generateConfiguredPluginSpecs(): void
{
$pluginNames = require __DIR__ . '/config/plugins.php';
foreach ($pluginNames as $pluginName) {
try {
$this->specGenerationService->generateSpecForPlugins(
$pluginName,
'json',
OpenApiDocs::DEFAULT_SPEC_VERSION,
true,
true
);
} catch (\Throwable $e) {
$this->logger->error(
'OpenApiDocs scheduled generation failed for plugin {plugin}: {error}',
[
'plugin' => $pluginName,
'error' => $e->getMessage(),
]
);
}
}
}
private function isSpecGenerationEnabled(): bool
{
return (bool) (Config::getInstance()->OpenApiDocs['enable_spec_generation_task'] ?? 0);
}
}