diff --git a/resources/sql/patches/20130607.xaccount.sql b/resources/sql/patches/20130607.xaccount.sql new file mode 100644 index 0000000000..e82523137f --- /dev/null +++ b/resources/sql/patches/20130607.xaccount.sql @@ -0,0 +1,31 @@ +TRUNCATE {$NAMESPACE}_user.user_externalaccount; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + CHANGE accountDomain accountDomain varchar(64) NOT NULL COLLATE utf8_bin; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + CHANGE displayName displayName varchar(255) COLLATE utf8_bin; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + ADD username VARCHAR(255) COLLATE utf8_bin; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + ADD realName VARCHAR(255) COLLATE utf8_bin; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + ADD email VARCHAR(255) COLLATE utf8_bin; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + ADD emailVerified BOOL NOT NULL COLLATE utf8_bin; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + ADD accountURI VARCHAR(255) COLLATE utf8_bin; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + ADD profileImagePHID VARCHAR(64) COLLATE utf8_bin; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + ADD properties LONGTEXT NOT NULL COLLATE utf8_bin; + +ALTER TABLE {$NAMESPACE}_user.user_externalaccount + ADD KEY `key_userAccounts` (userPHID); diff --git a/src/applications/metamta/receiver/PhabricatorMailReceiver.php b/src/applications/metamta/receiver/PhabricatorMailReceiver.php index 96f83d8435..d621497ec1 100644 --- a/src/applications/metamta/receiver/PhabricatorMailReceiver.php +++ b/src/applications/metamta/receiver/PhabricatorMailReceiver.php @@ -84,14 +84,17 @@ abstract class PhabricatorMailReceiver { $allow_email_users = PhabricatorEnv::getEnvConfig($email_key); if ($allow_email_users) { $xuser = id(new PhabricatorExternalAccount())->loadOneWhere( - 'accountType = %s AND accountDomain IS NULL and accountID = %s', + 'accountType = %s AND accountDomain = %s and accountID = %s', 'email', + 'self', $from); if (!$xuser) { $xuser = id(new PhabricatorExternalAccount()) ->setAccountID($from) ->setAccountType('email') + ->setAccountDomain('self') ->setDisplayName($from) + ->setEmail($from) ->save(); } return $xuser->getPhabricatorUser(); diff --git a/src/applications/people/editor/PhabricatorUserEditor.php b/src/applications/people/editor/PhabricatorUserEditor.php index af0c48ae82..6ed36f0139 100644 --- a/src/applications/people/editor/PhabricatorUserEditor.php +++ b/src/applications/people/editor/PhabricatorUserEditor.php @@ -317,6 +317,13 @@ final class PhabricatorUserEditor extends PhabricatorEditor { $oauth->delete(); } + $externals = id(new PhabricatorExternalAccount())->loadAllWhere( + 'userPHID = %s', + $user->getPHID()); + foreach ($externals as $external) { + $external->delete(); + } + $prefs = id(new PhabricatorUserPreferences())->loadAllWhere( 'userPHID = %s', $user->getPHID()); diff --git a/src/applications/people/storage/PhabricatorExternalAccount.php b/src/applications/people/storage/PhabricatorExternalAccount.php index 0f0e9ef92b..5764f87d9b 100644 --- a/src/applications/people/storage/PhabricatorExternalAccount.php +++ b/src/applications/people/storage/PhabricatorExternalAccount.php @@ -8,6 +8,13 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO { protected $accountSecret; protected $accountID; protected $displayName; + protected $username; + protected $realName; + protected $email; + protected $emailVerified = 0; + protected $accountURI; + protected $profileImagePHID; + protected $properties = array(); public function generatePHID() { return PhabricatorPHID::generateNewPHID( @@ -17,6 +24,9 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO { public function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, + self::CONFIG_SERIALIZATION => array( + 'properties' => self::SERIALIZATION_JSON, + ), ) + parent::getConfiguration(); } @@ -27,4 +37,11 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO { return $tmp_usr; } + public function save() { + if (!$this->getAccountSecret()) { + $this->setAccountSecret(Filesystem::readRandomCharacters(32)); + } + return parent::save(); + } + } diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php index 6fc7d0d8de..eb677ba048 100644 --- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php +++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php @@ -1354,6 +1354,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'type' => 'sql', 'name' => $this->getPatchPath('20130606.userxactions.sql'), ), + '20130607.xaccount.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('20130607.xaccount.sql'), + ), ); } }