Download the PHP package kdesilva/audit-trail without Composer

On this page you can find all versions of the php package kdesilva/audit-trail. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package audit-trail

AuditStash Plugin For CakePHP 4.x

This plugin is forked from lorenzo/audit-stash

Although the above plugin is very good for storing change history, it has the following issues or does not have all the features I needed.

Therefore, I decided to fork from the original project and improve it to support the above missing features.

Installation

You can install this plugin into your CakePHP application using composer and executing the following lines in the root of your application.

If you plan to use ElasticSearch as the storage engine, please refer to lorenzo/audit-stash

Configuration

Tables / Regular Databases

If you want to use a regular database, respectively an engine that can be used via the CakePHP ORM API, then you can use the table persister that ships with this plugin.

To do so you need to configure the AuditStash.persister option accordingly. In your config/app.php file add the following configuration:

The plugin will then by default try to store the logs in a table named audit_logs, via a table class with the alias AuditLogs, which you could create/overwrite in your application if you need.

You can find a migration in the config/migration folder of this plugin which you can apply to your database, this will add a table named audit_logs with all the default columns. Alternatively you can bake your own migration to create the table. After that you can migrate the corresponding table class.

If you use the plugin's default migration, you can create the table and model class using the commands below.

Table Persister Configuration

The table persister supports various configuration options, please refer to its API documentation for further information. Generally configuration can be applied via its config() (or setConfig()) method:

Also, you can set some common config via the app.php. Currently, the plugin supports 'extractMetaFields' and 'blacklist'

Using AuditStash

Enabling the Audit Log in any of your table classes is as simple as adding a behavior in the initialize() function:

Configuring the Behavior

The AuditLog behavior can be configured to ignore certain fields of your table, by default it ignores the id, created and modified fields:

If you prefer, you can use a whitelist instead. This means that only the fields listed in that array will be tracked by the behavior:

If you need to retrieve human-friendly data fields from related tables (i.e. with foreign keys) you can set foreignKeys as below.

As explained in the project description above, CakePHP (4.x) ORM returns all associated data even if no are changes made to the associated data. Therefore, you need to set unsetAssociatedEntityFieldsNotDirtyByFieldName as you can see in the above example if you need to remove unchanged data from the associated entities.

Storing The Logged In User

It is often useful to store the identifier of the user that is triggering the changes in a certain table. For this purpose, AuditStash provides the RequestMetadata listener class, that is capable of storing the current URL, IP and logged in user. You need to add this listener to your application in the AppController::beforeFilter() method:

The above code assumes that you will trigger the table operations from the controller, using the default Table class for the controller. If you plan to use other Table classes for saving or deleting inside the same controller, it is advised that you attach the listener globally:

Storing Extra Information In Logs

AuditStash is also capable of storing arbitrary data for each of the logged events. You can use the ApplicationMetadata listener or create your own. If you choose to use ApplicationMetadata, your logs will contain the app_name key stored and any extra information your may have provided. You can configure this listener anywhere in your application, such as the bootstrap.php file or, again, directly in your AppController.

Implementing your own metadata listeners is as simple as attaching the listener to the AuditStash.beforeLog event. For example:

Implementing Your Own Persister Strategies

There are valid reasons for wanting to use a different persist engine for your audit logs. Luckily, this plugin allows you to implement your own storage engines. It is as simple as implementing the PersisterInterface interface:

Finally, you need to configure AuditStash to use your new persister. In the config/app.php file add the following lines:

or if you are using as standalone via

The configuration contains the fully namespaced class name of your persister.

Working With Transactional Queries

Occasionally, you may want to wrap a number of database changes in a transaction, so that it can be rolled back if one part of the process fails. In order to create audit logs during a transaction, some additional setup is required. First create the file src/Model/Audit/AuditTrail.php with the following:

Anywhere you wish to use Connection::transactional(), you will need to first include the following at the top of the file:

Your transaction should then look similar to this example of a BookmarksController:

This will save all audit info for your objects, as well as audits for any associated data. Please note, $result must be an instance of an Object. Do not change the text "Model.afterCommit".

Saving Multiple Entities

Create the file src/Model/Audit/AuditTrail.php as shown in the above section


All versions of audit-trail with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
cakephp/orm Version ^4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kdesilva/audit-trail contains the following files

Loading the files please wait ....