Mercurial > hg > orthanc
diff OrthancServer/DatabaseWrapper.cpp @ 1177:5b2d8c280ac2 db-changes
Plugins can monitor changes through callbacks
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 Sep 2014 17:37:44 +0200 |
parents | 3b372ab992ec |
children | 6b9b02a16e99 |
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp Mon Sep 22 14:11:37 2014 +0200 +++ b/OrthancServer/DatabaseWrapper.cpp Wed Sep 24 17:37:44 2014 +0200 @@ -116,7 +116,7 @@ virtual void Compute(SQLite::FunctionContext& context) { ResourceType type = static_cast<ResourceType>(context.GetIntValue(1)); - listener_.SignalResourceDeleted(type, context.GetStringValue(0)); + listener_.SignalChange(ChangeType_Deleted, type, context.GetStringValue(0)); } }; @@ -258,7 +258,7 @@ throw OrthancException(ErrorCode_InternalError); } - LogChange(changeType, id, type); + LogChange(changeType, id, type, publicId); return id; } @@ -650,14 +650,23 @@ void DatabaseWrapper::LogChange(ChangeType changeType, int64_t internalId, ResourceType resourceType, - const boost::posix_time::ptime& date) + const std::string& publicId) { + if (changeType == ChangeType_Deleted) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)"); s.BindInt(0, changeType); s.BindInt64(1, internalId); s.BindInt(2, resourceType); - s.BindString(3, boost::posix_time::to_iso_string(date)); - s.Run(); + s.BindString(3, boost::posix_time::to_iso_string(now)); + s.Run(); + + listener_.SignalChange(changeType, resourceType, publicId); }