Hello,
as newbie to AppGini and SQL ..
I would like to know How to save/archive Deleted records into a "Archive" table using AppGini ?
How to Archive Deleted Records?
How to Archive Deleted Records?
THANK YOU...
AppGini Pro 24.11 -
Calendar - Search Page Maker - Summary Reports - Mass Update - DataTalk -
bizzworxx AppGini Helper JabaScript Library - bizzworxx Inline Detail-View - bizzworxx Helper Pack - AppGini Helper Packaging Tool -
Udemy course
AppGini Pro 24.11 -
Calendar - Search Page Maker - Summary Reports - Mass Update - DataTalk -
bizzworxx AppGini Helper JabaScript Library - bizzworxx Inline Detail-View - bizzworxx Helper Pack - AppGini Helper Packaging Tool -
Udemy course
Re: How to Archive Deleted Records?
Hi ,
you can use the before delete hook and save your record to an archive table.
you can use the before delete hook and save your record to an archive table.
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.
Re: How to Archive Deleted Records?
Hello,
Thank you ...
A tough tip , but will try to search the net for some possible codes, that I can review and try
Thank you ...
A tough tip , but will try to search the net for some possible codes, that I can review and try
THANK YOU...
AppGini Pro 24.11 -
Calendar - Search Page Maker - Summary Reports - Mass Update - DataTalk -
bizzworxx AppGini Helper JabaScript Library - bizzworxx Inline Detail-View - bizzworxx Helper Pack - AppGini Helper Packaging Tool -
Udemy course
AppGini Pro 24.11 -
Calendar - Search Page Maker - Summary Reports - Mass Update - DataTalk -
bizzworxx AppGini Helper JabaScript Library - bizzworxx Inline Detail-View - bizzworxx Helper Pack - AppGini Helper Packaging Tool -
Udemy course
Re: How to Archive Deleted Records?
Hi Mohamed,
this should actually be quite easy.
As pbötcher said - just intercept the delete using the hooks.
ag_root/hooks/tablename.php
function ...before_delete
Before the delete will be executed this function will be run. You can simply copy the current record (which ID you get in the variable $selectedID):
Read the record with $selectedID from your table
Write the record to your backup table
return true in the function to actually continue the deletion process.
You might also use the Audit Log (see my footer: viewtopic.php?f=4&t=1369&p=10407). This can log deletions as well (and give you some extra feature).
Olaf
this should actually be quite easy.
As pbötcher said - just intercept the delete using the hooks.
ag_root/hooks/tablename.php
function ...before_delete
Before the delete will be executed this function will be run. You can simply copy the current record (which ID you get in the variable $selectedID):
Read the record with $selectedID from your table
Write the record to your backup table
return true in the function to actually continue the deletion process.
You might also use the Audit Log (see my footer: viewtopic.php?f=4&t=1369&p=10407). This can log deletions as well (and give you some extra feature).
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: How to Archive Deleted Records?
The ideas and concepts named before will definitely work well.
A different approach which does not require additional, cloned tables is "soft delete" concept:
Add a column "is_deleted" (int, default=0, checkbox) and perhaps "deleted_on" and "deleted_by". Then, instead of deleting a record, just set "is_deleted" flag to 1 and cancel delete.
The "deleted" records will not be deleted but just marked as deleted. They will stay in the same db and table. History and references will stay consistent (integrity).
You can use filters, for example in TABLENAME_init function, to filter out "deleted" records (having is_deleted=1).
Or you can use permissions in membership system to hide those "deleted" records for non-admin users.
You can even use some jquery + CSS to show soft-deleted records for example in red or striped through.
Soft-delete is not better but different. As the other concepts, also soft-delete has advantages and disadvantages. All concepts require additional coding.
A different approach which does not require additional, cloned tables is "soft delete" concept:
Add a column "is_deleted" (int, default=0, checkbox) and perhaps "deleted_on" and "deleted_by". Then, instead of deleting a record, just set "is_deleted" flag to 1 and cancel delete.
The "deleted" records will not be deleted but just marked as deleted. They will stay in the same db and table. History and references will stay consistent (integrity).
You can use filters, for example in TABLENAME_init function, to filter out "deleted" records (having is_deleted=1).
Or you can use permissions in membership system to hide those "deleted" records for non-admin users.
You can even use some jquery + CSS to show soft-deleted records for example in red or striped through.
Soft-delete is not better but different. As the other concepts, also soft-delete has advantages and disadvantages. All concepts require additional coding.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: How to Archive Deleted Records?
Forgot to say: the "soft-delete" concept can be used with an "is_archived" column (instead of "is_deleted"). Filter all records where is_archived = 1 in _init() function. Those marked records will stay in db and integrity with related records (lookups) will be kept.
But if you need extra archive tables, as your question was about, you should follow the answers above.
Just wanted to describe a different approach than cloning into a different table and deleting the original record in case someone else stumbles upon this thread.
But if you need extra archive tables, as your question was about, you should follow the answers above.
Just wanted to describe a different approach than cloning into a different table and deleting the original record in case someone else stumbles upon this thread.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: How to Archive Deleted Records?
Hi,
good idea Jan. I want to add, that columns "deleted_on" and "deleted_by" are enough. You do not need an extra column "is_deleted". This would be redundant: A record is deleted, if it holds values in the "deleted_on" and "deleted_by" columns.
A quick reminder: Be sure, you follow privacy rules. You might not be legally allowed to keep deleted records - or you are forced to do so for a specific time.
Olaf
good idea Jan. I want to add, that columns "deleted_on" and "deleted_by" are enough. You do not need an extra column "is_deleted". This would be redundant: A record is deleted, if it holds values in the "deleted_on" and "deleted_by" columns.
A quick reminder: Be sure, you follow privacy rules. You might not be legally allowed to keep deleted records - or you are forced to do so for a specific time.
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: How to Archive Deleted Records?
1[+2] columns vs. 1 column
Yes, from technical point of view you are completely right, Olaf. Thanks for emphasizing.
The primary idea of soft-delete is the is_deleted flag. As mentioned ("perhaps"), deleted_by and/or deleted_on are optional for some extra information. Of course, if you have at least one of them, others may become redundant from technical perspective. You can filter by "deleted_on IS NOT NULL" as well as on "is_deleted=1" (or vice versa).
However, I am used to add "is_xxxxx" flags for simple checkbox in UI and simple SQL queries plus some extra information in columns xxxxx_on and xxxxx_by. So, having all three columns may not be smallest possible solution but very practical over the years from different points of view.
Privacy rules
That's a good and important point, Olaf! The privacy rules or legal restrictions for deleting or keeping records are the same for all archive-concepts. Legal restrictions are not bound to technical implementation.
Yes, from technical point of view you are completely right, Olaf. Thanks for emphasizing.
The primary idea of soft-delete is the is_deleted flag. As mentioned ("perhaps"), deleted_by and/or deleted_on are optional for some extra information. Of course, if you have at least one of them, others may become redundant from technical perspective. You can filter by "deleted_on IS NOT NULL" as well as on "is_deleted=1" (or vice versa).
However, I am used to add "is_xxxxx" flags for simple checkbox in UI and simple SQL queries plus some extra information in columns xxxxx_on and xxxxx_by. So, having all three columns may not be smallest possible solution but very practical over the years from different points of view.
Privacy rules
That's a good and important point, Olaf! The privacy rules or legal restrictions for deleting or keeping records are the same for all archive-concepts. Legal restrictions are not bound to technical implementation.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: How to Archive Deleted Records?
Hello onoehring & jsetzer,
Thanks for the details. Will try the suggestions once I am done with testing the other features I am intending to use in AppGini.
Thanks for the details. Will try the suggestions once I am done with testing the other features I am intending to use in AppGini.
THANK YOU...
AppGini Pro 24.11 -
Calendar - Search Page Maker - Summary Reports - Mass Update - DataTalk -
bizzworxx AppGini Helper JabaScript Library - bizzworxx Inline Detail-View - bizzworxx Helper Pack - AppGini Helper Packaging Tool -
Udemy course
AppGini Pro 24.11 -
Calendar - Search Page Maker - Summary Reports - Mass Update - DataTalk -
bizzworxx AppGini Helper JabaScript Library - bizzworxx Inline Detail-View - bizzworxx Helper Pack - AppGini Helper Packaging Tool -
Udemy course