Skip to content

Commit

Permalink
add *blacklist* parameter
Browse files Browse the repository at this point in the history
to exclude tables when applied globally
  • Loading branch information
themouette committed Sep 14, 2012
1 parent b16a116 commit a18d9dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -82,6 +82,7 @@ Following paramters are available :
* **activity_label_column** : column for activity log in **activity_table**
* **object_column** : column for object table in **activity_table**
* **object_pk_column** : column for object primarikey in **activity_table**
* **blacklist**: a coma separated list of tables to exclude from audit

How it works
------------
Expand Down
11 changes: 11 additions & 0 deletions src/AuditableBehavior.php
Expand Up @@ -28,12 +28,15 @@ class AuditableBehavior extends Behavior
'object_column' => 'object_class',
'object_pk_column' => 'object_pk',
'created_at_column' => 'created_at',
'blacklist' => '',
);

protected $activityTable, $peerBuilderModifier, $objectBuilderModifier;

public function modifyDatabase()
{
$blacklist = $this->getParameter('blacklist');
$blacklist = $this->getBlacklist($blacklist);
foreach ($this->getDatabase()->getTables() as $table) {
if ($table->hasBehavior($this->getName())) {
// don't add the same behavior twice
Expand All @@ -44,11 +47,19 @@ public function modifyDatabase()
// don't add the behavior to activity talbe
continue;
}
if (in_array($table->getName(), $blacklist)) {
// do not apply on blacklisted tables
continue;
}
$b = clone $this;
$table->addBehavior($b);
}
}

public function getBlacklist($blacklist) {
return array_map('trim', explode(',', $blacklist));
}

public function modifyTable()
{
$this->addActivityTable();
Expand Down
6 changes: 6 additions & 0 deletions tests/AuditableBehaviorTest.php
Expand Up @@ -107,6 +107,12 @@ function testApplyOnEveryTableButActivityWhenAppliedToDatabase()
$this->assertFalse(method_exists('AuditableBehaviorTestAppliedOnDatabaseActivity', 'disableLocalAudit'));
}

function testGetBlacklist() {
$b = new AuditableBehavior();
$list = $b->getBlacklist('tab,tab1, tab2, tab3 ,tab4');
$this->assertEquals(array('tab', 'tab1', 'tab2', 'tab3', 'tab4'), $list);
}

function testAuditActivity()
{
$o = new AuditableBehaviorTest1();
Expand Down

0 comments on commit a18d9dc

Please sign in to comment.