Add postPersist to listener. Add fieldDump function to user. #330

This commit is contained in:
Korina Cordero 2020-03-05 03:54:33 +00:00
parent eb0fd34eec
commit 485865901a
2 changed files with 27 additions and 6 deletions

View file

@ -309,4 +309,8 @@ class User extends BaseUser implements Serializable
{ {
return $this->partners_created; return $this->partners_created;
} }
public function fieldDump()
{
}
} }

View file

@ -22,6 +22,20 @@ abstract class EntityListener
$this->log_db = $log_db; $this->log_db = $log_db;
} }
public function postPersist($object, LifecycleEventArgs $args)
{
$event_time = new DateTime();
// get user for logging
$user = $this->token_storage->getToken()->getUser();
$username = $user->getUsername();
$obj_class = preg_replace('/.*\\\\/', '', get_class($object));
$log_message = $obj_class . ' with id ' . $object->getID() . ' created.';
error_log($log_message);
}
public function onFlush(OnFlushEventArgs $args) public function onFlush(OnFlushEventArgs $args)
{ {
$em = $args->getEntityManager(); $em = $args->getEntityManager();
@ -45,7 +59,10 @@ abstract class EntityListener
// get objects for creation // get objects for creation
foreach ($created_entities as $created_entity) foreach ($created_entities as $created_entity)
{ {
$log_message = 'Object with id ' . $created_entity->getID() . ' created.'; $obj_class = preg_replace('/.*\\\\/', '', get_class($created_entity));
$log_message = $obj_class . ' with id ' . $created_entity->getUsername() . ' created.';
error_log($log_message);
} }
// get updated fields. This doesn't include lists of other entities. // get updated fields. This doesn't include lists of other entities.
@ -75,11 +92,11 @@ abstract class EntityListener
$log_message = 'Object with id ' . $deleted_id . ' deleted.'; $log_message = 'Object with id ' . $deleted_id . ' deleted.';
} }
$this->log_db->writePoints([new Point( //$this->log_db->writePoints([new Point(
'User', // 'User',
'Action', // 'Action',
['status' => 'success'] // ['status' => 'success']
)]); //)]);
// TODO: find a way to get the list of "old" items, compare with list of updated items // TODO: find a way to get the list of "old" items, compare with list of updated items
// so we can find out what was added/removed // so we can find out what was added/removed