Example #1
0
 public function publish(array $tree)
 {
     echo "Finding Root Page...\n";
     if (array_key_exists('ancestor_id', $this->confluence)) {
         $pages = $this->client->getList($this->confluence['ancestor_id']);
         $published = null;
         foreach ($pages as $page) {
             if ($page['title'] == $tree['title']) {
                 $published = $page;
                 break;
             }
         }
     } elseif (array_key_exists('root_id', $this->confluence)) {
         $published = $this->client->getPage($this->confluence['root_id']);
         $this->confluence['ancestor_id'] = $published['ancestor_id'];
     } else {
         throw new \RuntimeException('You must at least specify a `root_id` or `ancestor_id` in your confluence configuration.');
     }
     $this->run('Getting already published pages...', function () use(&$published) {
         if ($published != null) {
             $published['children'] = $this->client->getList($published['id'], true);
         }
     });
     $published = $this->run("Create placeholder pages...\n", function () use($tree, $published) {
         return $this->createRecursive($this->confluence['ancestor_id'], $tree, $published);
     });
     $this->output->writeLn('Publishing updates...');
     $published = $this->updateRecursive($this->confluence['ancestor_id'], $tree, $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);
 }