Use symfony console, nicer output
This commit is contained in:
@ -1,19 +1,23 @@
|
||||
<?php namespace Todaymade\Daux\Format\Confluence;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\Format\Base\RunAction;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
|
||||
class Generator
|
||||
{
|
||||
use RunAction;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
public function generate(Daux $daux)
|
||||
public function generate(Daux $daux, OutputInterface $output, $width)
|
||||
{
|
||||
$confluence = $daux->getParams()['confluence'];
|
||||
|
||||
@ -21,15 +25,24 @@ class Generator
|
||||
|
||||
$params = $daux->getParams();
|
||||
|
||||
echo "Generating Tree...\n";
|
||||
$tree = $this->generateRecursive($daux->tree, $params);
|
||||
$tree['title'] = $this->prefix . $daux->getParams()['title'];
|
||||
$tree = $this->runAction(
|
||||
"Generating Tree ...",
|
||||
$output,
|
||||
$width,
|
||||
function() use ($daux, $params) {
|
||||
$tree = $this->generateRecursive($daux->tree, $params);
|
||||
$tree['title'] = $this->prefix . $daux->getParams()['title'];
|
||||
|
||||
return $tree;
|
||||
}
|
||||
);
|
||||
|
||||
$output->writeln("Start Publishing...");
|
||||
|
||||
echo "Start Publishing...\n";
|
||||
$publisher = new Publisher($confluence);
|
||||
$publisher->output = $output;
|
||||
$publisher->width = $width;
|
||||
$publisher->publish($tree);
|
||||
|
||||
echo "Done !\n";
|
||||
}
|
||||
|
||||
private function generateRecursive(Entry $tree, Config $params, $base_url = '')
|
||||
|
@ -2,10 +2,13 @@
|
||||
|
||||
use GuzzleHttp\Exception\BadResponseException;
|
||||
use GuzzleHttp\Exception\ParseException;
|
||||
use Todaymade\Daux\Format\Base\RunAction;
|
||||
|
||||
class Publisher
|
||||
{
|
||||
|
||||
use RunAction;
|
||||
|
||||
/**
|
||||
* @var Api
|
||||
*/
|
||||
@ -21,6 +24,19 @@ class Publisher
|
||||
*/
|
||||
protected $previous_title;
|
||||
|
||||
/**
|
||||
* @var string terminal width
|
||||
*/
|
||||
public $width;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
public $output;
|
||||
|
||||
/**
|
||||
* @param $confluence
|
||||
*/
|
||||
public function __construct($confluence)
|
||||
{
|
||||
$this->confluence = $confluence;
|
||||
@ -29,6 +45,14 @@ class Publisher
|
||||
$this->client->setSpace($confluence['space_id']);
|
||||
}
|
||||
|
||||
public function run($title, $closure) {
|
||||
try {
|
||||
return $this->runAction($title, $this->output, $this->width, $closure);
|
||||
} catch (BadResponseException $e) {
|
||||
echo " X Failed with message: " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function publish(array $tree)
|
||||
{
|
||||
echo "Finding Root Page...\n";
|
||||
@ -41,15 +65,23 @@ class Publisher
|
||||
}
|
||||
}
|
||||
|
||||
echo "Getting already published pages...\n";
|
||||
if ($published != null) {
|
||||
$published['children'] = $this->client->getHierarchy($published['id']);
|
||||
}
|
||||
$this->run(
|
||||
"Getting already published pages...",
|
||||
function() use (&$published) {
|
||||
if ($published != null) {
|
||||
$published['children'] = $this->client->getHierarchy($published['id']);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
echo "Create placeholder pages...\n";
|
||||
$published = $this->createRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||
$published = $this->run(
|
||||
"Create placeholder pages...",
|
||||
function() use ($tree, $published) {
|
||||
return $this->createRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||
}
|
||||
);
|
||||
|
||||
echo "Publishing updates...\n";
|
||||
$this->output->writeLn("Publishing updates...");
|
||||
$this->updateRecursive($this->confluence['ancestor_id'], $tree, $published);
|
||||
}
|
||||
|
||||
@ -195,32 +227,30 @@ class Publisher
|
||||
echo "Updating Pages...\n";
|
||||
}
|
||||
|
||||
echo "- " . $this->niceTitle($entry['file']->getUrl());
|
||||
|
||||
try {
|
||||
if ($this->shouldUpdate($entry['page'], $published)) {
|
||||
$this->client->updatePage(
|
||||
$parent_id,
|
||||
$published['id'],
|
||||
$published['version'] + 1,
|
||||
$entry['title'],
|
||||
$entry['page']->getContent()
|
||||
);
|
||||
echo " √\n";
|
||||
} else {
|
||||
echo " √ (No update needed)\n";
|
||||
}
|
||||
|
||||
if (count($entry['page']->attachments)) {
|
||||
foreach ($entry['page']->attachments as $attachment) {
|
||||
echo " With attachment: $attachment[filename]";
|
||||
$this->client->uploadAttachment($published['id'], $attachment);
|
||||
echo " √\n";
|
||||
$this->run(
|
||||
"- " . $this->niceTitle($entry['file']->getUrl()),
|
||||
function() use ($entry, $published, $parent_id) {
|
||||
if ($this->shouldUpdate($entry['page'], $published)) {
|
||||
$this->client->updatePage(
|
||||
$parent_id,
|
||||
$published['id'],
|
||||
$published['version'] + 1,
|
||||
$entry['title'],
|
||||
$entry['page']->getContent()
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
} catch (BadResponseException $e) {
|
||||
echo " X Failed with message: " . $e->getMessage() . "\n";
|
||||
if (count($entry['page']->attachments)) {
|
||||
foreach ($entry['page']->attachments as $attachment) {
|
||||
$this->run(
|
||||
" With attachment: $attachment[filename]",
|
||||
function() use($published, $attachment) {
|
||||
$this->client->uploadAttachment($published['id'], $attachment);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Verwijs in nieuw issue
Block a user