From 51b9a7f89adcd0f4018dc6399e24fd49f12ab53d Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 26 Feb 2014 18:46:10 +0100 Subject: [PATCH 1/2] Improve Xsendfile tools, allow dump whenever the conf is disabled --- .../Setup/XSendFileConfigurationDumper.php | 17 ++++++++--------- .../Command/Setup/XSendFileMappingGenerator.php | 4 +++- .../Phrasea/Http/XSendFile/XSendFileFactory.php | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/Setup/XSendFileConfigurationDumper.php b/lib/Alchemy/Phrasea/Command/Setup/XSendFileConfigurationDumper.php index f761945e73..ec20cfe039 100644 --- a/lib/Alchemy/Phrasea/Command/Setup/XSendFileConfigurationDumper.php +++ b/lib/Alchemy/Phrasea/Command/Setup/XSendFileConfigurationDumper.php @@ -33,27 +33,26 @@ class XSendFileConfigurationDumper extends Command $output->writeln(''); if (!$this->container['phraseanet.xsendfile-factory']->isXSendFileModeEnabled()) { - $output->writeln('XSendFile support is disabled'); - - return 1; + $output->writeln('XSendFile support is disabled, enable it to use this feature.'); + $ret = 1; + } else { + $output->writeln('XSendFile support is enabled'); + $ret = 0; } - $output->writeln('XSendFile support is enabled'); - try { - $configuration = $this->container['phraseanet.xsendfile-factory']->getMode(true)->getVirtualHostConfiguration(); + $configuration = $this->container['phraseanet.xsendfile-factory']->getMode(true, true)->getVirtualHostConfiguration(); $output->writeln('XSendFile configuration seems OK'); $output->writeln($configuration); - return 0; } catch (RuntimeException $e) { $output->writeln('XSendFile configuration seems invalid'); - return 1; + $ret = 1; } $output->writeln(''); - return 0; + return $ret; } } diff --git a/lib/Alchemy/Phrasea/Command/Setup/XSendFileMappingGenerator.php b/lib/Alchemy/Phrasea/Command/Setup/XSendFileMappingGenerator.php index 9610a42491..24829ab774 100644 --- a/lib/Alchemy/Phrasea/Command/Setup/XSendFileMappingGenerator.php +++ b/lib/Alchemy/Phrasea/Command/Setup/XSendFileMappingGenerator.php @@ -56,13 +56,15 @@ class XSendFileMappingGenerator extends Command $this->container['phraseanet.configuration']['xsendfile'] = $conf; $output->writeln(" OK"); $output->writeln(""); - $output->write("It is now strongly recommended to use xsendfile:dump-configuration command to upgrade your virtual-host"); + $output->writeln("It is now strongly recommended to use xsendfile:dump-configuration command to upgrade your virtual-host"); } else { $output->writeln("Configuration will not be written, use --write option to write it"); $output->writeln(""); $output->writeln(Yaml::dump(array('xsendfile' => $conf), 4)); } + $output->writeln(""); + return 0; } diff --git a/lib/Alchemy/Phrasea/Http/XSendFile/XSendFileFactory.php b/lib/Alchemy/Phrasea/Http/XSendFile/XSendFileFactory.php index 17401f17eb..abb19975e1 100644 --- a/lib/Alchemy/Phrasea/Http/XSendFile/XSendFileFactory.php +++ b/lib/Alchemy/Phrasea/Http/XSendFile/XSendFileFactory.php @@ -66,9 +66,9 @@ class XSendFileFactory * * @throws InvalidArgumentException if mode type is unknown */ - public function getMode($throwException = false) + public function getMode($throwException = false, $forceMode = false) { - if (false === $this->enabled) { + if (false === $this->enabled && true !== $forceMode) { return new NullMode(); } From 5856992262a36ceb6d3d85e3c5b9824cbc5695e0 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 27 Feb 2014 15:53:44 +0100 Subject: [PATCH 2/2] Remove disk IO on media_subdef::get_size --- lib/classes/media/subdef.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/classes/media/subdef.php b/lib/classes/media/subdef.php index 0849875302..10b8f4e07a 100644 --- a/lib/classes/media/subdef.php +++ b/lib/classes/media/subdef.php @@ -101,6 +101,9 @@ class media_subdef extends media_abstract implements cache_cacheableInterface */ protected $is_physically_present = false; + /** @var integer */ + private $size = 0; + /** * Players types constants */ @@ -168,6 +171,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface $this->mime = $datas['mime']; $this->width = $datas['width']; $this->height = $datas['height']; + $this->size = $datas['size']; $this->etag = $datas['etag']; $this->path = $datas['path']; $this->url = $datas['url']; @@ -203,6 +207,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface if ($row) { $this->width = (int) $row['width']; + $this->size = (int) $row['size']; $this->height = (int) $row['height']; $this->mime = $row['mime']; $this->file = $row['file']; @@ -228,6 +233,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface $datas = array( 'mime' => $this->mime , 'width' => $this->width + , 'size' => $this->size , 'height' => $this->height , 'etag' => $this->etag , 'path' => $this->path @@ -447,7 +453,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface */ public function get_size() { - return (int) @filesize($this->get_pathfile()); + return $this->size; } /**