mirror of
https://github.com/friendica/friendica
synced 2024-12-22 18:00:16 +00:00
New photo field "photo-type" as preparation for banners
This commit is contained in:
parent
86947b0997
commit
13827edd2c
15 changed files with 80 additions and 60 deletions
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2021.12-dev (Siberian Iris)
|
||||
-- DB_UPDATE_VERSION 1437
|
||||
-- DB_UPDATE_VERSION 1438
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -970,6 +970,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
|
|||
`title` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||
`desc` text COMMENT '',
|
||||
`album` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the album to which the photo belongs',
|
||||
`photo-type` tinyint unsigned COMMENT 'User avatar, contact avatar or default',
|
||||
`filename` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||
`type` varchar(30) NOT NULL DEFAULT 'image/jpeg',
|
||||
`height` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
|
||||
|
@ -993,6 +994,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
|
|||
INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`),
|
||||
INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`,`created`),
|
||||
INDEX `resource-id` (`resource-id`),
|
||||
INDEX `uid_photo-type` (`uid`,`photo-type`),
|
||||
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE RESTRICT,
|
||||
FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
|
||||
|
|
|
@ -19,6 +19,7 @@ Fields
|
|||
| title | | varchar(255) | NO | | | |
|
||||
| desc | | text | YES | | NULL | |
|
||||
| album | The name of the album to which the photo belongs | varchar(255) | NO | | | |
|
||||
| photo-type | User avatar, contact avatar or default | tinyint unsigned | YES | | NULL | |
|
||||
| filename | | varchar(255) | NO | | | |
|
||||
| type | | varchar(30) | NO | | image/jpeg | |
|
||||
| height | | smallint unsigned | NO | | 0 | |
|
||||
|
@ -48,6 +49,7 @@ Indexes
|
|||
| uid_album_scale_created | uid, album(32), scale, created |
|
||||
| uid_album_resource-id_created | uid, album(32), resource-id, created |
|
||||
| resource-id | resource-id |
|
||||
| uid_photo-type | uid, photo-type |
|
||||
|
||||
Foreign Keys
|
||||
------------
|
||||
|
|
|
@ -4115,8 +4115,8 @@ function api_fr_photos_list($type)
|
|||
$r = DBA::toArray(DBA::p(
|
||||
"SELECT `resource-id`, MAX(scale) AS `scale`, `album`, `filename`, `type`, MAX(`created`) AS `created`,
|
||||
MAX(`edited`) AS `edited`, MAX(`desc`) AS `desc` FROM `photo`
|
||||
WHERE `uid` = ? AND NOT `album` IN (?, ?) GROUP BY `resource-id`, `album`, `filename`, `type`",
|
||||
local_user(), Photo::CONTACT_PHOTOS, DI::l10n()->t(Photo::CONTACT_PHOTOS)
|
||||
WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) GROUP BY `resource-id`, `album`, `filename`, `type`",
|
||||
local_user(), Photo::CONTACT_AVATAR, Photo::CONTACT_BANNER
|
||||
));
|
||||
$typetoext = [
|
||||
'image/jpeg' => 'jpg',
|
||||
|
@ -4212,7 +4212,7 @@ function api_fr_photo_create_update($type)
|
|||
// now let's upload the new media in create-mode
|
||||
if ($mode == "create") {
|
||||
$media = $_FILES['media'];
|
||||
$data = save_media_to_database("photo", $media, $type, $album, trim($allow_cid), trim($deny_cid), trim($allow_gid), trim($deny_gid), $desc, $visibility);
|
||||
$data = save_media_to_database("photo", $media, $type, $album, trim($allow_cid), trim($deny_cid), trim($allow_gid), trim($deny_gid), $desc, Photo::DEFAULT, $visibility);
|
||||
|
||||
// return success of updating or error message
|
||||
if (!is_null($data)) {
|
||||
|
@ -4265,7 +4265,7 @@ function api_fr_photo_create_update($type)
|
|||
if (!empty($_FILES['media'])) {
|
||||
$nothingtodo = false;
|
||||
$media = $_FILES['media'];
|
||||
$data = save_media_to_database("photo", $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, 0, $visibility, $photo_id);
|
||||
$data = save_media_to_database("photo", $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, Photo::DEFAULT, $visibility, $photo_id);
|
||||
if (!is_null($data)) {
|
||||
return api_format_data("photo_update", $type, $data);
|
||||
}
|
||||
|
@ -4408,7 +4408,7 @@ function api_account_update_profile_image($type)
|
|||
$media = $_FILES['media'];
|
||||
}
|
||||
// save new profile image
|
||||
$data = save_media_to_database("profileimage", $media, $type, DI::l10n()->t('Profile Photos'), "", "", "", "", "", $is_default_profile);
|
||||
$data = save_media_to_database("profileimage", $media, $type, DI::l10n()->t('Profile Photos'), "", "", "", "", "", Photo::USER_AVATAR);
|
||||
|
||||
// get filetype
|
||||
if (is_array($media['type'])) {
|
||||
|
@ -4427,7 +4427,7 @@ function api_account_update_profile_image($type)
|
|||
// change specified profile or all profiles to the new resource-id
|
||||
if ($is_default_profile) {
|
||||
$condition = ["`profile` AND `resource-id` != ? AND `uid` = ?", $data['photo']['id'], api_user()];
|
||||
Photo::update(['profile' => false], $condition);
|
||||
Photo::update(['profile' => false, 'photo-type' => Photo::DEFAULT], $condition);
|
||||
} else {
|
||||
$fields = ['photo' => DI::baseUrl() . '/photo/' . $data['photo']['id'] . '-4.' . $fileext,
|
||||
'thumb' => DI::baseUrl() . '/photo/' . $data['photo']['id'] . '-5.' . $fileext];
|
||||
|
@ -4534,7 +4534,7 @@ function check_acl_input($acl_string)
|
|||
* @param string $allow_gid
|
||||
* @param string $deny_gid
|
||||
* @param string $desc
|
||||
* @param integer $profile
|
||||
* @param integer $phototype
|
||||
* @param boolean $visibility
|
||||
* @param string $photo_id
|
||||
* @return array
|
||||
|
@ -4545,7 +4545,7 @@ function check_acl_input($acl_string)
|
|||
* @throws NotFoundException
|
||||
* @throws UnauthorizedException
|
||||
*/
|
||||
function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, $profile = 0, $visibility = false, $photo_id = null)
|
||||
function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, $phototype = 0, $visibility = false, $photo_id = null)
|
||||
{
|
||||
$visitor = 0;
|
||||
$src = "";
|
||||
|
@ -4623,13 +4623,13 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
// upload normal image (scales 0, 1, 2)
|
||||
logger::info("photo upload: starting new photo upload");
|
||||
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 0, Photo::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (!$r) {
|
||||
logger::notice("photo upload: image upload with scale 0 (original size) failed");
|
||||
}
|
||||
if ($width > 640 || $height > 640) {
|
||||
$Image->scaleDown(640);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 1, Photo::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (!$r) {
|
||||
logger::notice("photo upload: image upload with scale 1 (640x640) failed");
|
||||
}
|
||||
|
@ -4637,7 +4637,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
|
||||
if ($width > 320 || $height > 320) {
|
||||
$Image->scaleDown(320);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 2, Photo::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (!$r) {
|
||||
logger::notice("photo upload: image upload with scale 2 (320x320) failed");
|
||||
}
|
||||
|
@ -4649,7 +4649,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
|
||||
if ($width > 300 || $height > 300) {
|
||||
$Image->scaleDown(300);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 4, $phototype, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (!$r) {
|
||||
logger::notice("photo upload: profile image upload with scale 4 (300x300) failed");
|
||||
}
|
||||
|
@ -4657,7 +4657,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
|
||||
if ($width > 80 || $height > 80) {
|
||||
$Image->scaleDown(80);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 5, $phototype, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (!$r) {
|
||||
logger::notice("photo upload: profile image upload with scale 5 (80x80) failed");
|
||||
}
|
||||
|
@ -4665,7 +4665,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
|
|||
|
||||
if ($width > 48 || $height > 48) {
|
||||
$Image->scaleDown(48);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 6, $phototype, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (!$r) {
|
||||
logger::notice("photo upload: profile image upload with scale 6 (48x48) failed");
|
||||
}
|
||||
|
|
|
@ -46,10 +46,10 @@ function fbrowser_content(App $a)
|
|||
$sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
|
||||
|
||||
if (DI::args()->getArgc() == 2) {
|
||||
$photos = DBA::toArray(DBA::p("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = ? AND NOT `album` IN (?, ?)",
|
||||
$photos = DBA::toArray(DBA::p("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?)",
|
||||
local_user(),
|
||||
Photo::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(Photo::CONTACT_PHOTOS)
|
||||
Photo::CONTACT_AVATAR,
|
||||
Photo::CONTACT_BANNER
|
||||
));
|
||||
|
||||
$albums = array_column($photos, 'album');
|
||||
|
@ -64,11 +64,11 @@ function fbrowser_content(App $a)
|
|||
|
||||
$r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
|
||||
min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
|
||||
FROM `photo` WHERE `uid` = ? $sql_extra AND NOT `album` IN (?, ?)
|
||||
FROM `photo` WHERE `uid` = ? $sql_extra AND NOT `photo-type` IN (?, ?)
|
||||
GROUP BY `resource-id` $sql_extra2",
|
||||
local_user(),
|
||||
Photo::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(Photo::CONTACT_PHOTOS)
|
||||
Photo::CONTACT_AVATAR,
|
||||
Photo::CONTACT_BANNER
|
||||
));
|
||||
|
||||
function _map_files1($rr)
|
||||
|
|
|
@ -725,7 +725,7 @@ function photos_post(App $a)
|
|||
|
||||
$resource_id = Photo::newResource();
|
||||
|
||||
$r = Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
|
||||
$r = Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0 , Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
|
||||
|
||||
if (!$r) {
|
||||
Logger::info('image store failed');
|
||||
|
@ -735,13 +735,13 @@ function photos_post(App $a)
|
|||
|
||||
if ($width > 640 || $height > 640) {
|
||||
$image->scaleDown(640);
|
||||
Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
|
||||
Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
|
||||
$smallest = 1;
|
||||
}
|
||||
|
||||
if ($width > 320 || $height > 320) {
|
||||
$image->scaleDown(320);
|
||||
Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
|
||||
Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
|
||||
$smallest = 2;
|
||||
}
|
||||
|
||||
|
@ -1546,11 +1546,11 @@ function photos_content(App $a)
|
|||
// Default - show recent photos with upload link (if applicable)
|
||||
//$o = '';
|
||||
$total = 0;
|
||||
$r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND NOT `album` IN (?, ?)
|
||||
$r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?)
|
||||
$sql_extra GROUP BY `resource-id`",
|
||||
$user['uid'],
|
||||
Photo::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(Photo::CONTACT_PHOTOS)
|
||||
Photo::CONTACT_AVATAR,
|
||||
Photo::CONTACT_BANNER
|
||||
));
|
||||
if (DBA::isResult($r)) {
|
||||
$total = count($r);
|
||||
|
@ -1561,11 +1561,11 @@ function photos_content(App $a)
|
|||
$r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
|
||||
ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
|
||||
ANY_VALUE(`created`) AS `created` FROM `photo`
|
||||
WHERE `uid` = ? AND NOT `album` IN (?, ?)
|
||||
WHERE `uid` = ? AND NOT `photo-type` IN (?, ?)
|
||||
$sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT ? , ?",
|
||||
$user['uid'],
|
||||
Photo::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(Photo::CONTACT_PHOTOS),
|
||||
Photo::CONTACT_AVATAR,
|
||||
Photo::CONTACT_BANNER,
|
||||
$pager->getStart(),
|
||||
$pager->getItemsPerPage()
|
||||
));
|
||||
|
|
|
@ -226,7 +226,7 @@ function wall_upload_post(App $a, $desktopmode = true)
|
|||
|
||||
$defperm = '<' . $default_cid . '>';
|
||||
|
||||
$r = Photo::store($Image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0, 0, $defperm);
|
||||
$r = Photo::store($Image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0, Photo::DEFAULT, $defperm);
|
||||
|
||||
if (!$r) {
|
||||
$msg = DI::l10n()->t('Image upload failed.');
|
||||
|
@ -240,7 +240,7 @@ function wall_upload_post(App $a, $desktopmode = true)
|
|||
|
||||
if ($width > 640 || $height > 640) {
|
||||
$Image->scaleDown(640);
|
||||
$r = Photo::store($Image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, 0, $defperm);
|
||||
$r = Photo::store($Image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, Photo::DEFAULT, $defperm);
|
||||
if ($r) {
|
||||
$smallest = 1;
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ function wall_upload_post(App $a, $desktopmode = true)
|
|||
|
||||
if ($width > 320 || $height > 320) {
|
||||
$Image->scaleDown(320);
|
||||
$r = Photo::store($Image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, 0, $defperm);
|
||||
$r = Photo::store($Image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, Photo::DEFAULT, $defperm);
|
||||
if ($r && ($smallest == 0)) {
|
||||
$smallest = 2;
|
||||
}
|
||||
|
|
|
@ -1933,7 +1933,7 @@ class Contact
|
|||
|
||||
if (!empty($cids)) {
|
||||
// Delete possibly existing cached user contact avatars
|
||||
Photo::delete(['uid' => $uids, 'contact-id' => $cids, 'album' => Photo::CONTACT_PHOTOS]);
|
||||
Photo::delete(['uid' => $uids, 'contact-id' => $cids, 'photo-type' => Photo::CONTACT_AVATAR]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,12 @@ class Photo
|
|||
{
|
||||
const CONTACT_PHOTOS = 'Contact Photos';
|
||||
|
||||
const DEFAULT = 0;
|
||||
const USER_AVATAR = 10;
|
||||
const USER_BANNER = 11;
|
||||
const CONTACT_AVATAR = 20;
|
||||
const CONTACT_BANNER = 21;
|
||||
|
||||
/**
|
||||
* Select rows from the photo table and returns them as array
|
||||
*
|
||||
|
@ -322,7 +328,7 @@ class Photo
|
|||
* @return boolean True on success
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function store(Image $Image, $uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = "", $allow_gid = "", $deny_cid = "", $deny_gid = "", $desc = "")
|
||||
public static function store(Image $Image, $uid, $cid, $rid, $filename, $album, $scale, $type = self::DEFAULT, $allow_cid = "", $allow_gid = "", $deny_cid = "", $deny_gid = "", $desc = "")
|
||||
{
|
||||
$photo = self::selectFirst(["guid"], ["`resource-id` = ? AND `guid` != ?", $rid, ""]);
|
||||
if (DBA::isResult($photo)) {
|
||||
|
@ -372,7 +378,8 @@ class Photo
|
|||
"datasize" => strlen($Image->asString()),
|
||||
"data" => $data,
|
||||
"scale" => $scale,
|
||||
"profile" => $profile,
|
||||
"photo-type" => $type,
|
||||
"profile" => $type == self::USER_AVATAR,
|
||||
"allow_cid" => $allow_cid,
|
||||
"allow_gid" => $allow_gid,
|
||||
"deny_cid" => $deny_cid,
|
||||
|
@ -476,7 +483,7 @@ class Photo
|
|||
$micro = "";
|
||||
|
||||
$photo = DBA::selectFirst(
|
||||
"photo", ["resource-id"], ["uid" => $uid, "contact-id" => $cid, "scale" => 4, "album" => self::CONTACT_PHOTOS]
|
||||
"photo", ["resource-id"], ["uid" => $uid, "contact-id" => $cid, "scale" => 4, "photo-type" => self::CONTACT_AVATAR]
|
||||
);
|
||||
if (!empty($photo['resource-id'])) {
|
||||
$resource_id = $photo["resource-id"];
|
||||
|
@ -529,7 +536,7 @@ class Photo
|
|||
Logger::info('Avatar is resized', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'type' => $Image->getType()]);
|
||||
}
|
||||
|
||||
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 4);
|
||||
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 4, self::CONTACT_AVATAR);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
|
@ -537,7 +544,7 @@ class Photo
|
|||
|
||||
$Image->scaleDown(80);
|
||||
|
||||
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 5);
|
||||
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 5, self::CONTACT_AVATAR);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
|
@ -545,7 +552,7 @@ class Photo
|
|||
|
||||
$Image->scaleDown(48);
|
||||
|
||||
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 6);
|
||||
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 6, self::CONTACT_AVATAR);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
|
@ -651,20 +658,20 @@ class Photo
|
|||
// At this time we just store the data in the cache
|
||||
$albums = DBA::toArray(DBA::p("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, ANY_VALUE(`created`) AS `created`
|
||||
FROM `photo`
|
||||
WHERE `uid` = ? AND NOT `album` IN (?, ?) $sql_extra
|
||||
WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) $sql_extra
|
||||
GROUP BY `album` ORDER BY `created` DESC",
|
||||
$uid,
|
||||
self::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(self::CONTACT_PHOTOS)
|
||||
self::CONTACT_AVATAR,
|
||||
self::CONTACT_BANNER
|
||||
));
|
||||
} else {
|
||||
// This query doesn't do the count and is much faster
|
||||
$albums = DBA::toArray(DBA::p("SELECT DISTINCT(`album`), '' AS `total`
|
||||
FROM `photo` USE INDEX (`uid_album_scale_created`)
|
||||
WHERE `uid` = ? AND NOT `album` IN (?, ?) $sql_extra",
|
||||
WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) $sql_extra",
|
||||
$uid,
|
||||
self::CONTACT_PHOTOS,
|
||||
DI::l10n()->t(self::CONTACT_PHOTOS)
|
||||
self::CONTACT_AVATAR,
|
||||
self::CONTACT_BANNER
|
||||
));
|
||||
}
|
||||
DI::cache()->set($key, $albums, Duration::DAY);
|
||||
|
@ -998,7 +1005,7 @@ class Photo
|
|||
|
||||
$smallest = 0;
|
||||
|
||||
$r = Photo::store($Image, $user['uid'], 0, $resource_id, $filename, $album, 0, 0, $defperm);
|
||||
$r = Photo::store($Image, $user['uid'], 0, $resource_id, $filename, $album, 0, self::DEFAULT, $defperm);
|
||||
if (!$r) {
|
||||
Logger::notice('Photo could not be stored');
|
||||
return [];
|
||||
|
@ -1006,7 +1013,7 @@ class Photo
|
|||
|
||||
if ($width > 640 || $height > 640) {
|
||||
$Image->scaleDown(640);
|
||||
$r = Photo::store($Image, $user['uid'], 0, $resource_id, $filename, $album, 1, 0, $defperm);
|
||||
$r = Photo::store($Image, $user['uid'], 0, $resource_id, $filename, $album, 1, self::DEFAULT, $defperm);
|
||||
if ($r) {
|
||||
$smallest = 1;
|
||||
}
|
||||
|
@ -1014,7 +1021,7 @@ class Photo
|
|||
|
||||
if ($width > 320 || $height > 320) {
|
||||
$Image->scaleDown(320);
|
||||
$r = Photo::store($Image, $user['uid'], 0, $resource_id, $filename, $album, 2, 0, $defperm);
|
||||
$r = Photo::store($Image, $user['uid'], 0, $resource_id, $filename, $album, 2, self::DEFAULT, $defperm);
|
||||
if ($r && ($smallest == 0)) {
|
||||
$smallest = 2;
|
||||
}
|
||||
|
|
|
@ -1184,7 +1184,7 @@ class User
|
|||
}
|
||||
|
||||
if (!$photo_failure) {
|
||||
Photo::update(['profile' => 1], ['resource-id' => $resource_id]);
|
||||
Photo::update(['profile' => true, 'photo-type' => Photo::USER_AVATAR], ['resource-id' => $resource_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ class Crop extends BaseSettings
|
|||
$base_image['filename'],
|
||||
DI::l10n()->t('Profile Photos'),
|
||||
4,
|
||||
1
|
||||
Photo::USER_AVATAR
|
||||
);
|
||||
if ($r === false) {
|
||||
notice(DI::l10n()->t('Image size reduction [%s] failed.', '300'));
|
||||
|
@ -116,7 +116,7 @@ class Crop extends BaseSettings
|
|||
$base_image['filename'],
|
||||
DI::l10n()->t('Profile Photos'),
|
||||
5,
|
||||
1
|
||||
Photo::USER_AVATAR
|
||||
);
|
||||
if ($r === false) {
|
||||
notice(DI::l10n()->t('Image size reduction [%s] failed.', '80'));
|
||||
|
@ -132,7 +132,7 @@ class Crop extends BaseSettings
|
|||
$base_image['filename'],
|
||||
DI::l10n()->t('Profile Photos'),
|
||||
6,
|
||||
1
|
||||
Photo::USER_AVATAR
|
||||
);
|
||||
if ($r === false) {
|
||||
notice(DI::l10n()->t('Image size reduction [%s] failed.', '48'));
|
||||
|
|
|
@ -59,7 +59,7 @@ class Expire
|
|||
|
||||
Logger::notice('start expiry');
|
||||
|
||||
$r = DBA::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0");
|
||||
$r = DBA::select('user', ['uid', 'username'], ["`expire` != ?", 0]);
|
||||
while ($row = DBA::fetch($r)) {
|
||||
Logger::info('Calling expiry', ['user' => $row['uid'], 'username' => $row['username']]);
|
||||
Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
|
||||
|
|
|
@ -36,7 +36,7 @@ class ExpireConversations
|
|||
return;
|
||||
}
|
||||
|
||||
DBA::p("DELETE FROM `conversation` WHERE `received` < UTC_TIMESTAMP() - INTERVAL ? DAY", $days);
|
||||
DBA::e("DELETE FROM `conversation` WHERE `received` < UTC_TIMESTAMP() - INTERVAL ? DAY", $days);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class RemoveUnusedAvatars
|
|||
$contacts = DBA::select('contact', ['id'], $condition);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
Contact::update(['photo' => '', 'thumb' => '', 'micro' => ''], ['id' => $contact['id']]);
|
||||
Photo::delete(['contact-id' => $contact['id'], 'album' => Photo::CONTACT_PHOTOS]);
|
||||
Photo::delete(['contact-id' => $contact['id'], 'photo-type' => [Photo::CONTACT_AVATAR, Photo::CONTACT_BANNER]]);
|
||||
if ((++$count % 1000) == 0) {
|
||||
if (!Worker::isInMaintenanceWindow()) {
|
||||
Logger::notice('We are outside of the maintenance window, quitting');
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1437);
|
||||
define('DB_UPDATE_VERSION', 1438);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -1023,6 +1023,7 @@ return [
|
|||
"title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"desc" => ["type" => "text", "comment" => ""],
|
||||
"album" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "The name of the album to which the photo belongs"],
|
||||
"photo-type" => ["type" => "tinyint unsigned", "comment" => "User avatar, contact avatar or default"],
|
||||
"filename" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"type" => ["type" => "varchar(30)", "not null" => "1", "default" => "image/jpeg"],
|
||||
"height" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
|
||||
|
@ -1048,6 +1049,7 @@ return [
|
|||
"uid_album_scale_created" => ["uid", "album(32)", "scale", "created"],
|
||||
"uid_album_resource-id_created" => ["uid", "album(32)", "resource-id", "created"],
|
||||
"resource-id" => ["resource-id"],
|
||||
"uid_photo-type" => ["uid", "photo-type"],
|
||||
]
|
||||
],
|
||||
"post" => [
|
||||
|
|
11
update.php
11
update.php
|
@ -192,8 +192,8 @@ function update_1330()
|
|||
}
|
||||
|
||||
// Update attachments and photos
|
||||
if (!DBA::p("UPDATE `photo` SET `photo`.`backend-class` = SUBSTR(`photo`.`backend-class`, 25) WHERE `photo`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'") ||
|
||||
!DBA::p("UPDATE `attach` SET `attach`.`backend-class` = SUBSTR(`attach`.`backend-class`, 25) WHERE `attach`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'")) {
|
||||
if (!DBA::e("UPDATE `photo` SET `photo`.`backend-class` = SUBSTR(`photo`.`backend-class`, 25) WHERE `photo`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'") ||
|
||||
!DBA::e("UPDATE `attach` SET `attach`.`backend-class` = SUBSTR(`attach`.`backend-class`, 25) WHERE `attach`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'")) {
|
||||
return Update::FAILED;
|
||||
};
|
||||
|
||||
|
@ -1006,3 +1006,10 @@ function update_1435()
|
|||
Contact\User::insertForContactArray($contact);
|
||||
}
|
||||
}
|
||||
|
||||
function update_1438()
|
||||
{
|
||||
DBA::update('photo', ['photo-type' => Photo::USER_AVATAR], ['profile' => true]);
|
||||
DBA::update('photo', ['photo-type' => Photo::CONTACT_AVATAR], ["NOT `profile` AND NOT `contact-id` IS NULL AND `contact-id` != ?", 0]);
|
||||
DBA::update('photo', ['photo-type' => Photo::DEFAULT], ["NOT `profile` AND (`contact-id` IS NULL OR `contact-id` = ?) AND `photo-type` IS NULL AND `album` != ?", 0, Photo::CONTACT_PHOTOS]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue