diff options
author | Mario Vavti <mario@mariovavti.com> | 2015-11-01 21:04:55 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2015-11-01 21:04:55 +0100 |
commit | 7ce3ebc46d3c0b007dd846adaa4097c69d26d0eb (patch) | |
tree | 602b9d0b04c0c09d33cdb1e32684f047e49b000e /include | |
parent | 0353b0e04f86945cb640f6e12031dd18981d5aeb (diff) | |
download | volse-hubzilla-7ce3ebc46d3c0b007dd846adaa4097c69d26d0eb.tar.gz volse-hubzilla-7ce3ebc46d3c0b007dd846adaa4097c69d26d0eb.tar.bz2 volse-hubzilla-7ce3ebc46d3c0b007dd846adaa4097c69d26d0eb.zip |
make sure we only have one profile photo for a cloned channel
Diffstat (limited to 'include')
-rw-r--r-- | include/photo/photo_driver.php | 7 | ||||
-rw-r--r-- | include/zot.php | 35 |
2 files changed, 26 insertions, 16 deletions
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index e980a96e1..285cbc8fb 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -734,6 +734,11 @@ function import_channel_photo($photo,$type,$aid,$uid) { $photo_failure = true; } - return(($photo_failure)? false : true); + //return(($photo_failure)? false : true); + + if($photo_failure) + return false; + else + return $hash; } diff --git a/include/zot.php b/include/zot.php index 73c7460d3..ed4bdc264 100644 --- a/include/zot.php +++ b/include/zot.php @@ -815,28 +815,33 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { $ph = z_fetch_url($arr['photo'], true); if ($ph['success']) { - // unless proven otherwise - $is_default_profile = 1; + $hash = import_channel_photo($ph['body'], $arr['photo_mimetype'], $local[0]['channel_account_id'], $local[0]['channel_id']); - $profile = q("select is_default from profile where aid = %d and uid = %d limit 1", - intval($local[0]['channel_account_id']), - intval($local[0]['channel_id']) - ); - if($profile) { - if(! intval($profile[0]['is_default'])) - $is_default_profile = 0; - } + if($hash) { + // unless proven otherwise + $is_default_profile = 1; - if($is_default_profile) { - q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND aid = %d AND uid = %d", - intval(PHOTO_NORMAL), - intval(PHOTO_PROFILE), + $profile = q("select is_default from profile where aid = %d and uid = %d limit 1", intval($local[0]['channel_account_id']), intval($local[0]['channel_id']) ); + if($profile) { + if(! intval($profile[0]['is_default'])) + $is_default_profile = 0; + } + + // If setting for the default profile, unset the profile photo flag from any other photos I own + if($is_default_profile) { + q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND resource_id != '%s' AND aid = %d AND uid = %d", + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE), + dbesc($hash), + intval($local[0]['channel_account_id']), + intval($local[0]['channel_id']) + ); + } } - import_channel_photo($ph['body'], $arr['photo_mimetype'], $local[0]['channel_account_id'],$local[0]['channel_id']); // reset the names in case they got messed up when we had a bug in this function $photos = array( z_root() . '/photo/profile/l/' . $local[0]['channel_id'], |