Browse Source

Committing so christian can write the test.

pull/364/head
Daniel Lamb 11 years ago
parent
commit
0fc33b5e2f
  1. 87
      islandora.module

87
islandora.module

@ -812,7 +812,7 @@ function islandora_default_islandora_view_object($object) {
* *
* Includes some very basic error logging. * Includes some very basic error logging.
* *
* @param object $usr * @param object $new_user
* The user to connect as. * The user to connect as.
* @param string $url * @param string $url
* The URL to connect to. * The URL to connect to.
@ -820,30 +820,93 @@ function islandora_default_islandora_view_object($object) {
* @return IslandoraTuque * @return IslandoraTuque
* A IslandoraTuque instance * A IslandoraTuque instance
*/ */
function islandora_get_tuque_connection($usr = NULL, $url = NULL) { function islandora_get_tuque_connection($new_user = NULL, $url = NULL) {
$tuque = &drupal_static(__FUNCTION__); $tuque = &drupal_static(__FUNCTION__);
global $user; global $user;
$no_tuque_yet = !$tuque; // $user_for_tuque = NULL;
$user_is_different = ($usr && $usr->uid != $user->uid); //
// if TUQUE DOES NOT EXIST {
if ($no_tuque_yet || $user_is_different) { // if PROVIDED USER IS NOT NULL {
if (IslandoraTuque::exists()) { // MAKE TUQUE WITH PROVIDED USER
try { // }
$tuque = new IslandoraTuque($usr, $url); // else
// {
// MAKE TUQUE WITH GLOBAL USER
// }
// }
// else {
// if PROVIDED USER IS NOT NULL {
// if PROVIDED USER IS NOT TUQUE'S USER {
// MAKE TUQUE WITH PROVIDED USER
// }
// else {
// LEAVE TUQUE ALONE
// }
// }
// else {
// if GLOBAL USER IS NOT TUQUE'S USER {
// MAKE TUQUE WITH GLOBAL USER
// }
// else {
// LEAVE TUQUE ALONE
// }
// }
// }
// If tuque is NULL.
if (!$tuque) {
// If the provided user is not null, pass it along to Tuque.
if ($new_user) {
$tuque = islandora_make_tuque($new_user, $url);
}
// Otherwise give Tuque the global user.
else {
$tuque = islandora_make_tuque($user, $url);
}
}
// Else, tuque already exists. So only make it if the users are different.
else {
if ($new_user) {
// Get the name of the new user. If it's '', then it's actually
// 'anonymous' as far as Tuque is concerned.
$new_user_name = $new_user->name;
if (empty($new_user_name)) {
$new_user_name = 'anonymous';
} }
catch (Exception $e) { if ($new_user_name != $tuque->connection->username) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); $tuque = islandora_make_tuque($new_user);
} }
} }
else { else {
return NULL; // Get the name of the global user. If it's '', then it's actually
// 'anonymous' as far as Tuque is concerned.
$user_name = $user->name;
if (empty($user_name)) {
$user_name = 'anonymous';
}
if ($user->name != $tuque->connection->username) {
$tuque = islandora_make_tuque($user);
}
} }
} }
return $tuque; return $tuque;
} }
function islandora_make_tuque($user, $url) {
if (IslandoraTuque::exists()) {
try {
return new IslandoraTuque($user, $url);
}
catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
}
}
return NULL;
}
/** /**
* Loads the object from the given ID if possible. * Loads the object from the given ID if possible.
* *

Loading…
Cancel
Save