FOSSology  4.5.1
Open Source License Compliance by Open Source Software
AdminLicenseToYAML.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2024 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\UI\Page;
9 
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
18 
20 {
21  const NAME = "admin_license_to_yaml";
22 
23  function __construct()
24  {
25  parent::__construct(self::NAME, array(
26  self::TITLE => "Admin License Rules Export",
27  self::MENU_LIST => "Admin::License Admin::Rules Export",
28  self::REQUIRES_LOGIN => true,
29  self::PERMISSION => Auth::PERM_ADMIN
30  ));
31  }
32 
37  protected function handle(Request $request)
38  {
39  $confirmed = $request->get('confirmed', false);
40  $referer = $request->headers->get('referer');
41  $fileName = "fossology-license-comp-rules-export-" . date("YMj-Gis") . '.yaml';
42 
43  if (!$confirmed) {
44  $downloadUrl = "?mod=" . self::NAME . "&confirmed=true";
45  return DownloadUtil::getDownloadConfirmationResponse($downloadUrl, $fileName, $referer);
46  }
47 
49  $dbManager = $this->getObject('db.manager');
51  $compatibilityDao = $this->getObject('dao.compatibility');
52  $licenseYamlExport = new LicenseCompatibilityRulesYamlExport($dbManager,
53  $compatibilityDao);
54  $content = $licenseYamlExport->createYaml(0);
55  return DownloadUtil::getDownloadResponse($content, $fileName, 'text/x-yaml');
56  }
57 }
58 
59 register_plugin(new AdminLicenseToYAML());
Helper class to export license list as a YAML from the DB.
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
static getDownloadConfirmationResponse($downloadUrl, $fileName, $referer)
static getDownloadResponse($content, $fileName, $contentType='text/csv')