Fixes for registering and fetching backends

This commit is contained in:
Michael Gapczynski 2012-06-19 14:21:44 -04:00 committed by Bart Visscher
parent 945565f420
commit bd8769a7c5
1 changed files with 12 additions and 19 deletions

View File

@ -43,19 +43,19 @@ class Share {
/** /**
* @brief Register a sharing backend class that extends OCP\Share_Backend for an item type * @brief Register a sharing backend class that extends OCP\Share_Backend for an item type
* @param string Class
* @param string Item type * @param string Item type
* @param object Backend class
* @param string (optional) Depends on item type * @param string (optional) Depends on item type
* @param array (optional) List of supported file extensions if this item type depends on files * @param array (optional) List of supported file extensions if this item type depends on files
* @return Returns true if backend is registered or false if error * @return Returns true if backend is registered or false if error
*/ */
public static function registerBackend($class, $itemType, $dependsOn = null, $supportedFileExtensions = null) { public static function registerBackend($itemType, $class, $dependsOn = null, $supportedFileExtensions = null) {
if (is_subclass_of($class, 'OCP\Share_Backend')) { if (is_subclass_of($class, 'OCP\Share_Backend')) {
if (!isset(self::$backendTypes[$itemType])) { if (!isset(self::$backends[$itemType])) {
self::$backendTypes[$itemType] = array('class' => $class, 'dependsOn' => $dependsOn, 'supportedFileExtensions' => $supportedFileExtensions); self::$backends[$itemType] = array('class' => $class, 'dependsOn' => $dependsOn, 'supportedFileExtensions' => $supportedFileExtensions);
return true; return true;
} else { } else {
\OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class'].' is already registered for '.$itemType, \OC_Log::WARN); \OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not registered, '.self::$backends[$itemType]['class'].' is already registered for '.$itemType, \OC_Log::WARN);
return false; return false;
} }
} }
@ -111,8 +111,10 @@ class Share {
public static function share($itemType, $item, $shareType, $shareWith, $permissions) { public static function share($itemType, $item, $shareType, $shareWith, $permissions) {
$uidOwner = \OC_User::getUser(); $uidOwner = \OC_User::getUser();
// Verify share type and sharing conditions are met // Verify share type and sharing conditions are met
// TODO Doesn't handle types
switch ($shareType) { switch ($shareType) {
case self::SHARETYPE_USER: case self::SHARETYPE_USER:
\OC_Log::write('OCP\Share', 'share type '.$shareType, \OC_Log::ERROR);
if ($shareWith == $uidOwner) { if ($shareWith == $uidOwner) {
\OC_Log::write('OCP\Share', 'Sharing '.$item.' failed, because the user '.$shareWith.' is the item owner', \OC_Log::ERROR); \OC_Log::write('OCP\Share', 'Sharing '.$item.' failed, because the user '.$shareWith.' is the item owner', \OC_Log::ERROR);
return false; return false;
@ -153,6 +155,7 @@ class Share {
// TODO don't loop through folder conversion // TODO don't loop through folder conversion
$uidSharedWith = ''; $uidSharedWith = '';
$gidSharedWith = null; $gidSharedWith = null;
break;
default: default:
\OC_Log::write('OCP\Share', 'Share type '.$shareType.' is not valid for '.$item, \OC_Log::ERROR); \OC_Log::write('OCP\Share', 'Share type '.$shareType.' is not valid for '.$item, \OC_Log::ERROR);
return false; return false;
@ -218,11 +221,10 @@ class Share {
public static function unshareFromSelf($itemType, $itemTarget) { public static function unshareFromSelf($itemType, $itemTarget) {
$uidSharedWith = \OC_User::getUser(); $uidSharedWith = \OC_User::getUser();
if ($item = self::getItems($itemType, $itemTarget, $uidSharedWith, true, null, false, 1)) { if ($item = self::getItems($itemType, $itemTarget, $uidSharedWith, true, null, false, 1)) {
// TODO Check if item is inside a shared folder and was converted // Check if item is inside a shared folder and was converted
if ($item['parent']) { if ($item['parent']) {
$query = \OC_DB::prepare('SELECT item_type FROM *PREFIX*sharing WHERE id = ? LIMIT 1'); $query = \OC_DB::prepare('SELECT item_type FROM *PREFIX*sharing WHERE id = ? LIMIT 1');
$result = $query->execute(array($item['parent']))->fetchRow(); $result = $query->execute(array($item['parent']))->fetchRow();
// TODO Check other parents
if (isset($result['item_type']) && $result['item_type'] = 'folder') { if (isset($result['item_type']) && $result['item_type'] = 'folder') {
return false; return false;
} }
@ -343,17 +345,8 @@ class Share {
* @return Sharing backend object * @return Sharing backend object
*/ */
private static function getBackend($itemType) { private static function getBackend($itemType) {
if (isset(self::$backends[$itemType])) { if (isset(self::$backends[$itemType]['class'])) {
return self::$backends[$itemType]; return self::$backends[$itemType]['class'];
} else if (isset(self::$backendTypes[$itemType]['class'])) {
$class = self::$backendTypes[$itemType]['class'];
if (class_exists($class)) {
self::$backends[$itemType] = new $class;
return self::$backends[$itemType];
} else {
\OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not found', \OC_Log::ERROR);
return false;
}
} }
\OC_Log::write('OCP\Share', 'Sharing backend for '.$itemType.' not found', \OC_Log::ERROR); \OC_Log::write('OCP\Share', 'Sharing backend for '.$itemType.' not found', \OC_Log::ERROR);
return false; return false;