Comments (10)
Yes, please if you could let me know how to do it manually that would be really helpful.
from audit-stash.
No, it does not. It is one of many missing features. You can force it to do it manually, though. Let me know if you need help getting that to work
from audit-stash.
I'm also running into this issue, being able to at least force it manually would be good.
from audit-stash.
@aceat64 If I tell you how to do it would you volunteer for documenting it?
from audit-stash.
Sure
from audit-stash.
@aceat64 This is what I personally do:
<?php
namespace App\Model\Audit;
use Cake\Utility\Text;
use SplObjectStorage;
class AuditTrail
{
protected $_auditQueue;
protected $_auditTransaction;
public function __construct()
{
$this->_auditQueue = new SplObjectStorage;
$this->_auditTransaction = Text::uuid();
}
public function toSaveOptions()
{
return [
'_auditQueue' => $this->_auditQueue,
'_auditTransaction' => $this->_auditTransaction
];
}
}
$trail = new AuditTrail();
$success = $connection->transactional(function () use ($trail) {
$table1->save($data1, $trail->toSaveOptions());
$table2->save($data2, $trail->toSaveOptions());
....
$tableN->save($dataN, $trail->toSaveOptions());
return true;
});
if ($success) {
$event = new Event('Model.afterCommit', $table);
$table->behaviors()->get('AuditLog')->afterCommit($event, $result, $auditTrail->toSaveOptions());
}
from audit-stash.
@lorenzo I'm running into some issues and could use a bit more info. Where is $result coming from? Do I need to run the event for each table?
from audit-stash.
You run the event in only one table, typically, if you are saving associations, you call it on the parent.
$result
needs to be an entity, as that is the signature for the afterCommit
event. It does not really matter what entity, but I pass the parent entity when saving associations.
from audit-stash.
@lorenzo How hard would it be to make transactional saves work natively with this plugin, without the additional hacks above?
My concern is that we as developers can forget to add the code above in certain situations and we will be missing the audit logs.
Do you already have some ideas on how this could be achieved out-of-the-box? If so, I don't mind taking a stab at it, but I would probably need some guidance.
I know you're busy, so thanks for taking the time if you can.
from audit-stash.
The only way I can think of is by having some sort of global state somewhere tracking whether or not a transaction has started in the connection, and then the behaviour would inject the global shared audit state to the save()
method
Developers would still need to wrap their calls in transactional()
though
from audit-stash.
Related Issues (20)
- Exception: No handler for type [string] declared on field [transaction] HOT 2
- audit-stash not working when updating multiple rows together HOT 7
- Syntax error in 2.0.0 release HOT 1
- deprecation warning for ServerRequest::here() HOT 3
- Deprecated field type error when running elastic_mapping shell HOT 2
- Multiple index guide incorrect HOT 3
- Throws an SQL incorrect syntax error on test HOT 2
- Inserting stringifiable objects HOT 2
- Implement JSON field types HOT 3
- CakePHP 4 compatibility HOT 5
- Can't find %s in the configuration guide for daily index HOT 1
- psr-4 autoloading standard warning in composer 1.10 HOT 2
- AuditLogsType.php does not comply with psr-4 autoloading standard. HOT 2
- String datetime changes may break custom DateTimeType implementations HOT 1
- Log associative model HOT 4
- Logging Cascading Deletes HOT 1
- Rename AuditLogsType.php file to AuditLogsIndex.php
- Your requirements could not be resolved to an installable set of packages
- Tests fail on my local
- CakePHP 5 Support HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audit-stash.