• 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

Adding new field to database and populating it on image upload/edit

daltec

Chevereto Member
Hello, we have an external application that can save images to our Chevereto gallery. While these images are public domain, we'd still like to provide a link to the image source page. So we added a field for "attribution" to the chv_images table.

Images uploaded from our external app populate this field fine, and the URL shows for each image in Chevereto. We also added a field in the Anywhere Uploader form for attribution, and it shows the value from the database (if there is one).

We'd like to have changes or new entries to this field to be saved to the database, and that is where I am stuck. I have reviewed class.image.php and class.upload.php, but am not seeing where to make these edits.

For example, I have tried adding 'attribution' => $params['attribution'] to $image_insert_values, which doesn't work. I do not get an error, and other values are saved fine, but whatever has been entered for attribution does not get saved.

I understand this type of customization is outside the scope of normal tech support, but I would greatly appreciate any info on which files need to be edited, and where within those files we should be looking.

Many thanks in advance!
 
Add your custom key to:

PHP:
static $table_chv_image

Many thanks for your speedy reply, Rodolfo! I had forgotten to mention, I did that as follows:

PHP:
static $table_chv_image = [
               'name',
               'extension',
               'album_id',
               'size',
               'width',
               'height',
               'date',
               'date_gmt',
               'nsfw',
               'user_id',
               'uploader_ip',
               'storage_mode',
               'storage_id',
               'md5',
               'original_filename',
               'original_exifdata',
               'category_id',
               'description',
               'chain',
               'thumb_size',
               'medium_size',
               'title',
               'expiration_date_gmt',
               'likes',
               'is_animated',
               'attribution'
            ];

Here is what I have in anywhere_upload.php:

PHP:
<div class="input-label">
                   <label for="form-attribution"><?php _se('Attribution'); ?> <span class="optional"><?php _se('Source URL of image, if needed'); ?></span></label>
                   <input type="text" id="form-attribution" name="form-attribution" class="text-input" value="" maxlength="255">
</div>

Thanks again for your advice and guidance. I appreciate your willingness to help us with something outside the scope of normal tech support.
 
No, sorry that I did not make that clear. It seems to work, and I do not get an error, but it does not save to the database. And if I refresh the page, whatever value I added to the attribution field in the editor does not "stick" either. It's almost as if I am passing an empty or null value to the database for "Attribution," despite having entered something in the form.
 
Make sure that the filed in the database is 'image_attribution' not 'attribution'
 
Make sure that the filed in the database is 'image_attribution' not 'attribution'
It is, and I set it as a varchar with a length of 255. In class.image.php, I added the following:

PHP:
$image_insert_values = [
               'storage_mode'   => $storage_mode,
               'storage_id'   => $storage_id,
               'user_id'       => $user['id'],
               'album_id'       => $params['album_id'],
               'nsfw'           => $params['nsfw'],
               'category_id'   => $params['category_id'],
               'title'           => $params['title'],
               'description'   => $params['description'],
               'chain'           => $chain_value,
               'thumb_size'   => $image_thumb['fileinfo']['size'],
               'medium_size'   => $image_medium['fileinfo']['size'] ?: 0,
               'is_animated'   => $is_animated_image,
               'attribution'   => $params['attribution']
           ];
Which does not add or insert anything. Even if I try a hard-coded value such as 'attribution' => 'test' the word 'test' does not get saved.

I really appreciate your assistance, but your time is valuable and I do not want to impose on it any further! We've been following the structure for "description" as closely as we can, and basing our new field on that. So if you could please let me know in which places the value for "description" gets set, I could maybe figure it out from there. It seems to get added to $values at some point, but I am not seeing where that happens.

Thanks Rodolfo!
 
Go from the most inner layer to outside, start with insert() at class.image.php then uploadToWebsite() and finally route.json.php.

Debug your code properly, I can't help you guessing that you did right or wrong. Maybe is a silly thing like a typo error, etc. I can't tell.
 
Last edited:
Thanks Rodolfo! I appreciate all of your suggestions. I am sure we will get it figured out eventually!
 
Hi Rodolfo, I am sorry it took me so long to follow up. Your advice was great -- thanks! But we needed to make a few changes to chevereto.js and had overlooked that file. We made those edits and everything is working fine now.

Thanks also for all the work you do on Chevereto. It is an elegant piece of software and will be a nice resource for our members.
 
Back
Top