8 namespace Fossology\UI\Page;
13 use Symfony\Component\HttpFoundation\File\UploadedFile;
14 use Symfony\Component\HttpFoundation\Request;
15 use Symfony\Component\HttpFoundation\Response;
22 const NAME =
"admin_license_from_yaml";
23 const KEY_UPLOAD_MAX_FILESIZE =
'upload_max_filesize';
24 function __construct()
26 parent::__construct(self::NAME, array(
27 self::TITLE =>
"Admin License Rules Import",
28 self::MENU_LIST =>
"Admin::License Admin::Rules Import",
29 self::REQUIRES_LOGIN =>
true,
37 protected function handle (Request $request)
40 if ($request->isMethod(
'POST')) {
41 $uploadFile = $request->files->get(
'file_input');
42 $vars[
'message'] = $this->handleFileUpload($uploadFile);
44 $vars[self::KEY_UPLOAD_MAX_FILESIZE] = ini_get(self::KEY_UPLOAD_MAX_FILESIZE);
45 $vars[
'baseUrl'] = $request->getBaseUrl();
46 return $this->
render(
"admin_license_from_yaml.html.twig", $this->mergeWithDefault($vars));
53 protected function handleFileUpload($uploadedFile)
56 if (! ($uploadedFile instanceof UploadedFile)) {
57 $errMsg = _(
"No file selected");
58 } elseif ($uploadedFile->getError() !== UPLOAD_ERR_OK) {
59 $errMsg = $uploadedFile->getErrorMessage();
60 } elseif ($uploadedFile->getSize() == 0 && $uploadedFile->getError() == 0) {
61 $errMsg = _(
"Larger than upload_max_filesize ") .
62 ini_get(self::KEY_UPLOAD_MAX_FILESIZE);
63 } elseif ($uploadedFile->getClientOriginalExtension() !=
'yaml' &&
64 $uploadedFile->getClientOriginalExtension() !=
'yml') {
65 $errMsg = _(
'Invalid extension ') .
66 $uploadedFile->getClientOriginalExtension() .
' of file ' .
67 $uploadedFile->getClientOriginalName();
69 if (! empty($errMsg)) {
73 $licenseYamlImport = $this->
getObject(
'app.license_yaml_import');
74 return $licenseYamlImport->handleFile($uploadedFile->getRealPath());
78 register_plugin(
new AdminLicenseFromYAML());
Import licenses from YAML.
Contains the constants and helpers for authentication of user.
render($templateName, $vars=null, $headers=null)
Upload a file from the users computer using the UI.