summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-04-07 10:46:23 -0400
committerEvan Prodromou <evan@status.net>2010-04-07 10:46:23 -0400
commit76cce8a3c5b45bd32d2107ace4d3fcbdd5da3440 (patch)
treebb9df7e2b9b5100543f99e95dbed841c73f5e513
parentae139c4ddf59b253c0cbbdf3983cf0b25088b93f (diff)
parent9ea0b0645249b7e3f4cb37ac6bc3ff8c628ad2ba (diff)
Merge branch 'master' into 0.9.x
-rw-r--r--classes/Memcached_DataObject.php3
-rw-r--r--plugins/OStatus/classes/Ostatus_profile.php38
2 files changed, 38 insertions, 3 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 8d54e1f0f..0836c2019 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -573,6 +573,9 @@ class Memcached_DataObject extends Safe_DataObject
if ($this->id) {
$id .= ':' . $this->id;
}
+ if ($message instanceof PEAR_Error) {
+ $message = $message->getMessage();
+ }
throw new ServerException("[$id] DB_DataObject error [$type]: $message");
}
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 8ba2ce0c3..e3b3daa2c 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -726,7 +726,8 @@ class Ostatus_profile extends Memcached_DataObject
*
* @param string $profile_url
* @return Ostatus_profile
- * @throws Exception
+ * @throws Exception on various error conditions
+ * @throws OStatusShadowException if this reference would obscure a local user/group
*/
public static function ensureProfileURL($profile_url, $hints=array())
@@ -813,7 +814,7 @@ class Ostatus_profile extends Memcached_DataObject
* remote profiles.
*
* @return mixed Ostatus_profile or null
- * @throws Exception for local profiles
+ * @throws OStatusShadowException for local profiles
*/
static function getFromProfileURL($profile_url)
{
@@ -836,7 +837,7 @@ class Ostatus_profile extends Memcached_DataObject
$user = User::staticGet('id', $profile->id);
if (!empty($user)) {
- throw new Exception("'$profile_url' is the profile for local user '{$user->nickname}'.");
+ throw new OStatusShadowException($profile, "'$profile_url' is the profile for local user '{$user->nickname}'.");
}
// Continue discovery; it's a remote profile
@@ -1538,6 +1539,7 @@ class Ostatus_profile extends Memcached_DataObject
* @param string $addr webfinger address
* @return Ostatus_profile
* @throws Exception on error conditions
+ * @throws OStatusShadowException if this reference would obscure a local user/group
*/
public static function ensureWebfinger($addr)
{
@@ -1616,9 +1618,18 @@ class Ostatus_profile extends Memcached_DataObject
$oprofile = self::ensureProfileURL($hints['profileurl'], $hints);
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;
+ } catch (OStatusShadowException $e) {
+ // We've ended up with a remote reference to a local user or group.
+ // @fixme ideally we should be able to say who it was so we can
+ // go back and refer to it the regular way
+ throw $e;
} catch (Exception $e) {
common_log(LOG_WARNING, "Failed creating profile from profile URL '$profileUrl': " . $e->getMessage());
// keep looking
+ //
+ // @fixme this means an error discovering from profile page
+ // may give us a corrupt entry using the webfinger URI, which
+ // will obscure the correct page-keyed profile later on.
}
}
@@ -1720,3 +1731,24 @@ class Ostatus_profile extends Memcached_DataObject
return $file;
}
}
+
+/**
+ * Exception indicating we've got a remote reference to a local user,
+ * not a remote user!
+ *
+ * If we can ue a local profile after all, it's available as $e->profile.
+ */
+class OStatusShadowException extends Exception
+{
+ public $profile;
+
+ /**
+ * @param Profile $profile
+ * @param string $message
+ */
+ function __construct($profile, $message) {
+ $this->profile = $profile;
+ parent::__construct($message);
+ }
+}
+