Add share locking.
authorAlfonso Marí­n Marí­n <almarin@um.es>
Wed, 21 Jan 2009 17:23:59 +0000 (18:23 +0100)
committerJan Schneider <jan@horde.org>
Wed, 21 Jan 2009 18:15:53 +0000 (19:15 +0100)
kronolith/lib/api.php

index 2d82478..2860481 100644 (file)
@@ -126,6 +126,21 @@ $_services['unsubscribe'] = array(
     'type' => 'boolean',
 );
 
+$_services['lock'] = array(
+    'args' => array('calendar' => 'string', 'event' => 'string'),
+    'type' => 'string'
+);
+
+$_services['unlock'] = array(
+    'args' => array('calendar' => 'string', 'lockid' => 'string'),
+    'type' => 'string'
+);
+
+$_services['checklocks'] = array(
+    'args' => array('calendar' => 'string', 'event' => 'string'),
+    'type' => 'string'
+);
+
 /**
  * Returns a list of available permissions.
  *
@@ -1429,3 +1444,68 @@ function _kronolith_unsubscribe($calendar)
         return PEAR::raiseError('Unknown calendar specification');
     }
 }
+
+
+/**
+ * Place a lock for an exclusive calendar or for an event if defined
+ *
+ * @param array $calendar  The calendar to lock
+ * @param array $event     The event to lock
+ *
+ * @return mixed    A string lock ID on success; PEAR_Error on failure;
+ *                  false if:
+ *                    - The calendar is already locked
+ *                    - The event is already locked
+ *                    - We want a calendar lock and exists any event already
+ *                      locked associated to the calendar
+ */
+function _kronolith_lock($calendar, $event = null)
+{
+    require_once dirname(__FILE__) . '/base.php';
+    global $kronolith_shares;
+
+    if (!array_key_exists($calendar,
+                          Kronolith::listCalendars(false, PERMS_EDIT))) {
+        return PEAR::raiseError(_("Permission Denied"));
+    }
+    $share = &$kronolith_shares->getShare($calendar);
+    return $share->lock($calendar, $event);
+}
+
+/**
+ * Releases a lock
+ *
+ * @param array $calendar  The event to lock
+ * @param array $lockid  The lock id to unlock
+ */
+function _kronolith_unlock($calendar, $lockid)
+{
+    require_once dirname(__FILE__) . '/base.php';
+    global $kronolith_shares;
+
+    if (!array_key_exists($calendar,
+                          Kronolith::listCalendars(false, PERMS_EDIT))) {
+        return PEAR::raiseError(_("Permission Denied"));
+
+    $share = &$kronolith_shares->getShare($calendar);
+    return $share->unlock($lockid);
+}
+
+/**
+ * Check for existing calendar locks, or event locks if defined
+ *
+ * @param array $calendar  The calendar to check locks for
+ * @param array $event     The event to check locks for
+ */
+function _kronolith_checklocks($calendar, $event = null)
+{
+    require_once dirname(__FILE__) . '/base.php';
+    global $kronolith_shares;
+
+    if (!array_key_exists($calendar,
+                          Kronolith::listCalendars(false, PERMS_READ))) {
+        return PEAR::raiseError(_("Permission Denied"));
+
+    $share = &$kronolith_shares->getShare($calendar);
+    return $share->checkLocks($event);
+}
\ No newline at end of file