Don't use the injector from inside the share library, pass the lock object in as...
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 20 May 2010 16:33:05 +0000 (12:33 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 20 May 2010 16:34:35 +0000 (12:34 -0400)
framework/Share/lib/Horde/Share/Object.php
kronolith/lib/Api.php

index fd6a2cc..054898f 100644 (file)
@@ -237,7 +237,8 @@ class Horde_Share_Object
     /**
      * Locks an item from this share, or the entire share if no item defined.
      *
-     * @param string $item_uid  A uid of an item from this share.
+     * @param Horde_Lock $locks  The Horde_Lock object
+     * @param string $item_uid   A uid of an item from this share.
      *
      * @return mixed   A lock ID on success, PEAR_Error on failure, false if:
      *                  - The share is already locked
@@ -246,17 +247,8 @@ class Horde_Share_Object
      *                    locked in the share
      * @throws Horde_Share_Exception
      */
-    public function lock($item_uid = null)
+    public function lock(Horde_Lock $locks, $item_uid = null)
     {
-        try {
-            // TODO: Pass this in as a parameter, don't use the injector directly in
-            //       a library
-            $locks = $GLOBALS['injector']->getInstance('Horde_Lock');
-        } catch (Horde_Lock_Exception $e) {
-            Horde::logMessage($e, 'ERR');
-            throw new Horde_Share_Exception($e);
-        }
-
         $shareid = $this->getId();
 
         // Default parameters.
@@ -299,21 +291,14 @@ class Horde_Share_Object
     /**
      * Removes the lock for a lock ID.
      *
-     * @param string $lockid  The lock ID as generated by a previous call
-     *                        to lock().
+     * @param Horde_Lock $locks  The lock object
+     * @param string $lockid     The lock ID as generated by a previous call
+     *                           to lock().
      *
      * @return mixed  True on success, PEAR_Error on failure.
      */
-    public function unlock($lockid)
+    public function unlock(Horde_Lock $locks, $lockid)
     {
-        try {
-            // TODO: pass in method, do not use injector in library
-            $locks = $GLOBALS['injector']->getInstance('Horde_Lock');
-        } catch (Horde_Lock_Exception $e) {
-            Horde::logMessage($e, 'ERR');
-            throw new Horde_Share_Exception($e);
-        }
-
         return $locks->clearLock($lockid);
     }
 
@@ -323,22 +308,15 @@ class Horde_Share_Object
      * First this checks for share locks and if none exists, checks for item
      * locks (if item_uid defined).  It will return the first lock found.
      *
-     * @param string $item_uid  A uid of an item from this share.
+     * @param Horde_Lock  $locks  The lock object.
+     * @param string $item_uid    A uid of an item from this share.
      *
      * @return mixed   Hash with the found lock information in 'lock' and the
      *                 lock type ('share' or 'item') in 'type', or an empty
      *                 array if there are no locks, or a PEAR_Error on failure.
      */
-    public function checkLocks($item_uid = null)
+    public function checkLocks(Horde_Lock $locks, $item_uid = null)
     {
-        // TODO: Inject lock object, do not use injector in library
-        try {
-            $locks = $GLOBALS['injector']->getInstance('Horde_Lock');
-        } catch (Horde_Lock_Exception $e) {
-            Horde::logMessage($e, 'ERR');
-            throw new Horde_Share_Exception($e);
-        }
-
         $shareid = $this->getId();
         $locktype = Horde_Lock::TYPE_EXCLUSIVE;
 
index b39deec..77b4018 100644 (file)
@@ -1289,8 +1289,8 @@ class Kronolith_Api extends Horde_Registry_Api
     /**
      * Places an exclusive lock for a calendar or an event.
      *
-     * @param array $calendar  The calendar to lock
-     * @param array $event     The event to lock
+     * @param string $calendar  The id of the calendar to lock
+     * @param string $event     The uid for the event to lock
      *
      * @return mixed   A lock ID on success, false if:
      *                   - The calendar is already locked
@@ -1305,7 +1305,10 @@ class Kronolith_Api extends Horde_Registry_Api
             Kronolith::listCalendars(false, Horde_Perms::EDIT))) {
             throw new Horde_Exception_PermissionDenied();
         }
-        return $GLOBALS['kronolith_shares']->getShare($calendar)->lock($calendar, $event);
+        if (!empty($event)) {
+            $uid = $calendar . ':' . $event;
+        }
+        return $GLOBALS['kronolith_shares']->getShare($calendar)->lock($GLOBALS['injector']->getInstance('Horde_Lock'), $uid);
     }
 
     /**
@@ -1322,7 +1325,8 @@ class Kronolith_Api extends Horde_Registry_Api
             Kronolith::listCalendars(false, Horde_Perms::EDIT))) {
             throw new Horde_Exception_PermissionDenied();
         }
-        return $GLOBALS['kronolith_shares']->getShare($calendar)->unlock($lockid);
+
+        return $GLOBALS['kronolith_shares']->getShare($calendar)->unlock($GLOBALS['injector']->getInstance('Horde_Lock'), $lockid);
     }
 
     /**
@@ -1339,7 +1343,10 @@ class Kronolith_Api extends Horde_Registry_Api
             Kronolith::listCalendars(false, Horde_Perms::READ))) {
             throw new Horde_Exception_PermissionDenied();
         }
-        return $GLOBALS['kronolith_shares']->getShare($calendar)->checkLocks($event);
+        if (!empty($event)) {
+            $uid = $calendar . ':' . $event;
+        }
+        return $GLOBALS['kronolith_shares']->getShare($calendar)->checkLocks($GLOBALS['injector']->getInstance('Horde_Lock'), $uid);
     }
 
     /**