diff options
Diffstat (limited to 'server/src/transactionhandler.cc')
-rw-r--r-- | server/src/transactionhandler.cc | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index 7ec38f8..a52dd50 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -28,12 +28,13 @@ #include "transactionhandler.h" #include "macroparser.h" -#include "resumeparser.h" #include "templateparser.h" #include "templateheaderparser.h" #include "courseparser.h" #include "configuration.h" #include "luaquerymapper.h" +#include "luaresume.h" +#include "luaoncommit.h" #include "queryhandlerpentominos.h" #include "queryhandlerpracro.h" #include "xml_encode_decode.h" @@ -60,6 +61,7 @@ static std::string error_box(std::string message) static std::string handleCommits(Transaction &transaction, Environment &env, Session &session) + throw(LUAScript::Exception) { std::string answer; @@ -71,19 +73,32 @@ static std::string handleCommits(Transaction &transaction, Environment &env, mp.parse(); Macro *macro = mp.getMacro(); - std::string resume = resume_parser(*macro, commit); - commit.fields["journal.resume"] = resume; - session.commitMacro(transaction, commit, *macro); + std::string resume; + try { + LUAResume luaresume(transaction, commit); + luaresume.addScripts(macro->resume_scripts); + luaresume.run(); + resume = luaresume.resultString(); + commit.fields["journal.resume"] = resume; + session.commitMacro(transaction, commit, *macro); + } catch(LUAScript::Exception &e) { + throw e; + } - if(resume != "") { - + LUAOnCommit *oncommit = NULL; + if(macro->commit_scripts.size() != 0) { + oncommit = new LUAOnCommit(transaction, commit); + oncommit->addScripts(macro->commit_scripts); + } + + if(resume != "" || oncommit != NULL) { TemplateParser tp(env.templatelist.getLatestVersion(commit.templ)); tp.parse(); Template *templ = tp.getTemplate(); - - session.journal()->addEntry(transaction, commit, resume, templ); - } + session.journal()->addEntry(transaction, commit, resume, templ, oncommit); + } + i++; } @@ -92,6 +107,7 @@ static std::string handleCommits(Transaction &transaction, Environment &env, static std::string handleRequest(Request &request, Environment &env, Session &session) + throw(NotFoundException) { std::string answer; @@ -321,9 +337,9 @@ std::string handleTransaction(Request &request, try { answer += handleCommits(transaction, env, session); - } catch( std::exception &e ) { - ERR(server, "Commit error: %s\n", e.what()); - return error_box(xml_encode(e.what())); + } catch( LUAScript::Exception &e ) { + ERR(server, "Commit error: %s\n", e.msg.c_str()); + return error_box(xml_encode(e.msg)); } try { |