diff --git a/composer.json b/composer.json index 6e12f90c7e..9f556aab08 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "neutron/silex-filesystem-provider": "~1.0", "neutron/sphinxsearch-api" : "~2.0.6", "neutron/recaptcha" : "~0.1.0", - "neutron/temporary-filesystem" : "~2.0", + "neutron/temporary-filesystem" : "~2.1", "php-xpdf/php-xpdf" : "~0.2.1", "phpexiftool/phpexiftool" : "~0.2, >=0.2.2", "silex/silex" : "~1.0.0", diff --git a/lib/Alchemy/Phrasea/Command/RecordAdd.php b/lib/Alchemy/Phrasea/Command/RecordAdd.php index c3c0ef36c6..ba5184266b 100644 --- a/lib/Alchemy/Phrasea/Command/RecordAdd.php +++ b/lib/Alchemy/Phrasea/Command/RecordAdd.php @@ -81,7 +81,7 @@ class RecordAdd extends Command if ($input->getOption('in-place') !== '1') { $originalName = pathinfo($file, PATHINFO_BASENAME); - $tempfile = tempnam(sys_get_temp_dir(), 'addrecord') . '.' . pathinfo($file, PATHINFO_EXTENSION); + $tempfile = $this->container['temporary-filesystem']->createTemporaryFile('add_record', null, pathinfo($file, PATHINFO_EXTENSION)); $this->container['monolog']->addInfo(sprintf('copy file from `%s` to temporary `%s`', $file, $tempfile)); $this->container['filesystem']->copy($file, $tempfile, true); $file = $tempfile; @@ -97,6 +97,7 @@ class RecordAdd extends Command if ($input->getOption('force')) { switch ($input->getOption('force')) { default: + $this->container['temporary-filesystem']->clean('add_record'); throw new \InvalidArgumentException(sprintf('`%s` is not a valid force option', $input->getOption('force'))); break; case 'record': @@ -130,7 +131,7 @@ class RecordAdd extends Command if ($tempfile) { $this->container['monolog']->addInfo(sprintf('Remove temporary file `%s`', $tempfile)); - $this->container['filesystem']->remove($tempfile); + $this->container['temporary-filesystem']->clean('add_record'); } return; diff --git a/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php b/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php index e5c74875e7..e393cf481d 100644 --- a/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php +++ b/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php @@ -231,6 +231,7 @@ class Configuration implements ConfigurationInterface } } + unlink($tmpFile); throw new RuntimeException(sprintf('Unable to write %s', $file)); } diff --git a/lib/Alchemy/Phrasea/Core/Provider/TemporaryFilesystemServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/TemporaryFilesystemServiceProvider.php index 33ebf9d38a..73e933b32b 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/TemporaryFilesystemServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/TemporaryFilesystemServiceProvider.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\Core\Provider; use Neutron\TemporaryFilesystem\TemporaryFilesystem; +use Neutron\TemporaryFilesystem\Manager; use Silex\Application; use Silex\ServiceProviderInterface; @@ -19,9 +20,12 @@ class TemporaryFilesystemServiceProvider implements ServiceProviderInterface { public function register(Application $app) { - $app['temporary-filesystem'] = $app->share(function (Application $app) { + $app['temporary-filesystem.temporary-fs'] = $app->share(function (Application $app) { return new TemporaryFilesystem($app['filesystem']); }); + $app['temporary-filesystem'] = $app->share(function (Application $app) { + return new Manager($app['temporary-filesystem.temporary-fs'], $app['filesystem']); + }); } public function boot(Application $app) diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/TemporaryFilesystemServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/TemporaryFilesystemServiceProviderTest.php index 89b39e1c47..b3535f5682 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/TemporaryFilesystemServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/TemporaryFilesystemServiceProviderTest.php @@ -10,7 +10,7 @@ class TemporaryFilesystemServiceProvidertest extends ServiceProviderTestCase public function provideServiceDescription() { return array( - array('Alchemy\Phrasea\Core\Provider\TemporaryFilesystemServiceProvider', 'temporary-filesystem', 'Neutron\TemporaryFilesystem\TemporaryFilesystem'), + array('Alchemy\Phrasea\Core\Provider\TemporaryFilesystemServiceProvider', 'temporary-filesystem', 'Neutron\TemporaryFilesystem\TemporaryFilesystemInterface'), ); } }