diff --git a/config/configuration.sample.yml b/config/configuration.sample.yml index 9bbea0d4bc..a912e61876 100644 --- a/config/configuration.sample.yml +++ b/config/configuration.sample.yml @@ -111,7 +111,7 @@ main: download: null lazaret: null caption: null - tmp_files: null + worker_tmp_files: null border-manager: enabled: true extension-mapping: diff --git a/lib/Alchemy/Phrasea/Command/Setup/Install.php b/lib/Alchemy/Phrasea/Command/Setup/Install.php index 4682eda55a..4f83162584 100644 --- a/lib/Alchemy/Phrasea/Command/Setup/Install.php +++ b/lib/Alchemy/Phrasea/Command/Setup/Install.php @@ -55,6 +55,11 @@ class Install extends Command ->addOption('es-host', null, InputOption::VALUE_OPTIONAL, 'ElasticSearch server HTTP host', 'localhost') ->addOption('es-port', null, InputOption::VALUE_OPTIONAL, 'ElasticSearch server HTTP port', 9200) ->addOption('es-index', null, InputOption::VALUE_OPTIONAL, 'ElasticSearch index name', null) + ->addOption('download-path', null, InputOption::VALUE_OPTIONAL, 'Path to download repository', __DIR__ . '/../../../../../tmp/download') + ->addOption('lazaret-path', null, InputOption::VALUE_OPTIONAL, 'Path to lazaret repository', __DIR__ . '/../../../../../tmp/lazaret') + ->addOption('caption-path', null, InputOption::VALUE_OPTIONAL, 'Path to caption repository', __DIR__ . '/../../../../../tmp/caption') + ->addOption('scheduler-locks-path', null, InputOption::VALUE_OPTIONAL, 'Path to scheduler-locks repository', __DIR__ . '/../../../../../tmp/locks') + ->addOption('worker-tmp-files', null, InputOption::VALUE_OPTIONAL, 'Path to worker-tmp-files repository', __DIR__ . '/../../../../../tmp') ->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answer yes to all questions') ->setHelp("Phraseanet can only be installed on 64 bits PHP."); ; @@ -159,7 +164,9 @@ class Install extends Command } } - $this->container['phraseanet.installer']->install($email, $password, $abConn, $serverName, $dataPath, $dbConn, $templateName, $this->detectBinaries()); + $storagePaths = $this->getStoragePaths($input, $dataPath); + + $this->container['phraseanet.installer']->install($email, $password, $abConn, $serverName, $storagePaths, $dbConn, $templateName, $this->detectBinaries()); $this->container['conf']->set(['main', 'search-engine', 'options'], $esOptions->toArray()); if (null !== $this->getApplication()) { @@ -397,6 +404,27 @@ class Install extends Command return $index; } + private function getStoragePaths(InputInterface $input, $dataPath) + { + $schedulerLocksPath = $input->getOption('scheduler-locks-path'); + + if (!is_dir($schedulerLocksPath)) { + mkdir($schedulerLocksPath, 0755, true); + } + + if (($schedulerLocksPath = realpath($schedulerLocksPath)) === FALSE) { + throw new \InvalidArgumentException(sprintf('Path %s does not exist.', $schedulerLocksPath)); + } + + return [ + 'subdefs' => $dataPath, + 'download' => $input->getOption('download-path'), + 'lazaret' => $input->getOption('lazaret-path'), + 'caption' => $input->getOption('caption-path'), + 'worker_tmp_files' => $input->getOption('worker-tmp-files') + ]; + } + private function detectBinaries() { return [ diff --git a/lib/Alchemy/Phrasea/Controller/Prod/UploadController.php b/lib/Alchemy/Phrasea/Controller/Prod/UploadController.php index 27d18d5473..15cadafa52 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/UploadController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/UploadController.php @@ -181,8 +181,8 @@ class UploadController extends Controller $uploadedFilename = $file->getRealPath(); $renamedFilename = null; - if(!empty($this->app['conf']->get(['main', 'storage', 'tmp_files']))) { - $tmpStorage = \p4string::addEndSlash($this->app['conf']->get(['main', 'storage', 'tmp_files'])).'upload/'; + if(!empty($this->app['conf']->get(['main', 'storage', 'worker_tmp_files']))) { + $tmpStorage = \p4string::addEndSlash($this->app['conf']->get(['main', 'storage', 'worker_tmp_files'])).'upload/'; if(!is_dir($tmpStorage)){ $this->getFilesystem()->mkdir($tmpStorage); diff --git a/lib/Alchemy/Phrasea/Controller/SetupController.php b/lib/Alchemy/Phrasea/Controller/SetupController.php index 8e3b588326..af6cff5029 100644 --- a/lib/Alchemy/Phrasea/Controller/SetupController.php +++ b/lib/Alchemy/Phrasea/Controller/SetupController.php @@ -174,7 +174,9 @@ class SetupController extends Controller $email = $request->request->get('email'); $password = $request->request->get('password'); $template = $request->request->get('db_template'); - $dataPath = $request->request->get('datapath_noweb'); + $storagePath = [ + 'subdefs' => $request->request->get('datapath_noweb') + ]; try { $installer = $this->app['phraseanet.installer']; @@ -193,7 +195,7 @@ class SetupController extends Controller $binaryData[$key] = $path; } - $user = $installer->install($email, $password, $abConn, $servername, $dataPath, $dbConn, $template, $binaryData); + $user = $installer->install($email, $password, $abConn, $servername, $storagePath, $dbConn, $template, $binaryData); $this->app->getAuthenticator()->openAccount($user); diff --git a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php index 9612e3bc19..b6ebba31f3 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php +++ b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php @@ -57,7 +57,7 @@ class SubdefGenerator $this->filesystem = $filesystem; $this->logger = $logger; $this->mediavorus = $mediavorus; - $this->tmpDirectory = $this->app['conf']->get(['main', 'storage', 'tmp_files']);; + $this->tmpDirectory = $this->app['conf']->get(['main', 'storage', 'worker_tmp_files']);; } public function generateSubdefs(\record_adapter $record, array $wanted_subdefs = null) diff --git a/lib/Alchemy/Phrasea/Plugin/Management/ComposerInstaller.php b/lib/Alchemy/Phrasea/Plugin/Management/ComposerInstaller.php index 738e357fdc..17aba29f79 100644 --- a/lib/Alchemy/Phrasea/Plugin/Management/ComposerInstaller.php +++ b/lib/Alchemy/Phrasea/Plugin/Management/ComposerInstaller.php @@ -33,6 +33,11 @@ class ComposerInstaller $this->composer = $pluginsDirectory . DIRECTORY_SEPARATOR . 'composer.phar'; } + public function __destruct() + { + @unlink($this->composer); + } + public function install($directory) { $process = $this->createProcessBuilder() diff --git a/lib/Alchemy/Phrasea/Setup/Installer.php b/lib/Alchemy/Phrasea/Setup/Installer.php index 9c750d6cc7..74cb131e9b 100644 --- a/lib/Alchemy/Phrasea/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Setup/Installer.php @@ -30,11 +30,11 @@ class Installer $this->app = $app; } - public function install($email, $password, Connection $abConn, $serverName, $dataPath, Connection $dbConn = null, $templateName = null, array $binaryData = []) + public function install($email, $password, Connection $abConn, $serverName, array $storagePaths, Connection $dbConn = null, $templateName = null, array $binaryData = []) { $this->rollbackInstall($abConn, $dbConn); - $this->createConfigFile($abConn, $serverName, $binaryData, $dataPath); + $this->createConfigFile($abConn, $serverName, $binaryData, $storagePaths); try { $this->createAB($abConn); $user = $this->createUser($email, $password); @@ -185,7 +185,7 @@ class Installer $this->app->getApplicationBox()->insert_datas($this->app); } - private function createConfigFile(Connection $abConn, $serverName, $binaryData, $dataPath) + private function createConfigFile(Connection $abConn, $serverName, $binaryData, array $storagePaths) { $config = $this->app['configuration.store']->initialize()->getConfig(); @@ -203,17 +203,28 @@ class Installer $config['servername'] = $serverName; $config['main']['key'] = $this->app['random.medium']->generateString(16); - if (null === $dataPath = realpath($dataPath)) { - throw new \InvalidArgumentException(sprintf('Path %s does not exist.', $dataPath)); + // define storage config + $defaultStoragePaths = [ + 'subdefs' => __DIR__ . '/../../../../datas', + 'cache' => __DIR__ . '/../../../../cache', + 'log' => __DIR__ . '/../../../../logs', + 'download' => __DIR__ . '/../../../../tmp/download', + 'lazaret' => __DIR__ . '/../../../../tmp/lazaret', + 'caption' => __DIR__ . '/../../../../tmp/caption', + 'worker_tmp_files' => __DIR__ . '/../../../../tmp' + ]; + + $storagePaths = array_merge($defaultStoragePaths, $storagePaths); + + foreach ($storagePaths as $key => $path) { + if (!is_dir($path)) { + mkdir($path, 0755, true); + } + + $storagePaths[$key] = realpath($path); } - $config['main']['storage']['subdefs'] = $dataPath; - - $config['main']['storage']['cache'] = realpath(__DIR__ . '/../../../../cache'); - $config['main']['storage']['log'] = realpath(__DIR__ . '/../../../../logs'); - $config['main']['storage']['download'] = realpath(__DIR__ . '/../../../../tmp/download'); - $config['main']['storage']['lazaret'] = realpath(__DIR__ . '/../../../../tmp/lazaret'); - $config['main']['storage']['caption'] = realpath(__DIR__ . '/../../../../tmp/caption'); + $config['main']['storage'] = $storagePaths; $config['registry'] = $this->app['registry.manipulator']->getRegistryData(); diff --git a/lib/conf.d/configuration.yml b/lib/conf.d/configuration.yml index fb4805c7a9..8a7a62052d 100644 --- a/lib/conf.d/configuration.yml +++ b/lib/conf.d/configuration.yml @@ -111,7 +111,7 @@ main: download: null lazaret: null caption: null - tmp_files: null + worker_tmp_files: null trusted-proxies: [] debugger: diff --git a/tests/Alchemy/Tests/Phrasea/Command/Setup/InstallTest.php b/tests/Alchemy/Tests/Phrasea/Command/Setup/InstallTest.php index f8e0a8b5a1..e1b20fe3fb 100644 --- a/tests/Alchemy/Tests/Phrasea/Command/Setup/InstallTest.php +++ b/tests/Alchemy/Tests/Phrasea/Command/Setup/InstallTest.php @@ -36,6 +36,13 @@ class InstallTest extends \PhraseanetTestCase $password = 'sup4ssw0rd'; $serverName = 'http://phrasea.io'; $dataPath = '/tmp'; + $storagePaths = [ + 'subdefs' => $dataPath, + 'download' => $dataPath, + 'lazaret' => $dataPath, + 'caption' => $dataPath, + 'worker_tmp_files' => $dataPath + ]; $template = 'fr-simple'; $infoDb = Yaml::parse(file_get_contents(__DIR__ . '/../../../../../../resources/hudson/InstallDBs.yml')); @@ -72,6 +79,11 @@ class InstallTest extends \PhraseanetTestCase case 'password': return $password; break; + case 'download-path': + case 'lazaret-path': + case 'caption-path': + case 'scheduler-locks-path': + case 'worker-tmp-files': case 'data-path': return $dataPath; break; @@ -110,7 +122,7 @@ class InstallTest extends \PhraseanetTestCase self::$DI['cli']['phraseanet.installer']->expects($this->once()) ->method('install') - ->with($email, $password, $this->isInstanceOf('Doctrine\DBAL\Driver\Connection'), $serverName, $dataPath, $this->isInstanceOf('Doctrine\DBAL\Driver\Connection'), $template, $this->anything()); + ->with($email, $password, $this->isInstanceOf('Doctrine\DBAL\Driver\Connection'), $serverName, $storagePaths, $this->isInstanceOf('Doctrine\DBAL\Driver\Connection'), $template, $this->anything()); $structureTemplate = self::$DI['cli']['phraseanet.structure-template']; diff --git a/tests/Alchemy/Tests/Phrasea/Setup/InstallerTest.php b/tests/Alchemy/Tests/Phrasea/Setup/InstallerTest.php index c3a364c869..ea6d4890cc 100644 --- a/tests/Alchemy/Tests/Phrasea/Setup/InstallerTest.php +++ b/tests/Alchemy/Tests/Phrasea/Setup/InstallerTest.php @@ -75,7 +75,7 @@ class InstallerTest extends \PhraseanetTestCase $dataPath = __DIR__ . '/../../../../../datas/'; $installer = new Installer($app); - $installer->install(uniqid('admin') . '@example.com', 'sdfsdsd', $abConn, 'http://local.phrasea.test.installer/', $dataPath, $dbConn, 'en-simple'); + $installer->install(uniqid('admin') . '@example.com', 'sdfsdsd', $abConn, 'http://local.phrasea.test.installer/', ['subdefs' => $dataPath], $dbConn, 'en-simple'); $this->assertTrue($app['configuration.store']->isSetup()); $this->assertTrue($app['phraseanet.configuration-tester']->isUpToDate());