Add a confluence configuration checker. Allow configuration overrides on daux command
This commit is contained in:
parent
a40769b48a
commit
519e85b5dc
@ -129,4 +129,23 @@ class Config extends ArrayObject
|
||||
|
||||
return $this['html']['inherit_index'];
|
||||
}
|
||||
|
||||
public function setConfigurationOverrideFile($override_file)
|
||||
{
|
||||
$this['override_file'] = $override_file;
|
||||
}
|
||||
|
||||
public function getConfigurationOverrideFile()
|
||||
{
|
||||
if (array_key_exists('override_file', $this)) {
|
||||
return $this['override_file'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getConfluenceConfiguration()
|
||||
{
|
||||
return $this['confluence'];
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ class Serve extends DauxCommand
|
||||
|
||||
putenv('DAUX_SOURCE=' . $daux->getParams()->getDocumentationDirectory());
|
||||
putenv('DAUX_THEME=' . $daux->getParams()->getThemesPath());
|
||||
putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationOverrideFile());
|
||||
|
||||
//TODO :: support configuration and processor
|
||||
//putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationFile());
|
||||
//TODO :: support processor
|
||||
//putenv('DAUX_PROCESSOR=' . $daux->getParams()->getProcessorFile());
|
||||
|
||||
$base = ProcessUtils::escapeArgument(__DIR__ . '/../../');
|
||||
|
@ -68,7 +68,7 @@ class Daux
|
||||
* @param string $override_file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function initializeConfiguration($override_file = 'config.json')
|
||||
public function initializeConfiguration($override_file = null)
|
||||
{
|
||||
$params = $this->getParams();
|
||||
|
||||
@ -79,8 +79,10 @@ class Daux
|
||||
$this->loadConfiguration($docs_path . DIRECTORY_SEPARATOR . 'config.json');
|
||||
|
||||
// Read command line overrides
|
||||
if (!is_null($override_file)) {
|
||||
$this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . $override_file);
|
||||
$override_file = $this->getConfigurationOverride($override_file);
|
||||
if ($override_file != null) {
|
||||
$params->setConfigurationOverrideFile($override_file);
|
||||
$this->loadConfiguration($override_file);
|
||||
}
|
||||
|
||||
// Validate and set theme path
|
||||
@ -94,6 +96,30 @@ class Daux
|
||||
}
|
||||
}
|
||||
|
||||
public function getConfigurationOverride($override_file)
|
||||
{
|
||||
// When running through `daux --serve` we set an environment variable to know where we started from
|
||||
$env = getenv('DAUX_CONFIGURATION');
|
||||
if ($env && file_exists($env)) {
|
||||
return $env;
|
||||
}
|
||||
|
||||
if ($override_file == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (file_exists($override_file)) {
|
||||
return getcwd() . '/' . $override_file;
|
||||
}
|
||||
|
||||
$newPath = $this->local_base . DIRECTORY_SEPARATOR . $override_file;
|
||||
if (file_exists($newPath)) {
|
||||
return $newPath;
|
||||
}
|
||||
|
||||
throw new Exception('The configuration override file does not exist. Check the path again : ' . $override_file);
|
||||
}
|
||||
|
||||
public function normalizeThemePath($path)
|
||||
{
|
||||
// When running through `daux --serve` we set an environment variable to know where we started from
|
||||
|
@ -24,6 +24,34 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
public function __construct(Daux $daux)
|
||||
{
|
||||
$this->daux = $daux;
|
||||
|
||||
$this->checkConfiguration();
|
||||
}
|
||||
|
||||
public function checkConfiguration()
|
||||
{
|
||||
$config = $this->daux->getParams();
|
||||
$confluence = $config->getConfluenceConfiguration();
|
||||
|
||||
if ($confluence == null) {
|
||||
throw new \RuntimeException("You must specify your Confluence configuration");
|
||||
}
|
||||
|
||||
$mandatory = ['space_id', 'base_url', 'user', 'pass', 'prefix'];
|
||||
$errors = [];
|
||||
foreach ($mandatory as $key) {
|
||||
if (!array_key_exists($key, $confluence)) {
|
||||
$errors[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($errors)) {
|
||||
throw new \RuntimeException("The following options are mandatory for confluence : '" . join("', '", $errors) . "'");
|
||||
}
|
||||
|
||||
if (!array_key_exists('ancestor_id', $confluence) && !array_key_exists('root_id', $confluence)) {
|
||||
throw new \RuntimeException("You must specify an 'ancestor_id' or a 'root_id' for confluence.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user