RISE keeps an activity log (life cycle) of clients, leads, invoices, estimates, proposals, contracts, orders, subscriptions, tickets and expenses. A plugin can add its own tables to these logs with one filter.
What is logged
- created, updated and deleted records. Updates are logged only when an important field changes.
- sent: an invoice, estimate, proposal or contract was emailed. The log keeps the email log id and the ids of the client contacts who got the email (no email addresses).
- notified: a notification was sent for a record without another log (like reminders or a client opening a proposal).
- Draft invoices, estimates, proposals, contracts and subscriptions: only created, deleted and the change out of draft are logged. Edits and item changes of a draft are not logged.
Logs are saved automatically by ci_save(), delete() and delete_permanently() of the models. Saving costs one small query, only when an important field changes. If a log can't be saved, the error is written to the log file and the saving action goes on.
Add a table from a plugin
Your model must extend Crud_model and save with ci_save(). Add the table with the filter app_filter_activity_log_tracked_tables. Use the table name without the prefix.
app_hooks()->add_filter('app_filter_activity_log_tracked_tables', function ($tables) {
//a main record of a client
$tables["my_plugin_bookings"] = array(
"log_type" => "my_plugin_booking",
"title_fields" => array("title"),
"client_field" => "client_id",
"fields" => array("title", "status", "booking_date", "client_id"),
"created_fields" => array("status")
);
//a sub record of an invoice
$tables["my_plugin_invoice_notes"] = array(
"log_type" => "my_plugin_invoice_note",
"title_fields" => array("title"),
"parent" => "invoices",
"parent_field" => "invoice_id",
"fields" => array("title", "description")
);
return $tables;
});
Options
| Option | Meaning |
| log_type | Name of the record type (a-z, 0-9, _, max 30 characters). Use your plugin name in it. |
| title_fields | Fields used as the title of the log. The first one with a value is used. |
| client_field | Field with the client id. The log is shown in the client's history. |
| parent, parent_field | For sub records: the parent table and the field with the parent id. The client of the parent is saved too. |
| fields | Changes of these fields are logged. Other fields (like sort or totals) are ignored. |
| created_fields | Values saved with the created log. |
| draft_status | Status value of a draft (like "draft"). Edits of a draft are not logged. |
| sent_field | A date field set when the record is emailed (like last_email_sent_date). A change of it is logged as sent. |
| summary_fields | Big fields (like html content). The log only says that it changed. |
| condition | Function($row) returning false to skip a row. |
| skip_change | Function($field, $from, $to) returning true to skip a change. |
| actor_field | Field with the user who created the row. Used when nobody is signed in (like a cron job). |
Automatic changes
Logs are saved with the signed in user. When your plugin changes records automatically after a user's action (like creating an invoice after a client's order), run that code as the app, so the logs show the system instead of the user:
\App\Libraries\Activity_log_tracker::run_as_app(function () use ($order_id) {
//your automatic changes
});
Where the logs are shown
Logs of a main record with a client_field are shown in the Activity section of the client page. Logs of a sub record of invoices, estimates, proposals, contracts, orders, subscriptions or tickets are shown on that record's page too. Logs of plugin tables are shown only to admins, because RISE can't check their permissions.
Notifications
When you call log_notification() after saving a tracked record in the same request, the notification is linked to the log automatically (activity_log_id).