mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
fix #777 preview in quarantine
This commit is contained in:
@@ -23,6 +23,7 @@ use Monolog\Logger;
|
|||||||
use PHPExiftool\Driver\Metadata\Metadata;
|
use PHPExiftool\Driver\Metadata\Metadata;
|
||||||
use PHPExiftool\Driver\Value\Mono as MonoValue;
|
use PHPExiftool\Driver\Value\Mono as MonoValue;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
use Symfony\Component\Filesystem\Exception\IOException;
|
||||||
use XPDF\PdfToText;
|
use XPDF\PdfToText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -204,22 +205,25 @@ class Manager
|
|||||||
* @param string $filename The desired filename
|
* @param string $filename The desired filename
|
||||||
* @return string The available filename to use
|
* @return string The available filename to use
|
||||||
*/
|
*/
|
||||||
protected function bookLazaretPathfile($filename)
|
protected function bookLazaretPathfile($filename, $suffix = '')
|
||||||
{
|
{
|
||||||
$root = __DIR__ . '/../../../../tmp/lazaret/';
|
$output = __DIR__ . '/../../../../tmp/lazaret/lzrt_' . substr($filename, 0, 3) . '_' . $suffix . '.' .pathinfo($filename, PATHINFO_EXTENSION);
|
||||||
|
$infos = pathinfo($output);
|
||||||
|
$n = 0;
|
||||||
|
while (true) {
|
||||||
|
$output = sprintf('%s/%s-%d%s', $infos['dirname'], $infos['filename'], ++ $n, (isset($infos['extension']) ? '.' . $infos['extension'] : ''));
|
||||||
|
|
||||||
$infos = pathinfo($filename);
|
try {
|
||||||
|
if ( ! $this->filesystem->exists($output)) {
|
||||||
|
$this->filesystem->touch($output);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (IOException $e) {
|
||||||
|
|
||||||
$output = $root . $infos['basename'];
|
}
|
||||||
|
|
||||||
$n = 1;
|
|
||||||
while (file_exists($output) || ! touch($output)) {
|
|
||||||
$output = $root . $infos['filename'] . '-' . ++ $n . '.' . $infos['extension'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->filesystem->touch($output);
|
return realpath($output);
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -410,7 +414,8 @@ class Manager
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$lazaretPathname = $this->bookLazaretPathfile($file->getFile()->getRealPath());
|
$lazaretPathname = $this->bookLazaretPathfile($file->getOriginalName());
|
||||||
|
$lazaretPathnameThumb = $this->bookLazaretPathfile($file->getOriginalName(), 'thumb');
|
||||||
|
|
||||||
$this->filesystem->copy($file->getFile()->getRealPath(), $lazaretPathname, true);
|
$this->filesystem->copy($file->getFile()->getRealPath(), $lazaretPathname, true);
|
||||||
|
|
||||||
@@ -424,7 +429,7 @@ class Manager
|
|||||||
try {
|
try {
|
||||||
$core['media-alchemyst']
|
$core['media-alchemyst']
|
||||||
->open($file->getFile()->getPathname())
|
->open($file->getFile()->getPathname())
|
||||||
->turnInto($lazaretPathname, $spec)
|
->turnInto($lazaretPathnameThumb, $spec)
|
||||||
->close();
|
->close();
|
||||||
} catch (MediaAlchemystException $e) {
|
} catch (MediaAlchemystException $e) {
|
||||||
|
|
||||||
@@ -438,7 +443,9 @@ class Manager
|
|||||||
|
|
||||||
$lazaretFile->setForced($forced);
|
$lazaretFile->setForced($forced);
|
||||||
|
|
||||||
$lazaretFile->setPathname($lazaretPathname);
|
$lazaretFile->setPathname(pathinfo($lazaretPathname, PATHINFO_BASENAME));
|
||||||
|
$lazaretFile->setThumbPathName(pathinfo($lazaretPathnameThumb, PATHINFO_BASENAME));
|
||||||
|
|
||||||
$lazaretFile->setSession($session);
|
$lazaretFile->setSession($session);
|
||||||
|
|
||||||
$this->em->persist($lazaretFile);
|
$this->em->persist($lazaretFile);
|
||||||
|
@@ -18,6 +18,7 @@ use Silex\ControllerProviderInterface;
|
|||||||
use Silex\ControllerCollection;
|
use Silex\ControllerCollection;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Filesystem\Exception\IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lazaret controller collection
|
* Lazaret controller collection
|
||||||
@@ -189,12 +190,13 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
{
|
{
|
||||||
$ret = array('success' => false, 'message' => '', 'result' => array());
|
$ret = array('success' => false, 'message' => '', 'result' => array());
|
||||||
|
|
||||||
try {
|
|
||||||
$lazaretFile = $app['Core']['EM']->find('Entities\LazaretFile', $file_id);
|
$lazaretFile = $app['Core']['EM']->find('Entities\LazaretFile', $file_id);
|
||||||
|
|
||||||
/* @var $lazaretFile \Entities\LazaretFile */
|
/* @var $lazaretFile \Entities\LazaretFile */
|
||||||
if (null === $lazaretFile) {
|
if (null === $lazaretFile) {
|
||||||
throw new \Exception_NotFound(sprintf('Lazaret file id %d not found', $file_id));
|
$ret['message'] = _('File is not present in quarantine anymore, please refresh');
|
||||||
|
|
||||||
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = array(
|
$file = array(
|
||||||
@@ -209,11 +211,6 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
|
|
||||||
$ret['result'] = $file;
|
$ret['result'] = $file;
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
} catch (\Exception_NotFound $e) {
|
|
||||||
$ret['message'] = _('File is not present in quarantine anymore, please refresh');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$ret['message'] = _('An error occured');
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::formatJson($app['Core']['Serializer'], $ret);
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
@@ -242,14 +239,17 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
return self::formatJson($app['Core']['Serializer'], $ret);
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
$lazaretFile = $app['Core']['EM']->find('Entities\LazaretFile', $file_id);
|
$lazaretFile = $app['Core']['EM']->find('Entities\LazaretFile', $file_id);
|
||||||
|
|
||||||
/* @var $lazaretFile \Entities\LazaretFile */
|
/* @var $lazaretFile \Entities\LazaretFile */
|
||||||
if (null === $lazaretFile) {
|
if (null === $lazaretFile) {
|
||||||
throw new \Exception_NotFound(sprintf('Lazaret file id %d not found', $file_id));
|
$ret['message'] = _('File is not present in quarantine anymore, please refresh');
|
||||||
|
|
||||||
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$borderFile = Border\File::buildFromPathfile(
|
$borderFile = Border\File::buildFromPathfile(
|
||||||
$lazaretFile->getPathname(), $lazaretFile->getCollection(), $lazaretFile->getOriginalName()
|
$lazaretFile->getPathname(), $lazaretFile->getCollection(), $lazaretFile->getOriginalName()
|
||||||
);
|
);
|
||||||
@@ -311,15 +311,18 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
$app['Core']['EM']->remove($lazaretFile);
|
$app['Core']['EM']->remove($lazaretFile);
|
||||||
$app['Core']['EM']->flush();
|
$app['Core']['EM']->flush();
|
||||||
|
|
||||||
$app['Core']['file-system']->remove($lazaretFile->getPathname());
|
|
||||||
|
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
} catch (\Exception_NotFound $e) {
|
|
||||||
$ret['message'] = _('File is not present in quarantine anymore, please refresh');
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$ret['message'] = _('An error occured');
|
$ret['message'] = _('An error occured');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$app['Core']['file-system']->remove($lazaretFile->getPathname());
|
||||||
|
$app['Core']['file-system']->remove($lazaretFile->getThumbPathname());
|
||||||
|
} catch (IOException $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return self::formatJson($app['Core']['Serializer'], $ret);
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,27 +339,32 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
{
|
{
|
||||||
$ret = array('success' => false, 'message' => '', 'result' => array());
|
$ret = array('success' => false, 'message' => '', 'result' => array());
|
||||||
|
|
||||||
try {
|
|
||||||
$lazaretFile = $app['Core']['EM']->find('Entities\LazaretFile', $file_id);
|
$lazaretFile = $app['Core']['EM']->find('Entities\LazaretFile', $file_id);
|
||||||
|
|
||||||
/* @var $lazaretFile \Entities\LazaretFile */
|
/* @var $lazaretFile \Entities\LazaretFile */
|
||||||
if (null === $lazaretFile) {
|
if (null === $lazaretFile) {
|
||||||
throw new \Exception_NotFound(sprintf('Lazaret file id %d not found', $file_id));
|
$ret['message'] = _('File is not present in quarantine anymore, please refresh');
|
||||||
|
|
||||||
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete lazaret file
|
try {
|
||||||
$app['Core']['EM']->remove($lazaretFile);
|
$app['Core']['EM']->remove($lazaretFile);
|
||||||
$app['Core']['EM']->flush();
|
$app['Core']['EM']->flush();
|
||||||
|
|
||||||
$app['Core']['file-system']->remove($lazaretFile->getPathname());
|
|
||||||
|
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
} catch (\Exception_NotFound $e) {
|
|
||||||
$ret['message'] = _('File is not present in quarantine anymore, please refresh');
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$ret['message'] = _('An error occured');
|
$ret['message'] = _('An error occured');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$app['Core']['file-system']->remove($lazaretFile->getPathname());
|
||||||
|
$app['Core']['file-system']->remove($lazaretFile->getThumbPathname());
|
||||||
|
} catch (IOException $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return self::formatJson($app['Core']['Serializer'], $ret);
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,12 +388,13 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
return self::formatJson($app['Core']['Serializer'], $ret);
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
$lazaretFile = $app['Core']['EM']->find('Entities\LazaretFile', $file_id);
|
$lazaretFile = $app['Core']['EM']->find('Entities\LazaretFile', $file_id);
|
||||||
|
|
||||||
/* @var $lazaretFile \Entities\LazaretFile */
|
/* @var $lazaretFile \Entities\LazaretFile */
|
||||||
if (null === $lazaretFile) {
|
if (null === $lazaretFile) {
|
||||||
throw new \Exception_NotFound(sprintf('Lazaret file id %d not found', $file_id));
|
$ret['message'] = _('File is not present in quarantine anymore, please refresh');
|
||||||
|
|
||||||
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
$found = false;
|
$found = false;
|
||||||
@@ -406,6 +415,7 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
return self::formatJson($app['Core']['Serializer'], $ret);
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$media = $app['Core']['mediavorus']->guess(new \SplFileInfo($lazaretFile->getPathname()));
|
$media = $app['Core']['mediavorus']->guess(new \SplFileInfo($lazaretFile->getPathname()));
|
||||||
|
|
||||||
$record = $lazaretFile->getCollection()->get_databox()->get_record($recordId);
|
$record = $lazaretFile->getCollection()->get_databox()->get_record($recordId);
|
||||||
@@ -415,15 +425,18 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
$app['Core']['EM']->remove($lazaretFile);
|
$app['Core']['EM']->remove($lazaretFile);
|
||||||
$app['Core']['EM']->flush();
|
$app['Core']['EM']->flush();
|
||||||
|
|
||||||
$app['Core']['file-system']->remove($lazaretFile->getPathname());
|
|
||||||
|
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
} catch (\Exception_NotFound $e) {
|
|
||||||
$ret['message'] = _('File is not present in quarantine anymore, please refresh');
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$ret['message'] = _('An error occured');
|
$ret['message'] = _('An error occured');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$app['Core']['file-system']->remove($lazaretFile->getPathname());
|
||||||
|
$app['Core']['file-system']->remove($lazaretFile->getThumbPathname());
|
||||||
|
} catch (IOException $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return self::formatJson($app['Core']['Serializer'], $ret);
|
return self::formatJson($app['Core']['Serializer'], $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,11 +455,14 @@ class Lazaret implements ControllerProviderInterface
|
|||||||
|
|
||||||
/* @var $lazaretFile \Entities\LazaretFile */
|
/* @var $lazaretFile \Entities\LazaretFile */
|
||||||
if (null === $lazaretFile) {
|
if (null === $lazaretFile) {
|
||||||
|
|
||||||
return new Response(null, 404);
|
return new Response(null, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$lazaretPath = __DIR__ . '/../../../../../tmp/lazaret/';
|
||||||
|
|
||||||
$response = \set_export::stream_file(
|
$response = \set_export::stream_file(
|
||||||
$lazaretFile->getPathname(), $lazaretFile->getOriginalName(), 'image/jpeg', 'inline'
|
$lazaretPath . $lazaretFile->getThumbPathname(), $lazaretFile->getOriginalName(), 'image/jpeg', 'inline'
|
||||||
);
|
);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
@@ -176,8 +176,9 @@ class Upload implements ControllerProviderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Add file extension, so mediavorus can guess file type for octet-stream file
|
||||||
$uploadedFilename = $file->getRealPath();
|
$uploadedFilename = $file->getRealPath();
|
||||||
$renamedFilename = $file->getRealPath() . $file->getClientOriginalName();
|
$renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
|
||||||
|
|
||||||
$originalname = $file->getClientOriginalName();
|
$originalname = $file->getClientOriginalName();
|
||||||
$clientMimeType = $file->getClientMimeType();
|
$clientMimeType = $file->getClientMimeType();
|
||||||
|
@@ -17,6 +17,11 @@ class LazaretFile
|
|||||||
*/
|
*/
|
||||||
private $pathname;
|
private $pathname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string $thumbPathname
|
||||||
|
*/
|
||||||
|
private $thumbPathname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var integer $base_id
|
* @var integer $base_id
|
||||||
*/
|
*/
|
||||||
@@ -365,11 +370,23 @@ class LazaretFile
|
|||||||
$merged = array_merge($uuidRecords, $shaRecords);
|
$merged = array_merge($uuidRecords, $shaRecords);
|
||||||
|
|
||||||
foreach ($merged as $record) {
|
foreach ($merged as $record) {
|
||||||
if (!in_array($record, $ret)) {
|
if ( ! in_array($record, $ret)) {
|
||||||
$ret[] = $record;
|
$ret[] = $record;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThumbPathname()
|
||||||
|
{
|
||||||
|
return $this->thumbPathname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setThumbPathname($thumbPathname)
|
||||||
|
{
|
||||||
|
$this->thumbPathname = $thumbPathname;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,9 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use MediaAlchemyst\Exception\Exception as MediaAlchemystException;
|
||||||
|
use MediaAlchemyst\Specification\Image as ImageSpec;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||||
@@ -84,6 +87,24 @@ class patch_370a7 implements patchInterface
|
|||||||
$filePath = __DIR__ . '/../../../tmp/lazaret/' . $row['filepath'];
|
$filePath = __DIR__ . '/../../../tmp/lazaret/' . $row['filepath'];
|
||||||
|
|
||||||
if (file_exists($filePath)) {
|
if (file_exists($filePath)) {
|
||||||
|
|
||||||
|
$spec = new ImageSpec();
|
||||||
|
|
||||||
|
$spec->setResizeMode(ImageSpec::RESIZE_MODE_INBOUND_FIXEDRATIO);
|
||||||
|
$spec->setDimensions(375, 275);
|
||||||
|
|
||||||
|
$thumbPass = sprintf("thumb_%s", $filePath);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$Core['media-alchemyst']
|
||||||
|
->open($filePath)
|
||||||
|
->turnInto($thumbPass, $spec)
|
||||||
|
->close();
|
||||||
|
} catch (MediaAlchemystException $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$media = $Core['mediavorus']->guess(new \SplFileInfo($filePath));
|
$media = $Core['mediavorus']->guess(new \SplFileInfo($filePath));
|
||||||
|
|
||||||
$collection = \collection::get_from_base_id($row['base_id']);
|
$collection = \collection::get_from_base_id($row['base_id']);
|
||||||
@@ -111,7 +132,8 @@ class patch_370a7 implements patchInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$lazaretFile->setOriginalName($row['filename']);
|
$lazaretFile->setOriginalName($row['filename']);
|
||||||
$lazaretFile->setPathname(__DIR__ . '/../../../tmp/lazaret/' . $row['filepath']);
|
$lazaretFile->setPathname($row['filepath']);
|
||||||
|
$lazaretFile->setThumbPathname($thumbPass);
|
||||||
$lazaretFile->setCreated(new \DateTime($row['created_on']));
|
$lazaretFile->setCreated(new \DateTime($row['created_on']));
|
||||||
$lazaretFile->setSession($lazaretSession);
|
$lazaretFile->setSession($lazaretSession);
|
||||||
|
|
||||||
|
@@ -11,6 +11,9 @@ Entities\LazaretFile:
|
|||||||
pathname:
|
pathname:
|
||||||
type: string
|
type: string
|
||||||
length: 512
|
length: 512
|
||||||
|
thumbPathname:
|
||||||
|
type: string
|
||||||
|
length: 512
|
||||||
originalName:
|
originalName:
|
||||||
type: string
|
type: string
|
||||||
length: 256
|
length: 256
|
||||||
|
Reference in New Issue
Block a user