/** * @param AbstractAudit $audit * @param string $field * @param string $dataType * @param mixed $newValue * @param mixed $oldValue */ public function __construct(AbstractAudit $audit, $field, $dataType, $newValue, $oldValue) { $this->audit = $audit; $this->field = $field; $this->dataType = AuditFieldTypeRegistry::getAuditType($dataType); $this->setOldValue($oldValue); $this->setNewValue($newValue); }
public function testAuditFieldTypeRegistry() { $this->assertFalse(AuditFieldTypeRegistry::hasType('newtype')); AuditFieldTypeRegistry::addType('newtype', 'newtype_'); $this->assertTrue(AuditFieldTypeRegistry::hasType('newtype')); $this->assertEquals('newtype_', AuditFieldTypeRegistry::getAuditType('newtype')); AuditFieldTypeRegistry::overrideType('newtype', 'overridentype'); $this->assertEquals('overridentype', AuditFieldTypeRegistry::getAuditType('newtype')); AuditFieldTypeRegistry::removeType('newtype'); $this->assertFalse(AuditFieldTypeRegistry::hasType('newtype')); }
/** * @param OrmFilterDatasourceAdapter $ds * @param string $objectClass * @param string $fieldName * @param array $data */ protected function applyNewAuditValueFilter(OrmFilterDatasourceAdapter $ds, $objectClass, $fieldName, array $data) { if ($data['auditFilter']['type'] !== static::TYPE_CHANGED_TO_VALUE) { return; } $metadata = $ds->getQueryBuilder()->getEntityManager()->getClassMetadata($objectClass); $type = $metadata->getTypeOfField($fieldName); if (!$type) { $type = 'text'; } $newValueField = sprintf('new%s', ucfirst(AuditFieldTypeRegistry::getAuditType($type))); $this->applyFilter($ds, $data['filter']['filter'], sprintf('%s.%s', $this->auditFieldAlias, $newValueField), $data['filter']['data']); }
/** * @param array $row * @param array $data */ private function processArrayData(array $row, array $data) { foreach ($data as $field => $values) { $visible = true; $fieldType = $this->getFieldType($row['entity_id'], $field); $dataType = null; if (!AuditFieldTypeRegistry::hasType($fieldType) || !array_key_exists('old', $values) || !array_key_exists('new', $values)) { $dataType = 'array'; $visible = false; } else { $dataType = AuditFieldTypeRegistry::getAuditType($fieldType); } $dbData = ['audit_id' => $row['id'], 'data_type' => $dataType, 'field' => $field, sprintf('old_%s', $dataType) => $this->parseValue($values, 'old'), sprintf('new_%s', $dataType) => $this->parseValue($values, 'new'), 'visible' => $visible]; $types = ['integer', 'string', 'string', $dataType, $dataType, 'boolean']; $this->connection->insert('oro_audit_field', $dbData, $types); } }