Skip to content

Commit

Permalink
[jan] Add Horde_Pear_Package_Xml#setNotes().
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Oct 25, 2017
1 parent 31eb4c5 commit 5053cc8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
38 changes: 35 additions & 3 deletions lib/Horde/Pear/Package/Xml.php
Expand Up @@ -441,8 +441,6 @@ public function syncCurrentVersion()
* Add a new note to the package.xml
*
* @param string $note The note text.
*
* @return NULL
*/
public function addNote($note)
{
Expand All @@ -462,6 +460,28 @@ public function addNote($note)
}
}

/**
* Sets notes in the package.xml
*
* @param array[] $note Lists of note texts with versions as keys.
*/
public function setNotes(array $notes)
{
foreach ($notes as $version => $info) {
$new_notes = "\n* "
. implode("\n* ", explode("\n", trim($info['notes'])))
. "\n ";
if ($version == $this->getVersion()) {
$this->replaceTextNode('/p:package/p:notes', $new_notes);
}
if ($node = $this->_fetchRelease($version)) {
$this->replaceTextNodeRelativeTo(
'./p:notes', $node, $new_notes . ' '
);
}
}
}

/**
* Set the version in the package.xml
*
Expand Down Expand Up @@ -668,9 +688,21 @@ private function _requireCurrentRelease()
*
* @return DOMElement|NULL The release node or empty if no such node was found.
*/
private function _fetchCurrentRelease()
protected function _fetchCurrentRelease()
{
$version = $this->getNodeText('/p:package/p:version/p:release');
return $this->_fetchRelease($version);
}

/**
* Fetch the node holding release information in the changelog.
*
* @param string $version Version to fetch the release information from.
*
* @return DOMElement|NULL The release node or empty if no such node was found.
*/
protected function _fetchRelease($version)
{
foreach ($this->findNodes('/p:package/p:changelog/p:release') as $release) {
if ($this->getNodeTextRelativeTo('./p:version/p:release', $release) == $version) {
return $release;
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Expand Up @@ -21,6 +21,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [jan] Add Horde_Pear_Package_Xml#setNotes().
* [jan] Set replacement tasks for binaries and translation handlers.
</notes>
<contents>
Expand Down Expand Up @@ -665,6 +666,7 @@
<date>2017-10-20</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [jan] Add Horde_Pear_Package_Xml#setNotes().
* [jan] Set replacement tasks for binaries and translation handlers.
</notes>
</release>
Expand Down

0 comments on commit 5053cc8

Please sign in to comment.