Skip to content

Commit

Permalink
NRFE-361: Overwrite full page instead of using begin/end markers
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Weiske committed Feb 14, 2014
1 parent c0f2fd4 commit 7742295
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 95 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2014-02-14 Christian Weiske <christian.weiske@netresearch.de>

* NRFE-361: Overwrite full page instead of using begin/end markers
This is necessary for Confluence 5, since that does
not support exporting wiki markup anymore.
* Version 0.5.0

2014-01-21 Christian Weiske <christian.weiske@netresearch.de>

* NRFE-347: remove numberedHeadings macro since Confluence 5.1
Expand Down
28 changes: 24 additions & 4 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<active>yes</active>
</lead>

<date>2014-01-21</date>
<date>2014-02-14</date>
<time>00:00:00</time>

<version>
<release>0.4.0</release>
<api>0.4.0</api>
<release>0.5.0</release>
<api>0.5.0</api>
</version>

<stability>
Expand All @@ -37,7 +37,9 @@
<license uri="http://www.gnu.org/licenses/agpl.html">AGPL</license>

<notes>
NRFE-347: remove numberedHeadings macro since Confluence 5.1 does not support it anymore
NRFE-361: Overwrite full page instead of using begin/end markers.
This is necessary for Confluence 5, since that does not support exporting
wiki markup anymore.
</notes>

<contents>
Expand Down Expand Up @@ -128,6 +130,24 @@

<changelog>

<release>
<version>
<release>0.5.0</release>
<api>0.5.0</api>
</version>
<stability>
<release>alpha</release>
<api>alpha</api>
</stability>
<date>2014-02-14</date>
<license uri="http://www.gnu.org/licenses/agpl.html">AGPL</license>
<notes>
NRFE-361: Overwrite full page instead of using begin/end markers.
This is necessary for Confluence 5, since that does not support exporting
wiki markup anymore.
</notes>
</release>

<release>
<version>
<release>0.4.0</release>
Expand Down
92 changes: 1 addition & 91 deletions src/netresearch/DeployRst/Driver/Confluence.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,7 @@ class Driver_Confluence extends Driver

protected $filterObj;

/**
* Marks the beginning of the automatic deployed rST document
*
* @var string
*/
public $markerBegin = "{html}<!-- BEGIN deploy-content -->{html}\n";

/**
* Marks the end of the automatic deployed rST document
*
* @var string
*/
public $markerEnd = "{html}<!-- END deploy-content -->{html}\n";

/**
* Create a new instance, set some variables, load tools and parameters
Expand Down Expand Up @@ -76,10 +64,7 @@ public function run()
}

$this->storePage(
$this->embedIntoPage(
$this->getCurrentPage(),
$this->convertRst()
)
$this->convertRst()
);
}

Expand Down Expand Up @@ -267,81 +252,6 @@ protected function loadFilter()
return $this->filterObj;
}

/**
* Load the current wiki page contents from confluence
*
* @return string Confluence markup
*/
public function getCurrentPage()
{
//we cannot pipe it, see
// https://studio.plugins.atlassian.com/browse/CSOAP-122
$tmpfile = tempnam(sys_get_temp_dir(), 'deploy-confluence-');
$cmd = sprintf(
$this->cmd['cflcli']
. ' --server %s --user %s --password %s'
. ' --action getPageSource --space %s --title %s --file %s --quiet',
escapeshellarg($this->cflHost),
escapeshellarg($this->cflUser),
escapeshellarg($this->cflPass),
escapeshellarg($this->cflSpace),
escapeshellarg($this->cflPage),
escapeshellarg($tmpfile)
);
list($lastline, $retval) = Exec::run($cmd);
$curDoc = file_get_contents($tmpfile);
unlink($tmpfile);

//list($curDoc, $retval) = run($cmd);
if ($retval !== 0) {
throw new Exception(
'Error fetching confluence document source' . "\n" . $lastline,
21
);
}
if (strlen($curDoc) == 0) {
throw new Exception('Document is empty. This might be a bug', 22);
}

if (substr($curDoc, -1) != "\n") {
$curDoc .= "\n";
}

return $curDoc;
}

/**
* Embeds the rST document confluence markup into the existing document
* markup.
*
* @param string $curDoc Current confluence document
* @param string $newCont rST confluence document
*
* @return string Resulting document
*/
public function embedIntoPage($curDoc, $newCont)
{
$begin = strpos($curDoc, $this->markerBegin);
$end = strpos($curDoc, $this->markerEnd);

if ($begin === false && $end === false) {
//add it to the end
$newDoc = $curDoc . "\n\n"
. $this->markerBegin . $newCont . $this->markerEnd;
} else if ($begin === false || $end === false) {
throw new Exception('Begin or end marker not found', 23);
} else if ($end < $begin) {
throw new Exception('Begin marker after end marker', 24);
} else {
//replace it
$newDoc = substr($curDoc, 0, $begin)
. $this->markerBegin . $newCont . $this->markerEnd
. substr($curDoc, $end + strlen($this->markerEnd));
}

return $newDoc;
}

/**
* Store the confluence document in the confluence wiki.
*
Expand Down

0 comments on commit 7742295

Please sign in to comment.