0

For a custom component, I want to incorporate a way of keeping track of changes made to records in specific tables.

For example, when the mileage value of a car is changed, the record having the old mileage record is being copied to an archive table before the actual record is being changed.

I envisioned the following solution. I copied the table holding the current mileage information (same columns). Currently, I have the views, models and controllers setup to access the records through the backend component. Clicking an individual record opens the edit screen and the mileage can be changed. So far so good.

But this is where the magic should start happening. When I change a mileage record and click save I want to have a check if indeed anything has changed in the record, and when it does it should first write the record containing the old information to the archive table before saving the record.

Now I have tried playing with for example the duplicate function, trying to have a custom button call for the duplicate function and save it into a different table. I haven't been able to get this to work though and I'm struggling a bit with the routing of the data from the view to the controller and then to the model.

Is there someone who can help me with this?

2 Answers 2

0

Joomla has a build-in content history you are able to use in your custom component. maybe that helps you:

https://docs.joomla.org/Using_Content_History_in_your_Component

5
  • You are right, and I have looked into the content history function. However, I need to retrieve the data constantly to display to customers. The Joomla content history system stores all record information into a single cell, so I can't use a foreign key construction to connect this table to my application.
    – Badger
    Commented Jan 23, 2017 at 20:38
  • I dont know exactly your setup/component. But Thats the way we handle all our components. Its a mess, but after some time. its clear. Thats all :)
    – user5421
    Commented Jan 23, 2017 at 20:40
  • Well the mess is what we're trying to prevent. I am interested in how you use it exactly. We have around 7 tables and the ability to use content history. But we need to target specific records that are assigned to particular clients. How do you do that when all information is stored in a single cell? I'm guessing you're retrieving the information like a associative array and start work on it...
    – Badger
    Commented Jan 23, 2017 at 20:50
  • honestly: json. But i think i missunderstand you a lil or dont understand the "client" part and specific records. in your last comment. i will write tomorrow a lil more maybe. its time to sleep ;)
    – user5421
    Commented Jan 23, 2017 at 20:54
  • I would appreciate that, please do. Goodnight!
    – Badger
    Commented Jan 23, 2017 at 20:55
0

I would not bother implementing a Joomla extension for this task. A mysql trigger (simply done via phpMyAdmin) is going to be a stable solution -- least likely to break while upgrading Joomla (you only need to be concerned if the table schemas change).

Here are a couple of educational pages: MySQL Trigger after update only if row has changed and Get OLD Value in MySQL Trigger AFTER Update Statement

MySQL Doc: https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html

Also, https://dba.stackexchange.com/ is great place to continue your research.

You haven't offered any specifics, so I am unable to be more descriptive -- you will have to customise the exact necessary logic for your application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.