|
|
|
@ -812,7 +812,7 @@ function islandora_default_islandora_view_object($object) {
|
|
|
|
|
* |
|
|
|
|
* Includes some very basic error logging. |
|
|
|
|
* |
|
|
|
|
* @param object $usr |
|
|
|
|
* @param object $new_user |
|
|
|
|
* The user to connect as. |
|
|
|
|
* @param string $url |
|
|
|
|
* The URL to connect to. |
|
|
|
@ -820,30 +820,93 @@ function islandora_default_islandora_view_object($object) {
|
|
|
|
|
* @return IslandoraTuque |
|
|
|
|
* 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__); |
|
|
|
|
|
|
|
|
|
global $user; |
|
|
|
|
|
|
|
|
|
$no_tuque_yet = !$tuque; |
|
|
|
|
$user_is_different = ($usr && $usr->uid != $user->uid); |
|
|
|
|
|
|
|
|
|
if ($no_tuque_yet || $user_is_different) { |
|
|
|
|
if (IslandoraTuque::exists()) { |
|
|
|
|
try { |
|
|
|
|
$tuque = new IslandoraTuque($usr, $url); |
|
|
|
|
// $user_for_tuque = NULL; |
|
|
|
|
// |
|
|
|
|
// if TUQUE DOES NOT EXIST { |
|
|
|
|
// if PROVIDED USER IS NOT NULL { |
|
|
|
|
// MAKE TUQUE WITH PROVIDED USER |
|
|
|
|
// } |
|
|
|
|
// 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) { |
|
|
|
|
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); |
|
|
|
|
if ($new_user_name != $tuque->connection->username) { |
|
|
|
|
$tuque = islandora_make_tuque($new_user); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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. |
|
|
|
|
* |
|
|
|
|