mirror of
https://github.com/friendica/friendica
synced 2024-12-23 12:40:17 +00:00
Diaspora: Support account migration
This commit is contained in:
parent
6a7b3f19ae
commit
09020192d6
4 changed files with 72 additions and 20 deletions
|
@ -508,6 +508,9 @@ function delivery_run(&$argv, &$argc){
|
||||||
logger('diaspora retract: '.$loc);
|
logger('diaspora retract: '.$loc);
|
||||||
Diaspora::send_retraction($target_item,$owner,$contact,$public_message);
|
Diaspora::send_retraction($target_item,$owner,$contact,$public_message);
|
||||||
break;
|
break;
|
||||||
|
} elseif ($relocate) {
|
||||||
|
Diaspora::sendAccountMigration($owner, $uid);
|
||||||
|
break;
|
||||||
} elseif ($followup) {
|
} elseif ($followup) {
|
||||||
// send comments and likes to owner to relay
|
// send comments and likes to owner to relay
|
||||||
logger('diaspora followup: '.$loc);
|
logger('diaspora followup: '.$loc);
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Core\PConfig;
|
||||||
|
|
||||||
require_once 'include/items.php';
|
require_once 'include/items.php';
|
||||||
require_once 'include/bb2diaspora.php';
|
require_once 'include/bb2diaspora.php';
|
||||||
|
@ -2958,6 +2959,31 @@ class Diaspora {
|
||||||
return $return_code;
|
return $return_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sends an "unshare"
|
||||||
|
*
|
||||||
|
* @param array $owner the array of the item owner
|
||||||
|
* @param array $contact Target of the communication
|
||||||
|
*
|
||||||
|
* @return int The result of the transmission
|
||||||
|
*/
|
||||||
|
public static function sendAccountMigration($owner, $uid) {
|
||||||
|
|
||||||
|
$old_handle = PConfig::get($uid, 'system', 'previous_addr');
|
||||||
|
$profile = self::createProfileData($uid);
|
||||||
|
|
||||||
|
$signed_text = 'AccountMigration:'.$old_handle.':'.$profile['author'];
|
||||||
|
$signature = rsa_sign($signed_text, $owner["uprvkey"], "sha256");
|
||||||
|
|
||||||
|
$message = array("author" => $old_handle,
|
||||||
|
"profile" => $profile,
|
||||||
|
"signature" => $signature);
|
||||||
|
|
||||||
|
logger("Send account migration ".print_r($message, true), LOGGER_DEBUG);
|
||||||
|
|
||||||
|
return self::build_and_transmit($owner, $contact, "account_migration", $message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sends a "share" message
|
* @brief Sends a "share" message
|
||||||
*
|
*
|
||||||
|
@ -3648,25 +3674,13 @@ class Diaspora {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sends profile data
|
* @brief Create profile data
|
||||||
*
|
*
|
||||||
* @param int $uid The user id
|
* @param int $uid The user id
|
||||||
|
*
|
||||||
|
* @return array The profile data
|
||||||
*/
|
*/
|
||||||
public static function send_profile($uid, $recips = false) {
|
private static function createProfileData($uid) {
|
||||||
|
|
||||||
if (!$uid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!$recips)
|
|
||||||
$recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'
|
|
||||||
AND `uid` = %d AND `rel` != %d",
|
|
||||||
dbesc(NETWORK_DIASPORA),
|
|
||||||
intval($uid),
|
|
||||||
intval(CONTACT_IS_SHARING)
|
|
||||||
);
|
|
||||||
if (!$recips)
|
|
||||||
return;
|
|
||||||
|
|
||||||
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.*, `user`.`prvkey` AS `uprvkey`, `contact`.`addr`
|
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.*, `user`.`prvkey` AS `uprvkey`, `contact`.`addr`
|
||||||
FROM `profile`
|
FROM `profile`
|
||||||
INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
|
INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
|
||||||
|
@ -3675,8 +3689,9 @@ class Diaspora {
|
||||||
intval($uid)
|
intval($uid)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$r)
|
if (!$r) {
|
||||||
return;
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
$profile = $r[0];
|
$profile = $r[0];
|
||||||
|
|
||||||
|
@ -3714,7 +3729,7 @@ class Diaspora {
|
||||||
$tags = trim($tags);
|
$tags = trim($tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = array("author" => $handle,
|
return array("author" => $handle,
|
||||||
"first_name" => $first,
|
"first_name" => $first,
|
||||||
"last_name" => $last,
|
"last_name" => $last,
|
||||||
"image_url" => $large,
|
"image_url" => $large,
|
||||||
|
@ -3727,6 +3742,29 @@ class Diaspora {
|
||||||
"searchable" => $searchable,
|
"searchable" => $searchable,
|
||||||
"nsfw" => "false",
|
"nsfw" => "false",
|
||||||
"tag_string" => $tags);
|
"tag_string" => $tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sends profile data
|
||||||
|
*
|
||||||
|
* @param int $uid The user id
|
||||||
|
*/
|
||||||
|
public static function send_profile($uid, $recips = false) {
|
||||||
|
|
||||||
|
if (!$uid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!$recips)
|
||||||
|
$recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'
|
||||||
|
AND `uid` = %d AND `rel` != %d",
|
||||||
|
dbesc(NETWORK_DIASPORA),
|
||||||
|
intval($uid),
|
||||||
|
intval(CONTACT_IS_SHARING)
|
||||||
|
);
|
||||||
|
if (!$recips)
|
||||||
|
return;
|
||||||
|
|
||||||
|
$message = self::createProfileData($uid);
|
||||||
|
|
||||||
foreach ($recips as $recip) {
|
foreach ($recips as $recip) {
|
||||||
logger("Send updated profile data for user ".$uid." to contact ".$recip["id"], LOGGER_DEBUG);
|
logger("Send updated profile data for user ".$uid." to contact ".$recip["id"], LOGGER_DEBUG);
|
||||||
|
|
|
@ -149,7 +149,8 @@ function notifier_run(&$argv, &$argc){
|
||||||
$relocate = true;
|
$relocate = true;
|
||||||
$uid = $item_id;
|
$uid = $item_id;
|
||||||
|
|
||||||
$recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
|
$recipients_relocate = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND `network` IN ('%s', '%s')",
|
||||||
|
intval($uid), NETWORK_DFRN, NETWORK_DIASPORA);
|
||||||
} else {
|
} else {
|
||||||
// find ancestors
|
// find ancestors
|
||||||
$r = q("SELECT * FROM `item` WHERE `id` = %d AND visible = 1 AND moderated = 0 LIMIT 1",
|
$r = q("SELECT * FROM `item` WHERE `id` = %d AND visible = 1 AND moderated = 0 LIMIT 1",
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
|
use Friendica\Core\PConfig;
|
||||||
|
|
||||||
require_once("include/Photo.php");
|
require_once("include/Photo.php");
|
||||||
define("IMPORT_DEBUG", False);
|
define("IMPORT_DEBUG", False);
|
||||||
|
@ -124,6 +125,12 @@ function import_account(App $a, $file) {
|
||||||
$oldaddr = str_replace('http://', '@', normalise_link($oldbaseurl));
|
$oldaddr = str_replace('http://', '@', normalise_link($oldbaseurl));
|
||||||
$newaddr = str_replace('http://', '@', normalise_link($newbaseurl));
|
$newaddr = str_replace('http://', '@', normalise_link($newbaseurl));
|
||||||
|
|
||||||
|
if (!empty($account['profile']['addr'])) {
|
||||||
|
$old_handle = $account['profile']['addr'];
|
||||||
|
} else {
|
||||||
|
$old_handle = $account['user']['nickname'].$oldaddr;
|
||||||
|
}
|
||||||
|
|
||||||
$olduid = $account['user']['uid'];
|
$olduid = $account['user']['uid'];
|
||||||
|
|
||||||
unset($account['user']['uid']);
|
unset($account['user']['uid']);
|
||||||
|
@ -146,6 +153,8 @@ function import_account(App $a, $file) {
|
||||||
$newuid = last_insert_id();
|
$newuid = last_insert_id();
|
||||||
//~ $newuid = 1;
|
//~ $newuid = 1;
|
||||||
|
|
||||||
|
PConfig::set($newuid, 'system', 'previous_addr', $old_handle);
|
||||||
|
|
||||||
// Generate a new guid for the account. Otherwise there will be problems with diaspora
|
// Generate a new guid for the account. Otherwise there will be problems with diaspora
|
||||||
q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d",
|
q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d",
|
||||||
dbesc(generate_user_guid()), intval($newuid));
|
dbesc(generate_user_guid()), intval($newuid));
|
||||||
|
@ -183,6 +192,7 @@ function import_account(App $a, $file) {
|
||||||
|
|
||||||
switch ($contact['network']) {
|
switch ($contact['network']) {
|
||||||
case NETWORK_DFRN:
|
case NETWORK_DFRN:
|
||||||
|
case NETWORK_DIASPORA:
|
||||||
// send relocate message (below)
|
// send relocate message (below)
|
||||||
break;
|
break;
|
||||||
case NETWORK_ZOT:
|
case NETWORK_ZOT:
|
||||||
|
|
Loading…
Reference in a new issue