21 #include "core/audit/AuditEntry_odb.h" 23 #include "core/auth/User_odb.h" 26 #include <odb/query.hxx> 36 timestamp_ = boost::posix_time::second_clock::local_time();
46 if (e == odb::callback_event::post_update ||
47 e == odb::callback_event::post_persist)
60 "Not currently in a database transaction.");
64 "Trying to finalizing already finalized entry. Doing nothing instead.");
92 ASSERT_LOG(user->id(),
"Author is not already persisted.");
98 ASSERT_LOG(
id_,
"Current audit entry must be already persisted.");
100 ASSERT_LOG(parent->id(),
"Parent must be already persisted.");
103 ASSERT_LOG(parent_odb,
"Parent is not of type AuditEntry");
105 parent_odb->children_.push_back(shared_from_this());
118 auto &children =
parent->children_;
119 children.erase(std::remove(children.begin(), children.end(), shared_from_this()),
136 ASSERT_LOG(odb::transaction::has_current(),
"Not currently in transaction.");
165 using Query = odb::query<AuditEntry>;
166 Query q(
"ORDER BY id DESC LIMIT 1");
bool finalized_
Audit entry are sometime persisted multiple time before reaching their final state.
virtual void remove_parent() override
Remove the parent-child relationship between this entry and its parent.
Implementation of IAuditEntry, backed by ODB.
This is the header file for a generated source file, GitSHA1.cpp.
virtual size_t children_count() const override
Returns the number of children that this entry has.
virtual void author(Auth::UserPtr user) override
Set the author of the entry.
unsigned long AuditEntryId
size_t duration_
How long did it take for the Audit object to be finalized.
static AuditEntryPtr get_last_audit(DBPtr db)
Retrieve the last (finalized) audit entry.
virtual bool finalized() const override
Is this entry finalized.
Tools::ElapsedTimeCounter etc_
Keep track of how long the object has been alive.
An optional transaction is an object that behave like an odb::transaction if there is no currently ac...
std::shared_ptr< IAuditEntry > IAuditEntryPtr
virtual IAuditEntryPtr parent() const override
Retrieve the parent of this entry.
virtual void finalize() override
Mark the entry as finalized, and update it wrt the database.
void odb_callback(odb::callback_event e, odb::database &) const
Implementation of an ODB callback.
std::vector< AuditEntryPtr > children_
virtual Auth::UserId author_id() const override
Retrieve the user id of the author of this entry.
odb::query< Tools::LogEntry > Query
virtual boost::posix_time::ptime timestamp() const override
Retrieve unix timestamp.
std::shared_ptr< AuditEntry > AuditEntryPtr
virtual const EventMask & event_mask() const override
Retrieve the current event mask.
DBPtr database_
Pointer to the database.
std::shared_ptr< User > UserPtr
boost::posix_time::ptime timestamp_
FlagSet< EventType > EventMask
#define ASSERT_LOG(cond, msg)
virtual void reload() override
Reload the object from the database.
virtual size_t version() const override
Returns the ODB version of the object.
virtual void set_parent(IAuditEntryPtr parent) override
Set parent as the parent audit entry for this entry.
Auth::UserLPtr author_
The user at the source of the entry.
std::shared_ptr< odb::database > DBPtr
void database(DBPtr db)
Set the database pointer.
virtual AuditEntryId id() const override
Retrieve the identifier of the entry.
The Audit namespace provides classes and facilities to keep track of what's happening on the Leosac d...