<commit_before><?php
namespace App\Persister;

use AuditStash\PersisterInterface;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;

class MysqlPersister implements PersisterInterface
{
    /**
     * Persists all of the audit log event objects that are provided
     *
     * @param array $auditLogs An array of EventInterfacfe objects
     * @return void
     */
    public function logEvents(array $auditLogs)
    {
        foreach ($auditLogs as $log) {
            $eventType = $log->getEventType();
            $data = [
                'timestamp' => $log->getTimestamp(),
                'transaction' => $log->getTransactionId(),
                'type' => $log->getEventType(),
                'primary_key' => $log->getId(),
                'source' => $log->getSourceName(),
                'parent_source' => $log->getParentSourceName(),
                'changed' => 'delete' === $eventType ? null : json_encode($log->getChanged()),
                'meta' => json_encode($log->getMetaInfo())
            ];
            // save audit log
            TableRegistry::get('LogAudit')->save(new Entity($data));
        }
    }
}<commit_msg>store fields original values (task #1397)<commit_after><?php
namespace App\Persister;

use AuditStash\PersisterInterface;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;

class MysqlPersister implements PersisterInterface
{
    /**
     * Persists all of the audit log event objects that are provided
     *
     * @param array $auditLogs An array of EventInterfacfe objects
     * @return void
     */
    public function logEvents(array $auditLogs)
    {
        foreach ($auditLogs as $log) {
            $eventType = $log->getEventType();
            $data = [
                'timestamp' => $log->getTimestamp(),
                'transaction' => $log->getTransactionId(),
                'type' => $log->getEventType(),
                'primary_key' => $log->getId(),
                'source' => $log->getSourceName(),
                'parent_source' => $log->getParentSourceName(),
                'changed' => 'delete' === $eventType ? null : json_encode($log->getChanged()),
                'original' => json_encode($log->getOriginal()),
                'meta' => json_encode($log->getMetaInfo())
            ];
            // save audit log
            TableRegistry::get('LogAudit')->save(new Entity($data));
        }
    }
}
{'fraction_non_alphanumeric': 0.14052013422818793, 'fraction_numerical': 0.0016778523489932886, 'mean_word_length': 2.171542553191489, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2209479', 'n_tokens_mistral': 674, 'n_tokens_neox': 654, 'n_words': 145}