]> git.mxchange.org Git - friendica.git/commitdiff
New photo field "photo-type" as preparation for banners
authorMichael <heluecht@pirati.ca>
Mon, 11 Oct 2021 14:21:10 +0000 (14:21 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 11 Oct 2021 14:21:10 +0000 (14:21 +0000)
15 files changed:
database.sql
doc/database/db_photo.md
include/api.php
mod/fbrowser.php
mod/photos.php
mod/wall_upload.php
src/Model/Contact.php
src/Model/Photo.php
src/Model/User.php
src/Module/Settings/Profile/Photo/Crop.php
src/Worker/Expire.php
src/Worker/ExpireConversations.php
src/Worker/RemoveUnusedAvatars.php
static/dbstructure.config.php
update.php

index 709d9f35eabf2baddd686fe9b180529ac3b7b909..d30ad46d7e719b5b5806078dcba959292b9f075f 100644 (file)
@@ -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';
index b641ae4596ecfbd76d52f575ddcf2dca66b1f2f3..8f1905bc7d46cc0e75bc62a746905245c2c031f5 100644 (file)
@@ -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
 ------------
index 211c2f6ecc01ab53f7a2c6c89f38b65473f559ed..c5c863bdd1ec0893c2d8150213647b43e74831aa 100644 (file)
@@ -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");
                        }
index c68b44a1ed8cc3bb940ed704bc16288ca696cbd2..b9f9b4c7f6a3e4b6c399fffa095a9658fbb92337 100644 (file)
@@ -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)
index 05767d4a4c70987c664b8aa5a482f6dc91de21ba..f58e5322499b0cfa4c9c9f33f04d536635b7adf1 100644 (file)
@@ -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()
        ));
index 100c9480882de740f4e06c6f3dfd5a106a4c4a29..f915954f0a1f6c42150911089b2803d0225d2011 100644 (file)
@@ -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;
                }
index 918eab384fdc55c0ac041fff1400b298f28eb17b..60b303bd547c2034c9cfa7c9b1c73915db91e41b 100644 (file)
@@ -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]);
                        }
                }
 
index 54316d92efa749d0e9238d0fd3277b98e46fa73b..1fdd55926d6177e106dc2debbaee4b5e7626a748 100644 (file)
@@ -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;
                        }
index e27a950adb57f609039f93e7ad5b5ff85f16d446..fbee73c786b527e5b10c7bd4419e8a864e855957 100644 (file)
@@ -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]);
                                }
                        }
 
index ba96e0032f9bf2b5d91c063096aefe2097ac571c..d9f04d8de43e7d704194b844af5af8e6d2a68731 100644 (file)
@@ -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'));
index d64a63a843aef47d16fdc503f4e53ac6a5383617..7a636499bdafde0ae507b3f64389f6ae2a644e1c 100644 (file)
@@ -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],
index aedf7cea518987467cfffcb56c55bf9c277570d4..8980a192acb9cf26e725e3b9c44cb9a710a4e4ed 100644 (file)
@@ -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);
 
        }
 }
index 7fdbeb7eccd847805f67bb8f3bc27835b75259cf..e8f615f62f6954c53e62c9e0e768e339b6988530 100644 (file)
@@ -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');
index 8203ae520217623f5f6930668dcd54de4dcc84fa..454d7c54e4a7f0c379427a53e6123c6a67b00d4b 100644 (file)
@@ -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" => [
index 49287cd0b2a86205a9c944d4f36047fb4b0692bc..114401334401e8c514e28a0985258fe6a9402397 100644 (file)
@@ -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;
        };
 
@@ -1005,4 +1005,11 @@ function update_1435()
        while ($contact = DBA::fetch($contacts)) {
                Contact\User::insertForContactArray($contact);
        }
-}
\ No newline at end of file
+}
+
+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]);
+}