Page 1 of 1

Automatism to duplicate records from a table to another

Posted: 2019-06-13 20:44
by fgazza
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

Re: Automatism to duplicate records from a table to another

Posted: 2019-06-14 05:22
by pbottcher
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.

Re: Automatism to duplicate records from a table to another

Posted: 2019-06-14 08:10
by fgazza
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!