Merge branch 'master' into PHRAS-3021_add-volumes-custom-cache

This commit is contained in:
Nicolas Maillat
2020-04-09 16:19:22 +02:00
committed by GitHub
10 changed files with 80 additions and 22 deletions

View File

@@ -111,7 +111,7 @@ main:
download: null
lazaret: null
caption: null
tmp_files: null
worker_tmp_files: null
border-manager:
enabled: true
extension-mapping:

View File

@@ -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 [

View File

@@ -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);

View File

@@ -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);

View File

@@ -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)

View File

@@ -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()

View File

@@ -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);
}
$config['main']['storage']['subdefs'] = $dataPath;
$storagePaths[$key] = realpath($path);
}
$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();

View File

@@ -111,7 +111,7 @@ main:
download: null
lazaret: null
caption: null
tmp_files: null
worker_tmp_files: null
trusted-proxies: []
debugger:

View File

@@ -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'];

View File

@@ -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());