34 const NAME =
"admin_license_from_csv";
35 const KEY_UPLOAD_MAX_FILESIZE =
'upload_max_filesize';
37 function __construct()
39 parent::__construct(self::NAME, array(
40 self::TITLE =>
"Admin License CSV Import",
41 self::MENU_LIST =>
"Admin::License Admin::CSV Import",
42 self::REQUIRES_LOGIN =>
true,
51 protected function handle (Request $request)
55 if ($request->isMethod(
'POST')) {
56 $uploadFile = $request->files->get(
'file_input');
57 $delimiter = $request->get(
'delimiter') ?:
',';
58 $enclosure = $request->get(
'enclosure') ?:
'"';
59 $vars[
'message'] = $this->handleFileUpload($uploadFile, $delimiter,
63 $vars[self::KEY_UPLOAD_MAX_FILESIZE] = ini_get(self::KEY_UPLOAD_MAX_FILESIZE);
64 $vars[
'baseUrl'] = $request->getBaseUrl();
66 return $this->
render(
"admin_license_from_csv.html.twig", $this->mergeWithDefault($vars));
73 protected function handleFileUpload($uploadedFile,$delimiter=
',',$enclosure=
'"')
76 if (! ($uploadedFile instanceof UploadedFile)) {
77 $errMsg = _(
"No file selected");
78 } elseif ($uploadedFile->getError() !== UPLOAD_ERR_OK) {
79 $errMsg = $uploadedFile->getErrorMessage();
80 } elseif ($uploadedFile->getSize() == 0 && $uploadedFile->getError() == 0) {
81 $errMsg = _(
"Larger than upload_max_filesize ") .
82 ini_get(self::KEY_UPLOAD_MAX_FILESIZE);
83 } elseif ($uploadedFile->getClientOriginalExtension() !=
'csv') {
84 $errMsg = _(
'Invalid extension ') .
85 $uploadedFile->getClientOriginalExtension() .
' of file ' .
86 $uploadedFile->getClientOriginalName();
88 if (! empty($errMsg)) {
92 $licenseCsvImport = $this->
getObject(
'app.license_csv_import');
93 $licenseCsvImport->setDelimiter($delimiter);
94 $licenseCsvImport->setEnclosure($enclosure);
95 return $licenseCsvImport->handleFile($uploadedFile->getRealPath());
Upload a file from the users computer using the UI.
render($templateName, $vars=null, $headers=null)