Files
kimai2/src/Controller/PluginController.php
Kevin Papst 2e6b700b43 Release 2.32 (#5411)
* bump packages
* dynamic invoice options
* make sure that invoice previews can be detected
* support for mpdf associated files
* do not include any future times in work contract calculation
* re-add username column in Excel spreadsheet
* deactivate internal rate editing
* show if plugin update exists
* shorten name to Kimai only, without Time-Tracking
* remove check for existing id in work contract
* fix metafield already defined in search
* helper methods to unlock months
* new translation
* send event on unlock month
2025-04-06 09:53:48 +02:00

82 lines
2.5 KiB
PHP

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Controller;
use App\Plugin\PluginManager;
use App\Utils\PageSetup;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
#[Route(path: '/admin/plugins')]
#[IsGranted('plugins')]
final class PluginController extends AbstractController
{
#[Route(path: '/', name: 'plugins', methods: ['GET'])]
public function indexAction(PluginManager $manager, HttpClientInterface $client, CacheInterface $cache): Response
{
$installed = [];
$plugins = $manager->getPlugins();
foreach ($plugins as $plugin) {
$installed[] = $plugin->getId();
}
$page = new PageSetup('menu.plugin');
$page->setHelp('plugins.html');
$all = $this->getPluginInformation($client, $cache);
$bundles = [];
foreach ($all as $item) {
if ($item['bundle'] !== null) {
$bundles[$item['bundle']] = $item;
}
}
return $this->render('plugin/index.html.twig', [
'page_setup' => $page,
'plugins' => $plugins,
'installed' => $installed,
'extensions' => $all,
'bundles' => $bundles,
]);
}
private function getPluginInformation(HttpClientInterface $client, CacheInterface $cache): array
{
return $cache->get('kimai.marketplace_extensions', function (ItemInterface $item) use ($client) {
try {
$response = $client->request('GET', 'https://www.kimai.org/plugins.json');
if ($response->getStatusCode() !== 200) {
return [];
}
$json = json_decode($response->getContent(), true);
if ($json === null) {
return [];
}
$item->expiresAfter(86400); // one day
return $response->toArray();
} catch (\Throwable $exception) {
$this->logException($exception);
$this->flashError('Could not download plugin information');
}
return [];
});
}
}