fix config storage

This commit is contained in:
aynsix
2020-04-08 17:29:28 +03:00
parent 67381fa198
commit 7accf0f995
4 changed files with 39 additions and 43 deletions

View File

@@ -164,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());
$this->defineStorageTmpPath($input);
@@ -403,33 +405,8 @@ class Install extends Command
return $index;
}
private function defineStorageTmpPath(InputInterface $input)
private function getStoragePaths(InputInterface $input, $dataPath)
{
$downloadPath = $input->getOption('download-path');
if (!is_dir($downloadPath)) {
mkdir($downloadPath, 0755, true);
}
$lazaretPath = $input->getOption('lazaret-path');
if (!is_dir($lazaretPath)) {
mkdir($lazaretPath, 0755, true);
}
$captionPath = $input->getOption('caption-path');
if (!is_dir($captionPath)) {
mkdir($captionPath, 0755, true);
}
$workerTmpFiles = $input->getOption('worker-tmp-files');
if (!is_dir($workerTmpFiles)) {
mkdir($workerTmpFiles, 0755, true);
}
$schedulerLocksPath = $input->getOption('scheduler-locks-path');
if (!is_dir($schedulerLocksPath)) {
@@ -440,10 +417,13 @@ class Install extends Command
throw new \InvalidArgumentException(sprintf('Path %s does not exist.', $schedulerLocksPath));
}
$this->container['conf']->set(['main', 'storage', 'download'], realpath($downloadPath));
$this->container['conf']->set(['main', 'storage', 'lazaret'], realpath($lazaretPath));
$this->container['conf']->set(['main', 'storage', 'caption'], realpath($captionPath));
$this->container['conf']->set(['main', 'storage', 'worker_tmp_files'], realpath($workerTmpFiles));
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()

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

@@ -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,14 +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/worker_tmp_files'
];
$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'] = $storagePaths;
$config['registry'] = $this->app['registry.manipulator']->getRegistryData();

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