This module allows you to record all changes made to the application's SQL tables.
- Changes made through a DAO derivated from the
\z4m_audittrail\mod\AuditTrailDAO
class are automatically recorded in the Audit trail. - The history of data changes can be viewed for a given date range.
- The audit trail can be purged partially for a given period or purged completely.
This module is published under the version 3 of GPL General Public Licence.
- ZnetDK 4 Mobile version 2.0 or higher,
- A MySQL database is configured to store the application data,
- Authentication is enabled
(
CFG_AUTHENT_REQUIRED
isTRUE
in the App'sconfig.php
).
- Add a new subdirectory named
z4m_audittrail
within the./engine/modules/
subdirectory of your ZnetDK 4 Mobile starter App, - Copy module's code in the new
./engine/modules/z4m_audittrail/
subdirectory, or from your IDE, pull the code from this module's GitHub repository, - Edit the App's
menu.php
located in the./applications/default/app/
subfolder and include themenu.inc
script to add a menu item definition for thez4m_audittrail
view.
require ZNETDK_MOD_ROOT . '/z4m_audittrail/mod/menu.inc';
- Go to the Audit trail menu to check if the audit trail view is correctly installed.
Once the Audit trail menu item is added to the application, you can restrict
its access via a user profile.
For example:
- Create a user profile named
Admin
from the Authorizations | Profiles menu, - Select for this new profile, the Audit trail menu item,
- Finally for each allowed user, add them the
Admin
profile from the Authorizations | Users menu.
This module is translated in French, English and Spanish languages.
To translate this module in another language or change the standard
translations:
- Copy in the clipboard the PHP constants declared within the
locale_en.php
script of the module, - Paste them from the clipboard within the
locale.php
script of your application, - Finally, translate each text associated with these PHP constants into your own language.
To enable the audit trail for your custom DAO class,
you just have to extends your class from the \z4m_audittrail\mod\AuditTrailDAO
class instead of the \DAO
class.
Here is below the example of the \app\model\BookDAO
class which extends the \z4m_audittrail\mod\AuditTrailDAO
class.
<?php
namespace app\model;
use \z4m_audittrail\mod\AuditTrailDAO;
class BookDAO extends AuditTrailDAO {
protected function initDaoProperties() {
$this->table = 'book';
}
}
Next, when you instantiate your custom \app\model\BookDAO
class to store or delete a row, set TRUE
to the first and second argument of the class constructor as shown below.
function saveBook($row) {
$dao = \app\model\BookDAO(TRUE, TRUE);
return $dao->store($row);
}
function deleteBook($bookId) {
$dao = \app\model\BookDAO(TRUE, TRUE);
return $dao->remove($bookId);
}
Tip
If you set FALSE
to the second argument of the DAO constructor, the detail of the values changed is not recorded in the audit trail.
Once you have inserted, updated or deleted rows in SQL tables traced in the audit trail, go to Audit trail menu to visualize the history of the SQL transactions that have occurred.
To display the audit trail for a specific date or a specific range of dates, enter a begin and end date to the filter bar located above the datalist.
By clicking the Transaction ID in the datalist, a modal dialog is open to show the detail of the changed values for each table's column.
To purge the audit trail, go to the Audit trail menu and click the Purge... button. If you entered a period in the filter bar above the datalist, the audit trail is purged only for the specified period.
The zdk_user_rows
and zdk_user_row_values
SQL tables
are created automatically by the module when they don't yet exist.
If the MySQL user declared through the
CFG_SQL_APPL_USR
PHP constant does not have CREATE
privilege, the module can't create the
required SQL tables.
In this case, you can create the module's SQL tables by importing in MySQL or
phpMyAdmin the script z4m_audittrail.sql
provided by the module.
See CHANGELOG.md file.
Your contribution to the ZnetDK 4 Mobile project is welcome. Please refer to the CONTRIBUTING.md file.