Only list deletable pages if there are any
This commit is contained in:
parent
e5ee061ddd
commit
e3a89832c5
@ -32,6 +32,11 @@ class Publisher
|
|||||||
*/
|
*/
|
||||||
public $output;
|
public $output;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array files that can be deleted
|
||||||
|
*/
|
||||||
|
protected $deletable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $confluence
|
* @param $confluence
|
||||||
*/
|
*/
|
||||||
@ -41,6 +46,8 @@ class Publisher
|
|||||||
|
|
||||||
$this->client = new Api($confluence['base_url'], $confluence['user'], $confluence['pass']);
|
$this->client = new Api($confluence['base_url'], $confluence['user'], $confluence['pass']);
|
||||||
$this->client->setSpace($confluence['space_id']);
|
$this->client->setSpace($confluence['space_id']);
|
||||||
|
|
||||||
|
$this->deletable = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run($title, $closure)
|
public function run($title, $closure)
|
||||||
@ -83,7 +90,7 @@ class Publisher
|
|||||||
);
|
);
|
||||||
|
|
||||||
$published = $this->run(
|
$published = $this->run(
|
||||||
"Create placeholder pages...\n",
|
"Create placeholder pages...",
|
||||||
function () use ($tree, $published) {
|
function () use ($tree, $published) {
|
||||||
return $this->createRecursive($this->confluence['ancestor_id'], $tree, $published);
|
return $this->createRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||||
}
|
}
|
||||||
@ -92,15 +99,7 @@ class Publisher
|
|||||||
$this->output->writeLn('Publishing updates...');
|
$this->output->writeLn('Publishing updates...');
|
||||||
$published = $this->updateRecursive($this->confluence['ancestor_id'], $tree, $published);
|
$published = $this->updateRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||||
|
|
||||||
|
$this->handleDeletables($published);
|
||||||
if ($this->shouldDelete()) {
|
|
||||||
$this->output->writeLn('Deleting obsolete pages...');
|
|
||||||
} else {
|
|
||||||
$this->output->writeLn('Listing obsolete pages...');
|
|
||||||
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.\n";
|
|
||||||
}
|
|
||||||
$this->deleteRecursive($published);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function niceTitle($title)
|
protected function niceTitle($title)
|
||||||
@ -197,24 +196,44 @@ class Publisher
|
|||||||
return array_key_exists('delete', $this->confluence) && $this->confluence['delete'];
|
return array_key_exists('delete', $this->confluence) && $this->confluence['delete'];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function deleteRecursive($published, $prefix = '')
|
protected function listDeletable($published, $prefix = '')
|
||||||
{
|
{
|
||||||
foreach ($published['children'] as $child) {
|
foreach ($published['children'] as $child) {
|
||||||
if (array_key_exists('children', $child) && count($child['children'])) {
|
if (array_key_exists('children', $child) && count($child['children'])) {
|
||||||
$this->deleteRecursive($child, $child['title'] . '/');
|
$this->listDeletable($child, $child['title'] . '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists('needed', $child)) {
|
if (!array_key_exists('needed', $child)) {
|
||||||
if ($this->shouldDelete()) {
|
$this->deletable[$child['id']] = $prefix . $child['title'];
|
||||||
$this->run(
|
}
|
||||||
'- ' . $prefix . $child['title'],
|
}
|
||||||
function () use ($child) {
|
}
|
||||||
$this->client->deletePage($child['id']);
|
|
||||||
}
|
protected function handleDeletables($published)
|
||||||
);
|
{
|
||||||
} else {
|
$this->listDeletable($published);
|
||||||
echo '- ' . $prefix . $child['title'] . "\n";
|
|
||||||
}
|
if (!count($this->deletable)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->shouldDelete()) {
|
||||||
|
$this->output->writeLn('Deleting obsolete pages...');
|
||||||
|
foreach ($this->deletable as $id => $title) {
|
||||||
|
$this->run(
|
||||||
|
'- ' . $title,
|
||||||
|
function () use ($id) {
|
||||||
|
$this->client->deletePage($id);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->output->writeLn('Listing obsolete pages...');
|
||||||
|
$this->output->writeLn("> The following pages will not be deleted, but just listed for information.");
|
||||||
|
$this->output->writeLn("> If you want to delete these pages, you need to set the --delete flag on the command.");
|
||||||
|
foreach ($this->deletable as $id => $title) {
|
||||||
|
$this->output->writeLn("- $title");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user