fix rename_system_url() for the case of somebody who has no local xchan_url (was cloned from elsewhere and is not primary)

This commit is contained in:
friendica 2014-07-15 17:11:43 -07:00
parent 01491e7d61
commit 0435a08f3b
2 changed files with 22 additions and 12 deletions

View File

@ -1365,12 +1365,21 @@ function fix_system_urls($oldurl,$newurl) {
// that they can clean up their hubloc tables (this includes directories).
// It's a very expensive operation so you don't want to have to do it often or after your site gets to be large.
$r = q("select xchan.*, channel.* from xchan left join channel on channel_hash = xchan_hash where xchan_url like '%s'",
$r = q("select xchan.*, hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url like '%s'",
dbesc($oldurl . '%')
);
if($r) {
foreach($r as $rr) {
$channel = substr($rr['xchan_addr'],0,strpos($rr['xchan_addr'],'@'));
$channel_address = substr($rr['hubloc_addr'],0,strpos($rr['hubloc_addr'],'@'));
// get the associated channel. If we don't have a local channel, do nothing for this entry.
$c = q("select * from channel where channel_hash = '%s' limit 1",
dbesc($rr['hubloc_hash'])
);
if(! $c)
continue;
$parsed = @parse_url($newurl);
if(! $parsed)
@ -1387,9 +1396,13 @@ function fix_system_urls($oldurl,$newurl) {
// paths aren't going to work. You have to be at the (sub)domain root
// . (($parsed['path']) ? $parsed['path'] : '');
// The xchan_url might point to another nomadic identity clone
$replace_xchan_url = ((strpos($rr['xchan_url'],$oldurl) !== false) ? true : false);
$x = q("update xchan set xchan_addr = '%s', xchan_url = '%s', xchan_connurl = '%s', xchan_follow = '%s', xchan_connpage = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_date = '%s' where xchan_hash = '%s' limit 1",
dbesc($channel . '@' . $rhs),
dbesc(str_replace($oldurl,$newurl,$rr['xchan_url'])),
dbesc($channel_address . '@' . $rhs),
dbesc(($replace_xchan_url) ? str_replace($oldurl,$newurl,$rr['xchan_url']) : $rr['xchan_url']),
dbesc(str_replace($oldurl,$newurl,$rr['xchan_connurl'])),
dbesc(str_replace($oldurl,$newurl,$rr['xchan_follow'])),
dbesc(str_replace($oldurl,$newurl,$rr['xchan_connpage'])),
@ -1400,26 +1413,23 @@ function fix_system_urls($oldurl,$newurl) {
dbesc($rr['xchan_hash'])
);
$y = q("update hubloc set hubloc_addr = '%s', hubloc_url = '%s', hubloc_url_sig = '%s', hubloc_host = '%s', hubloc_callback = '%s' where hubloc_hash = '%s' and hubloc_url = '%s' limit 1",
dbesc($channel . '@' . $rhs),
dbesc($channel_address . '@' . $rhs),
dbesc($newurl),
dbesc(base64url_encode(rsa_sign($newurl,$rr['channel_prvkey']))),
dbesc(base64url_encode(rsa_sign($newurl,$c[0]['channel_prvkey']))),
dbesc($newhost),
dbesc($newurl . '/post'),
dbesc($rr['xchan_hash']),
dbesc($oldurl)
);
$z = q("update profile set photo = '%s', thumb = '%s' where uid = %d",
dbesc(str_replace($oldurl,$newurl,$rr['xchan_photo_l'])),
dbesc(str_replace($oldurl,$newurl,$rr['xchan_photo_m'])),
intval($rr['channel_id'])
intval($c[0]['channel_id'])
);
proc_run('php', 'include/notifier.php', 'refresh_all', $rr['channel_id']);
proc_run('php', 'include/notifier.php', 'refresh_all', $c[0]['channel_id']);
}
}
}

View File

@ -1 +1 @@
2014-07-14.736
2014-07-15.737