Plugins

From RedBean

Jump to: navigation, search

Contents

Plugins

Some people like extra functions, but others do not. This is why RedBean is a very minimalistic ORM library; you can plug-in extra functionality if you like. Instead of offering a complete plug-in architecture; RedBean uses old fashioned, traditional, easy to understand OO techniques to add functionality. Plugins that ship with RedBean are stored in the plugin-folder. You have to include them manually. 3rd party plugins should be downloaded and included according to the documentation of the authors.

Plugin: Stable Beans (DracSoft)

Allows you to have a collection of stable beens that reside in frozen schema while the rest of the app works in fluid mode. http://www.redbeanphp.com/downloads/plugins/stablebeans.tar.gz


Plugin: Concurrency Control

To install this plug-in, just include its file and:

$logger = new RedBean_Plugin_ChangeLogger( $toolbox );
$redbean->addEventListener( "open", $logger );
$redbean->addEventListener( "update", $logger);
$redbean->addEventListener( "delete", $logger); 

RedBean Change Logger Plugin protects against three types of concurrency issues: internal concurrency, session concurrency and offline concurrency.

Internal Concurrency

Internal concurrency happens when you have two instances of the same bean and one updates the database before the other and the other does not reload. In this case chances are that the other bean overwrites the changed made by the older bean. Sometimes this kind of behaviour can be a sign of bad code because it means you discard changes by other objects or you simply do redundant updates.

Session Concurrency

Session concurrency happens if multiple requests modify data in the database concurrently. Transactions with isolation level serializable may help to prevent this kind of concurrency; but to use this you need to handle transaction. Also, the exact implementation and behaviour differs over databases. With RedBean you dont have to think about this because if a record has been changed since the last read this is stored in the journal and access to the row will be denied.

Using the journaling system for offline Locking

When exporting bean to an external view, like a webpage-form with the possibility of subsequent updates to the bean with the submitted form-data, one should take care to preserve meta field "opened". This can be done using a hidden form-field or in session.

$newpage->setMeta("opened",(int) $_POST["revision"]);

Saving a bean without an opened meta property will cause a Failed Access Exception.

Plugin: Optimizer (standard)

To install this plug-in, just include its file and:

$optimizer = new RedBean_Plugin_Optimizer( $toolbox );
$redbean->addEventListener("update", $optimizer);

This plugin shrinks columns if possible to save space and boost performance. It is completely transparent. The Optimizer also transforms columns into datetime fields if needed.

Plugin: Bean Cache (standard)

To boost performance on production servers; you can use Bean Cache. The Bean Cache plugin provides a simple, elegant caching mechanism for beans. To use it, just include the corresponding file (Cache.php) in the plugin folder and add the following code:

$redbean = new RedBean_Plugin_Cache( $redbean, $toolbox );
Personal tools