• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.
  • Chevereto Support CLST

    Support response

    Support checklist

Permission to "delete," but not delete image, only hide from user

mrladeia

Chevereto Member
Website URL
<private>

Chevereto version
3.10.13

Description of the issue
I need an initial statement so I can implement the following function:

With delete permission enabled, but I want to change the delete function.

What would have to be done when deleting IMAGE:
> "DELETE" IMAGE
1) Instead of delete from in the table images, execute update in column USER_ID switching to VISITOR. Hiding from his vision.
2) Do not delete image from folder.

> "DELETE" ALBUM
What would have to be done when deleting ALBUM:
1) Instead of delete from in the table album, execute update in column USER_ID switching to VISITOR. Hiding from his vision.
2) Do not delete image from folder.
3) UPDATE images to album NULL.



Is there any other problem?

Where do I start? Do you already have something similar ready?
 
It worked!


PHP:
public static function delete($id, $update_user=TRUE) {
        try {
            $image = self::getSingle($id, FALSE, TRUE);
            $disk_space_used = $image['size'] + $image['thumb']['size'] + $image['medium']['size'];

            /*if($image['file_resource']['type'] == 'path') {
                foreach($image['file_resource']['chain'] as $file_delete) {
                    if(file_exists($file_delete) and !@unlink($file_delete)) {
                        throw new ImageException("Can't delete file", 200);
                    }
                }
            } else {

                $targets = [];

                foreach($image['file_resource']['chain'] as $k => $v) {
                    $targets[$k] = [
                        'key' => preg_replace('#'.G\add_ending_slash($image['storage']['url']).'#', '', $v),
                        'size'=> $image[$k]['size'],
                    ];
                }
                try {
                    Storage::deleteFiles($targets, $image['storage']);
                } catch(Exception $e) {
                    throw new Exception("Can't delete image - Storage error: '" . $image['storage']['name']."'");
                }
            }*/

            if($update_user and isset($image['user']['id'])) {
                DB::increment('users', ['image_count' => '-1'], ['id' => $image['user']['id']]);
            }

            // Update album count
            if($image['album']['id'] > 0) {
                Album::updateImageCount($image['album']['id'], 1, '-');
            }
            
            // Track stats
            /*Stat::track([
                'action'    => 'delete',
                'table'        => 'images',
                'value'        => '-1',
                'date_gmt'    => $image['date_gmt'],
                'disk_sum'    => $disk_space_used,
                'likes'        => $image['likes'],
            ]);*/

            // Remove "liked" counter for each user who liked this image
            #DB::queryExec('UPDATE '.DB::getTable('users').' INNER JOIN '.DB::getTable('likes').' ON user_id = like_user_id AND like_content_type = "image" AND like_content_id = '.$image['id'].' SET user_liked = GREATEST(cast(user_liked AS SIGNED) - 1, 0);');

            /*if(isset($image['user']['id'])) {
                // Detect autolike
                $autoliked = DB::get('likes', ['user_id' => $image['user']['id'], 'content_type' => 'image', 'content_id' => $image['id']])[0];
                $likes_counter = (int) $image['likes']; // This is stored as "bigint" but PDO MySQL get it as string. Fuck my code, fuck PHP.
                if($autoliked) {
                    $likes_counter -= 1;
                }
                if($likes_counter > 0) {
                    $likes_counter = 0 - $likes_counter;
                }
                // Update user "likes" counter (if needed)
                if($likes_counter !== 0) {
                    DB::increment('users', ['likes' => $likes_counter], ['id' => $image['user']['id']]);
                }
                // Remove notifications related to this image (owner notifications)
                Notification::delete([
                    'table'        => 'images',
                    'image_id'    => $image['id'],
                    'user_id'    => $image['user']['id'],
                ]);
            }*/

            // Remove image likes
            #DB::delete('likes', ['content_type' => 'image', 'content_id' => $image['id']]);

            // Log image deletion
            /*DB::insert('deletions', [
                'date_gmt'            => G\datetimegmt(),
                'content_id'        => $image['id'],
                'content_date_gmt'    => $image['date_gmt'],
                'content_user_id'    => $image['user']['id'],
                'content_ip'        => $image['uploader_ip'],
                'content_views'        => $image['views'],
                'content_md5'        => $image['md5'],
                'content_likes'        => $image['likes'],
                'content_original_filename'    => $image['original_filename'],
            ]);*/

            #return DB::delete('images', ['id' => $id]);
            
            return DB::update('images', ['user_id' => NULL], ['id' => $id]);
        } catch(Exception $e) {
            throw new ImageException($e->getMessage() .' (LINE:' . $e->getLine() . ')', 400);
        }
    }
 
Where do I enable the option for users to delete content?

I'm not finding this option!


Incorrect translation! :(, so I was not finding.

msgid "Enable user content delete"
msgstr "Ativar códigos embed (conteúdo)"

msg correct:

"Permitir usuário deletar o próprio conteúdo"
 
Back
Top