Thread tagged as: Question, Api, Gallery

PerchDB class example

I'm looking for an example of how to build a callback page (server side) which updates a single value in ‘imageDynamicFields’ (perch2_gallery_images table) using the PerchDB class? (I’m stuck on how to actually use the API or misunderstanding the requirement for a custom app to do this).

Essentially I just want to mark an existing image checkbox as 'sold' so that an 'image' can't be bought twice. The function will simply be called via an ajax post request after paypal payment completes on gallery image.php. Figured the best way to do this was dive into the API but I'm struggling with tests thus far.

(Sadly not using Shop app due to pre-existing Gallery App requirement).

Many thanks Chris

Chris Henry

Chris Henry 0 points

  • 4 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

Hi Chris,

Unfortunately there isn't a public api for the gallery app, but if you check out the code you'll see the functions and classes that are used. If you write your own app to use those, you will obviously have to be aware that you will have to keep an eye on any updates to the gallery app that may affect your custom app.

It sounds like you may need a page function (literally a php function that can be called from your .php page). The code for this will live in the runtime.php file in your custom app. In theory, you can call in the image classes from the gallery app to handle updating a value...

Hi Duncan

Thanks for answering my question. I was thinking along the same lines but you confirmed I'll need to create an actual app to do this.

I've seen it mentioned that Gallery will be deprecated at some point in the not too distant future. While going with an app would be best, I may simply custom write a script without the involvement of Perch and update the database via more traditional means.

Thanks again Chris

Drew McLellan

Drew McLellan 2638 points
Perch Support

You shouldn't try to write to a table without going through the app that controls that table.

If you're going to go off piste, you should at least use the Gallery app itself to modify the data.

Hi Drew

I'd definitely prefer not to go an unofficial route.

As Duncan said, and in my mind I literally just need a function that marks the custom image field 'sold' with the string 'SOLD'. It can be assumed that this is null or empty before hand.

How would you do it?

Thanks for pointers!