Merge pull request #2373 from falylala/PHRAS-1717-PORT_Install_show_available_documentary

PHRAS-1717- PORT_1296_Show all available structure for install CLI/Graphic mode
This commit is contained in:
Nicolas Maillat
2018-01-08 12:33:19 +01:00
committed by GitHub
7 changed files with 107 additions and 6 deletions

0
cache/.gitkeep vendored
View File

View File

@@ -176,6 +176,7 @@ class Install extends Command
private function getDBConn(InputInterface $input, OutputInterface $output, Connection $abConn, DialogHelper $dialog)
{
$dbConn = $template = $info = null;
$templates = $this->container['phraseanet.structure-template']->getAvailable();
if (!$input->getOption('databox')) {
do {
$retry = false;
@@ -196,8 +197,9 @@ class Install extends Command
$output->writeln("\n\t<info>Data-Box : Connection successful !</info>\n");
do {
$template = $dialog->ask($output, 'Choose a language template for metadata structure, available are fr (french) and en (english) (en) : ', 'en');
} while (!in_array($template, ['en', 'fr']));
$template = $dialog->ask($output, "Choose a language template for metadata structure, available are {$templates->__toString()} : ", 'en');
}
while (!in_array($template, array_keys($templates->getTemplates())));
$output->writeln("\n\tLanguage selected is <info>'$template'</info>\n");
} catch (\Exception $e) {

View File

@@ -77,7 +77,7 @@ class SetupController extends Controller
return $this->render('/setup/step2.html.twig', [
'locale' => $this->app['locale'],
'available_locales' => Application::getAvailableLanguages(),
'available_templates' => ['en', 'fr'],
'available_templates' => $this->app['phraseanet.structure-template']->getAvailable()->getTemplates(),
'warnings' => $warnings,
'error' => $request->query->get('error'),
'current_servername' => $request->getScheme() . '://' . $request->getHttpHost() . '/',

View File

@@ -0,0 +1,93 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Configuration;
use Alchemy\Phrasea\Application;
/**
* Class StructureTemplate
* @package Alchemy\Phrasea\Core\Configuration
*/
class StructureTemplate
{
const TEMPLATE_EXTENSION = 'xml';
private $templates;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* @return $this
* @throws \Exception
*/
public function getAvailable()
{
$templateList = new \DirectoryIterator($this->app['root.path'] . '/lib/conf.d/data_templates');
if(empty($templateList)) throw new \Exception('No available structure template');
$templates = [];
$abbreviationLength = 2;
foreach ($templateList as $template)
{
if($template->isDot()
|| !$template->isFile()
|| $template->getExtension() !== self::TEMPLATE_EXTENSION) continue;
$name = $template->getFilename();
$abbreviation = strtolower(substr($name,0,$abbreviationLength));
if(array_key_exists($abbreviation,$templates) ){
$abbreviation = strtolower(substr($name,0,++$abbreviationLength));
}
$templates[$abbreviation] = $template->getBasename('.'.self::TEMPLATE_EXTENSION);
}
$this->templates = $templates;
return $this;
}
/**
* @return string
*/
public function __toString()
{
if(!$this->templates){
return '';
}
$templateToString = '';
$cpt = 1;
$templateLength = count($this->templates);
foreach ($this->templates as $key => $value){
if (($templateLength - 1) == $cpt) {
$separator = ' and ';
}elseif(end($this->templates) == $value){
$separator = '';
}else{
$separator = ', ';
}
$templateToString .= $key.' ('.$value.')'. $separator;
$cpt++;
}
return $templateToString;
}
/**
* @param $template
* @return mixed
* @throws \Exception
*/
public function getTemplateName($template = 'en'){
if(!array_key_exists($template,$this->templates)){
throw new \Exception('Not found template : '.$template);
}
return $this->templates[$template];
}
/**
* @return mixed
*/
public function getTemplates()
{
return $this->templates;
}
}

View File

@@ -11,6 +11,8 @@
namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Configuration\StructureTemplate;
use Alchemy\Phrasea\Core\Configuration\AccessRestriction;
use Alchemy\Phrasea\Core\Configuration\Configuration;
use Alchemy\Phrasea\Core\Configuration\DisplaySettingService;
@@ -71,6 +73,10 @@ class ConfigurationServiceProvider implements ServiceProviderInterface
$app['conf.restrictions'] = $app->share(function (SilexApplication $app) {
return new AccessRestriction($app['conf'], $app->getApplicationBox(), $app['monolog']);
});
$app['phraseanet.structure-template'] = $app->share(function (Application $app) {
return new StructureTemplate($app);
});
}
/**

View File

@@ -53,7 +53,7 @@ class Installer
private function createDB(Connection $dbConn = null, $template, User $admin)
{
$template = new \SplFileInfo(__DIR__ . '/../../../conf.d/data_templates/' . $template . '-simple.xml');
$template = new \SplFileInfo(__DIR__ . '/../../../conf.d/data_templates/' . $this->app['phraseanet.structure-template']->getAvailable()->getTemplateName($template) . '.xml');
$databox = \databox::create($this->app, $dbConn, $template);
$this->app->getAclForUser($admin)

View File

@@ -738,8 +738,8 @@
<td><label>{{ 'Modele de donnees' | trans }}</label></td>
<td>
<select name="db_template" class="databox_creation_input">
{% for template in available_templates %}
<option value="{{ template }}">{{ template }}</option>
{% for key,template in available_templates %}
<option value="{{ key }}">{{ template }}</option>
{% endfor %}
</select>
</td>