Skip to content

Commit

Permalink
fixed error messages and symlink command
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Jan 22, 2019
1 parent 4b1ca77 commit b527605
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 35 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.1.3] - 2019-01-22

#### Fixed
- error with non working error messages due incompatible error responses
- symlink command if temp folder not symlinked

## [1.1.2] - 2019-01-08

#### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/MultiFileUpload.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ContaoManager/Plugin.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/MultiFileUploadExtension.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
6 changes: 3 additions & 3 deletions src/EventListener/HookListener.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand All @@ -14,9 +14,9 @@
use Contao\DataContainer;
use Contao\Widget;
use HeimrichHannot\AjaxBundle\Response\Response;
use HeimrichHannot\AjaxBundle\Response\ResponseError;
use HeimrichHannot\MultiFileUploadBundle\Backend\MultiFileUpload;
use HeimrichHannot\MultiFileUploadBundle\Form\FormMultiFileUpload;
use HeimrichHannot\MultiFileUploadBundle\Response\DropzoneErrorResponse;
use Psr\Log\LogLevel;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -57,7 +57,7 @@ public function executePostActionsHook(string $action, DataContainer $dc)
['contao' => new ContaoContext(__CLASS__.'::'.__METHOD__, TL_ERROR)]
);

$objResponse = new ResponseError();
$objResponse = new DropzoneErrorResponse();
$objResponse->setMessage('Bad Request');
$objResponse->output();
}
Expand Down
44 changes: 29 additions & 15 deletions src/Form/FormMultiFileUpload.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand All @@ -20,10 +20,11 @@
use Contao\Upload;
use Contao\Validator;
use HeimrichHannot\AjaxBundle\Response\ResponseData;
use HeimrichHannot\AjaxBundle\Response\ResponseError;
use HeimrichHannot\AjaxBundle\Response\ResponseSuccess;
use HeimrichHannot\MultiFileUploadBundle\Backend\MultiFileUpload;
use HeimrichHannot\MultiFileUploadBundle\Response\DropzoneErrorResponse;
use Model\Collection;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
Expand Down Expand Up @@ -179,7 +180,9 @@ public function moveFiles(DataContainer $dc)
}

/**
* @return ResponseError|ResponseSuccess
* @throws \Exception
*
* @return ResponseSuccess|DropzoneErrorResponse|void
*/
public function upload()
{
Expand All @@ -189,7 +192,7 @@ public function upload()
$varReturn = null;
// check for the request token
if (!$request->hasPost('requestToken') || !\RequestToken::validate($request->getPost('requestToken'))) {
$objResponse = new ResponseError();
$objResponse = new DropzoneErrorResponse();
$objResponse->setMessage('Invalid Request Token!');
$objResponse->output();
}
Expand All @@ -198,17 +201,28 @@ public function upload()
return;
}

$objTmpFolder = new Folder($container->getParameter('huh.multifileupload.upload_tmp'));
$tempUploadFolder = new Folder($container->getParameter('huh.multifileupload.upload_tmp'));

// tmp directory is not public, mandatory for preview images
if (!file_exists($this->container->getParameter('contao.web_dir')
.\DIRECTORY_SEPARATOR
.$this->container->getParameter('huh.multifileupload.upload_tmp'))
$tmpPath = $this->container->getParameter('contao.web_dir').\DIRECTORY_SEPARATOR.$this->container->getParameter('huh.multifileupload.upload_tmp');

if (!file_exists($tmpPath)
) {
$objTmpFolder->unprotect();
$input = new ArrayInput([]);
$output = new NullOutput();
$this->container->get('contao.command.symlinks')->run($input, $output);
try {
$tempUploadFolder->unprotect();
$application = new Application($container->get('kernel'));
$application->setAutoExit(false);

$input = new ArrayInput([
'command' => 'contao:symlinks',
]);
$output = new NullOutput();
$application->run($input, $output);
} catch (\Exception $e) {
$objResponse = new DropzoneErrorResponse();
$objResponse->setMessage('Error at running symlink command: '.$e->getMessage());
$objResponse->output();
}
}

$strField = $this->name;
Expand All @@ -217,7 +231,7 @@ public function upload()
if (\is_array($varFile)) {
// prevent disk flooding
if (\count($varFile) > $this->maxFiles) {
$objResponse = new ResponseError();
$objResponse = new DropzoneErrorResponse();
$objResponse->setMessage('Bulk file upload violation.');
$objResponse->output();
}
Expand All @@ -226,7 +240,7 @@ public function upload()
* @var UploadedFile
*/
foreach ($varFile as $strKey => $objFile) {
$arrFile = $this->uploadFile($objFile, $objTmpFolder->path);
$arrFile = $this->uploadFile($objFile, $tempUploadFolder->path);
$varReturn[] = $arrFile;

if (isset($varReturn['uuid']) && Validator::isUuid($arrFile['uuid'])) {
Expand All @@ -235,7 +249,7 @@ public function upload()
}
} else {
// Single-file upload
$varReturn = $this->uploadFile($varFile, $objTmpFolder->path);
$varReturn = $this->uploadFile($varFile, $tempUploadFolder->path);

if (isset($varReturn['uuid']) && Validator::isUuid($varReturn['uuid'])) {
$uuids[] = $varReturn['uuid'];
Expand Down
2 changes: 1 addition & 1 deletion src/HeimrichHannotContaoMultiFileUploadBundle.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/contao/config/config.php
Expand Up @@ -58,6 +58,6 @@

$GLOBALS['TL_CSS']['dropzone'] = 'bundles/heimrichhannotcontaomultifileupload/css/dropzone.min.css|screen|static';

$GLOBALS['TL_JAVASCRIPT']['dropzone'] = 'assets/dropzone-latest/dist/min/dropzone.min.js|static';
$GLOBALS['TL_JAVASCRIPT']['multifileupload'] = 'bundles/heimrichhannotcontaomultifileupload/js/multifileupload.min.js|static';
$GLOBALS['TL_JAVASCRIPT']['dropzone'] = 'assets/dropzone-latest/dist/dropzone.js|static';
$GLOBALS['TL_JAVASCRIPT']['multifileupload'] = 'bundles/heimrichhannotcontaomultifileupload/js/multifileupload.js|static';
}
22 changes: 22 additions & 0 deletions src/Response/DropzoneErrorResponse.php
@@ -0,0 +1,22 @@
<?php

/*
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/

namespace HeimrichHannot\MultiFileUploadBundle\Response;

use HeimrichHannot\AjaxBundle\Response\ResponseError;

class DropzoneErrorResponse extends ResponseError
{
public function getOutputData()
{
$outputData = parent::getOutputData();
$outputData->error = $outputData->message;

return $outputData;
}
}
2 changes: 1 addition & 1 deletion src/Widget/BackendMultiFileUpload.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Backend/MultiFileUploadTest.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/ContaoManager/PluginTest.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/MultiFileUploadExtensionTest.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/EventListener/HookListenerTest.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Form/FormMultiFileUploadTest.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/HeimrichHannotContaoMultiFileUploadBundleTest.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Widget/BackendMultiFileUploadTestOld.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/files/cmd_test.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/files/cmd_test1.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
* Copyright (c) 2019 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down

0 comments on commit b527605

Please sign in to comment.