diff --git a/framework/Share/doc/Horde/Share/UPGRADING b/framework/Share/doc/Horde/Share/UPGRADING
new file mode 100644
index 00000000000..faf166cea66
--- /dev/null
+++ b/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.
diff --git a/framework/Share/lib/Horde/Share/Base.php b/framework/Share/lib/Horde/Share/Base.php
index 9e78b60cb6a..e47ee570ad0 100644
--- a/framework/Share/lib/Horde/Share/Base.php
+++ b/framework/Share/lib/Horde/Share/Base.php
@@ -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.
*
diff --git a/framework/Share/lib/Horde/Share/Object.php b/framework/Share/lib/Horde/Share/Object.php
index 6822a5b6efe..d9e340ae92f 100644
--- a/framework/Share/lib/Horde/Share/Object.php
+++ b/framework/Share/lib/Horde/Share/Object.php
@@ -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.
*
diff --git a/framework/Share/lib/Horde/Share/Object/Kolab.php b/framework/Share/lib/Horde/Share/Object/Kolab.php
index aae5df594b5..12200f2c7ff 100644
--- a/framework/Share/lib/Horde/Share/Object/Kolab.php
+++ b/framework/Share/lib/Horde/Share/Object/Kolab.php
@@ -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.
*
diff --git a/framework/Share/lib/Horde/Share/Object/Sql.php b/framework/Share/lib/Horde/Share/Object/Sql.php
index 12d78f05617..b6ec73a6ceb 100644
--- a/framework/Share/lib/Horde/Share/Object/Sql.php
+++ b/framework/Share/lib/Horde/Share/Object/Sql.php
@@ -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.
*
diff --git a/framework/Share/package.xml b/framework/Share/package.xml
index 7f6def65289..836cc7428ba 100644
--- a/framework/Share/package.xml
+++ b/framework/Share/package.xml
@@ -23,10 +23,10 @@ owns or has access to.
mrubinsk@horde.org
yes
- 2017-03-20
+ 2017-05-24
- 2.1.3
- 1.4.0
+ 2.2.0
+ 1.5.0
stable
@@ -42,6 +42,7 @@ owns or has access to.
+
@@ -455,6 +456,7 @@ owns or has access to.
+
@@ -1084,12 +1086,12 @@ Initial release as a PEAR package
- 2.1.3
- 1.4.0
+ 2.2.0
+ 1.5.0
stable
stable
- 2017-03-20
+ 2017-05-24
LGPL-2.1
*