Automatism to duplicate records from a table to another

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Automatism to duplicate records from a table to another

Post by fgazza » 2019-06-13 20:44

Hi everyone. I need to create an automatism to duplicate the records of the "appointments" table (which is visible only by privileged users) in the "public appointments" table that is visible to unauthenticated users.
This should happen whenever a record is added or modified in the "appointments" table if the "public" field is checked in that table.
Is it possible to create a code in some hook files to get this result?
Thank you!
Fabiano

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Automatism to duplicate records from a table to another

Post by pbottcher » 2019-06-14 05:22

Hi,

sure this is possible, you need to add you code to the hooks/appointments.php file into the function after_insert and after_update.
Maybe as well into after_delete, but you did not mention what should happen if a record is deleted.

If deleted records should remain in the public appointments table, that is the way to go. If not I would suggest that you create a view (database view) to the appointments table and display this view to the unauthenticated uses. Like that the db takes care of everything.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: Automatism to duplicate records from a table to another

Post by fgazza » 2019-06-14 08:10

Thank you for your answer. Actually creating a view of the appointment table is perhaps the best thing! Not being an expert, I would be grateful if you could tell me where to start. Do I have to work in phpmyadmin or appgini hook files? How do I create the view and keep it automatically updated? Thank you!

Post Reply