[Confluence] Delete pages that exist on confluence but not in the documentation
Dieser Commit ist enthalten in:
Ursprung
74b11f6c7b
Commit
12c4a150e0
@ -42,6 +42,7 @@
|
||||
},
|
||||
|
||||
"confluence": {
|
||||
"prefix": ""
|
||||
"prefix": "",
|
||||
"delete": false
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php namespace Todaymade\Daux\Console;
|
||||
|
||||
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Daux;
|
||||
|
||||
@ -15,11 +15,12 @@ class Generate extends SymfonyCommand
|
||||
$this
|
||||
->setName('generate')
|
||||
->setDescription('Generate documentation')
|
||||
->addOption('configuration', 'c', InputArgument::OPTIONAL, 'Configuration file')
|
||||
->addOption('format', 'f', InputArgument::OPTIONAL, 'Output format, html or confluence', 'html')
|
||||
->addOption('processor', 'p', InputArgument::OPTIONAL, 'Manipulations on the tree')
|
||||
->addOption('source', 's', InputArgument::OPTIONAL, 'Where to take the documentation from')
|
||||
->addOption('destination', 'd', InputArgument::OPTIONAL, $description, 'static');
|
||||
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
|
||||
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output format, html or confluence', 'html')
|
||||
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree')
|
||||
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
|
||||
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete pages not linked to a documentation page (confluence)')
|
||||
->addOption('destination', 'd', InputOption::VALUE_REQUIRED, $description, 'static');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
@ -58,6 +59,10 @@ class Generate extends SymfonyCommand
|
||||
|
||||
$daux->initializeConfiguration($input->getOption('configuration'));
|
||||
|
||||
if ($input->getOption('delete')) {
|
||||
$daux->getParams()['confluence']['delete'] = true;
|
||||
}
|
||||
|
||||
return $daux;
|
||||
}
|
||||
|
||||
|
@ -74,14 +74,21 @@ class Publisher
|
||||
);
|
||||
|
||||
$published = $this->run(
|
||||
"Create placeholder pages...",
|
||||
"Create placeholder pages...\n",
|
||||
function() use ($tree, $published) {
|
||||
return $this->createRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||
}
|
||||
);
|
||||
|
||||
$this->output->writeLn("Publishing updates...");
|
||||
$this->updateRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||
$published = $this->updateRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||
|
||||
$this->output->writeLn("Deleting obsolete pages...");
|
||||
if (!$this->shouldDelete()) {
|
||||
echo "> The following pages will not be deleted, but just listed for information.\n";
|
||||
echo "> If you want to delete these pages, you need to set the --delete flag on the command.";
|
||||
}
|
||||
$this->deleteRecursive($published);
|
||||
}
|
||||
|
||||
protected function niceTitle($title)
|
||||
@ -115,20 +122,22 @@ class Publisher
|
||||
{
|
||||
$published = $callback($parent_id, $entry, $published);
|
||||
|
||||
if (array_key_exists('children', $entry)) {
|
||||
foreach ($entry['children'] as $child) {
|
||||
$pub = [];
|
||||
if (isset($published['children']) && array_key_exists($child['title'], $published['children'])) {
|
||||
$pub = $published['children'][$child['title']];
|
||||
}
|
||||
if (!array_key_exists('children', $entry)) {
|
||||
return $published;
|
||||
}
|
||||
|
||||
$published['children'][$child['title']] = $this->recursiveWithCallback(
|
||||
$published['id'],
|
||||
$child,
|
||||
$pub,
|
||||
$callback
|
||||
);
|
||||
foreach ($entry['children'] as $child) {
|
||||
$pub = [];
|
||||
if (isset($published['children']) && array_key_exists($child['title'], $published['children'])) {
|
||||
$pub = $published['children'][$child['title']];
|
||||
}
|
||||
|
||||
$published['children'][$child['title']] = $this->recursiveWithCallback(
|
||||
$published['id'],
|
||||
$child,
|
||||
$pub,
|
||||
$callback
|
||||
);
|
||||
}
|
||||
|
||||
return $published;
|
||||
@ -137,9 +146,6 @@ class Publisher
|
||||
protected function createRecursive($parent_id, $entry, $published)
|
||||
{
|
||||
$callback = function($parent_id, $entry, $published) {
|
||||
|
||||
//TODO :: remove deleted pages
|
||||
|
||||
// nothing to do if the ID already exists
|
||||
if (array_key_exists('id', $published)) {
|
||||
return $published;
|
||||
@ -164,6 +170,7 @@ class Publisher
|
||||
if (array_key_exists('id', $published) && array_key_exists('page', $entry)) {
|
||||
$this->updatePage($parent_id, $entry, $published);
|
||||
}
|
||||
$published['needed'] = true;
|
||||
|
||||
return $published;
|
||||
};
|
||||
@ -171,6 +178,35 @@ class Publisher
|
||||
return $this->recursiveWithCallback($parent_id, $entry, $published, $callback);
|
||||
}
|
||||
|
||||
protected function shouldDelete()
|
||||
{
|
||||
return array_key_exists('delete', $this->confluence) && $this->confluence['delete'];
|
||||
}
|
||||
|
||||
protected function deleteRecursive($published, $prefix = '')
|
||||
{
|
||||
foreach($published['children'] as $child) {
|
||||
if (array_key_exists('children', $child) && count($child['children'])) {
|
||||
$this->deleteRecursive($child, $child['title'] . '/');
|
||||
}
|
||||
|
||||
if (!array_key_exists('needed', $child)) {
|
||||
|
||||
if ($this->shouldDelete()) {
|
||||
$this->run(
|
||||
"- " . $prefix . $child['title'],
|
||||
function() use ($child) {
|
||||
$this->client->deletePage($child['id']);
|
||||
}
|
||||
);
|
||||
|
||||
} else {
|
||||
echo "- " . $prefix . $child['title'] . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function shouldUpdate($local, $published)
|
||||
{
|
||||
if (!array_key_exists('content', $published)) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren