Skip to content

Commit

Permalink
Add fromHash() and toHash() methods.
Browse files Browse the repository at this point in the history
These are helpers for backup/restore.
  • Loading branch information
yunosh committed May 24, 2017
1 parent ec6947d commit 8433433
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 6 deletions.
27 changes: 27 additions & 0 deletions framework/Share/doc/Horde/Share/UPGRADING
@@ -0,0 +1,27 @@
=======================
Upgrading Horde_Share
=======================

:Contact: dev@lists.horde.org

.. contents:: Contents
.. section-numbering::


This lists the API changes between releases of the package.


Upgrading to 2.2
================

- Horde_Share_Base

- fromHash()

This method has been added.

- Horde_Share_Object

- toHash()

This method has been added.
27 changes: 27 additions & 0 deletions framework/Share/lib/Horde/Share/Base.php
Expand Up @@ -468,6 +468,33 @@ public function addShare(Horde_Share_Object $share)
*/
abstract protected function _addShare(Horde_Share_Object $share);

/**
* Adds a share created from a hash.
*
* @since Horde_Share 2.2.0
*
* @param array $hash A hash like exported from
* Horde_Share_Object#toHash().
*
* @return Horde_Share_Object A new share object.
*/
public function fromHash(array $hash)
{
$share = $this->newShare($hash['owner'], $hash['name']);
if (isset($hash['attributes'])) {
foreach ($hash['attributes'] as $attribute => $value) {
$share->set($attribute, $value);
}
}
if (isset($hash['permissions'])) {
$permission = $share->getPermission();
$permission->setData($hash['permissions']);
$share->setPermission($permission, false);
}
$this->addShare($share);
return $share;
}

/**
* Renames a share in the shares system.
*
Expand Down
24 changes: 24 additions & 0 deletions framework/Share/lib/Horde/Share/Object.php
Expand Up @@ -111,6 +111,30 @@ public function save()
*/
abstract protected function _save();

/**
* Exports the share object as a PHP hash.
*
* @since Horde_Shares 2.2.0
*
* @return array Hash representation of this share.
*/
public function toHash()
{
return array(
'id' => $this->getId(),
'name' => $this->getName(),
'attributes' => $this->_getAttributes(),
'permissions' => $this->getPermission()->getData(),
);
}

/**
* Returns the share attributes.
*
* @return array All share attributes as a hash.
*/
abstract protected function _getAttributes();

/**
* Gives a user a certain privilege for this share.
*
Expand Down
17 changes: 17 additions & 0 deletions framework/Share/lib/Horde/Share/Object/Kolab.php
Expand Up @@ -344,6 +344,23 @@ protected function _save()
$this->getPermission()->save();
}

/**
* Returns the share attributes.
*
* @return array All share attributes as a hash.
*/
protected function _getAttributes()
{
$blacklist = array('owner', 'prefix', 'delimiter', 'subpath');
$attributes = array();
foreach ($this->data as $attribute => $value) {
if (!in_array($attribute, $blacklist)) {
$attributes[$attribute] = $value;
}
}
return $attributes;
}

/**
* Checks to see if a user has a given permission.
*
Expand Down
16 changes: 16 additions & 0 deletions framework/Share/lib/Horde/Share/Object/Sql.php
Expand Up @@ -341,6 +341,22 @@ protected function _save()
return true;
}

/**
* Returns the share attributes.
*
* @return array All share attributes as a hash.
*/
protected function _getAttributes()
{
$attributes = array();
foreach ($this->data as $attribute => $value) {
if (strpos($attribute, 'attribute_') === 0) {
$attributes[substr($attribute, 10)] = $value;
}
}
return $attributes;
}

/**
* Checks to see if a user has a given permission.
*
Expand Down
14 changes: 8 additions & 6 deletions framework/Share/package.xml
Expand Up @@ -23,10 +23,10 @@ owns or has access to.</description>
<email>mrubinsk@horde.org</email>
<active>yes</active>
</lead>
<date>2017-03-20</date>
<date>2017-05-24</date>
<version>
<release>2.1.3</release>
<api>1.4.0</api>
<release>2.2.0</release>
<api>1.5.0</api>
</version>
<stability>
<release>stable</release>
Expand All @@ -42,6 +42,7 @@ owns or has access to.</description>
<dir name="Horde">
<dir name="Share">
<file name="COPYING" role="doc" />
<file name="UPGRADING" role="doc" />
</dir> <!-- /doc/Horde/Share -->
</dir> <!-- /doc/Horde -->
</dir> <!-- /doc -->
Expand Down Expand Up @@ -455,6 +456,7 @@ owns or has access to.</description>
<phprelease>
<filelist>
<install as="COPYING" name="doc/Horde/Share/COPYING" />
<install as="UPGRADING" name="doc/Horde/Share/UPGRADING" />
<install as="Horde/Share/Base.php" name="lib/Horde/Share/Base.php" />
<install as="Horde/Share/Exception.php" name="lib/Horde/Share/Exception.php" />
<install as="Horde/Share/Kolab.php" name="lib/Horde/Share/Kolab.php" />
Expand Down Expand Up @@ -1084,12 +1086,12 @@ Initial release as a PEAR package
</release>
<release>
<version>
<release>2.1.3</release>
<api>1.4.0</api></version>
<release>2.2.0</release>
<api>1.5.0</api></version>
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2017-03-20</date>
<date>2017-05-24</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
Expand Down

0 comments on commit 8433433

Please sign in to comment.