Commit 7244c3c1 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

remove srv_id information when removing activities following an unsubscribe....

remove srv_id information when removing activities following an unsubscribe. Fixed unsubscribe  - activity remove from db
parent 13db4dba
......@@ -51,6 +51,7 @@ void CaSupervisor::onResult(const CuData &data) {
// from CaReceiver_A activity
else if(data.containsKey("data")) {
const std::string& s = data.s("data");
printf("ca-supervisor.onResult: received \e[1;36m%s\e[0m\n", s.c_str());
CaJsonSrcBundleExtract bux;
std::list<CuData> dl;
std::string chan, id, global_m;
......@@ -63,7 +64,8 @@ void CaSupervisor::onResult(const CuData &data) {
}
else {
for(const CuData& da : dl)
printf("ca-supervisor.onResult: extracted %s chan %s id %s global method \"%s\"\n", datos(da), chan.c_str(), id.c_str(), global_m.c_str());
printf("ca-supervisor.onResult: extracted %s chan %s id %s global method \"%s\" extram[srv_id] %s extram[method] %s\n",
datos(da), chan.c_str(), id.c_str(), global_m.c_str(), extram["srv_id"].c_str(), extram["method"].c_str());
CaSupDbAEvent *e = new CaSupDbAEvent(extram["srv_id"], id, extram["method"], chan, dl);
d->dba->new_event(e);
}
......
......@@ -126,7 +126,7 @@ void CaSupDbActivity::execute() {
if(e->method == "s")
ok = dbf.register_activities(d->dbh, e->server_id, e->cli_id, e->channel, e->datalist);
else if(e->method == "u")
ok = dbf.unregister_activities(d->dbh, e->server_id, e->cli_id, e->channel, e->datalist);
ok = dbf.unregister_activities(d->dbh, e->cli_id, e->channel, e->datalist);
}
if(!ok) // database error
d->log->write("ca-supervisor", "database error: " + dbf.last_db_error);
......
......@@ -190,7 +190,6 @@ bool CaSupDbFuncs::register_activities(CaDbH *dbhan, const std::string &srv_id,
}
bool CaSupDbFuncs::m_unregister_a(CaDbH *dbhan,
const std::string &s_id,
const std::string &cli_id,
const std::string &src,
const std::string &chan) {
......@@ -199,22 +198,19 @@ bool CaSupDbFuncs::m_unregister_a(CaDbH *dbhan,
std::string stmde;
std::vector<std::string> pars;
if(src.length() > 0 && chan.length() > 0 && s_id.length() > 0 && cli_id.length() > 0) {
stmde = "DELETE FROM activity WHERE srv_id=$1 AND source=$2 AND chan=$3 AND cli_id=$4";
pars.push_back(s_id);
if(src.length() > 0 && chan.length() > 0 && cli_id.length() > 0) {
stmde = "DELETE FROM activity WHERE cli_id=$1 AND source=$2 AND chan=$3 ";
pars.push_back(cli_id);
pars.push_back(src);
pars.push_back(chan);
pars.push_back(cli_id);
}
else if(src.length() > 0 && s_id.length() > 0 && cli_id.length() > 0) {
stmde = "DELETE FROM activity WHERE srv_id=$1 AND source=$2 AND cli_id=$3";
pars.push_back(s_id);
else if(src.length() > 0 && cli_id.length() > 0) {
stmde = "DELETE FROM activity WHERE source=$1 AND cli_id=$2";
pars.push_back(src);
pars.push_back(cli_id);
}
else if(s_id.length() > 0 && cli_id.length() > 0) {
stmde = "DELETE FROM activity WHERE srv_id=$1 AND cli_id=$2";
pars.push_back(s_id);
else if(cli_id.length() > 0) {
stmde = "DELETE FROM activity WHERE cli_id=$1";
pars.push_back(cli_id);
}
......@@ -225,7 +221,6 @@ bool CaSupDbFuncs::m_unregister_a(CaDbH *dbhan,
}
bool CaSupDbFuncs::unregister_activities(CaDbH *dbhan,
const std::string & s_id,
const std::string & cli_id,
const std::string &chan,
const std::list<CuData> &datalist) {
......@@ -236,6 +231,7 @@ bool CaSupDbFuncs::unregister_activities(CaDbH *dbhan,
std::vector<std::string> ids;
for(const CuData &da : datalist) {
if(ok && da.containsKey("ids")) {
printf("CaSupDbFuncs.unregister_activities: adding ids from data %s\n", datos(da));
const std::vector<std::string>& vids = da["ids"].toStringVector();
ids.insert(ids.end(), vids.begin(), vids.end());
}
......@@ -245,8 +241,20 @@ bool CaSupDbFuncs::unregister_activities(CaDbH *dbhan,
}
for(const std::string& id : ids) {
if(ok)
ok = m_unregister_a(dbhan, s_id, id, "", "");
if(ok) {
printf("CaSupDbFuncs.unregister_activities: calling m_unregister_a with s_id %s chan %s\n",
id.c_str(), chan.c_str());
ok = m_unregister_a(dbhan, id, "", "");
}
}
if(cli_id.length() > 0 && ids.size() == 0) {
for(const CuData &da : datalist) {
// call m_unregister_a for each source. If da contains a specific channel use it
// otherwise use global chan. If chan empty, activity is deleted by src regardless
// the chan
if(ok)
ok = m_unregister_a(dbhan, cli_id, da.s("src"), da.containsKey("channel") ? da.s("channel") : chan);
}
}
if(ok)
......
......@@ -29,7 +29,6 @@ public:
bool unregister_instance(CaDbH *h, int id);
bool insert_recover_operation_start(CaDbH *h, int superv_id, int from_srv_id, const std::vector<CuData> *srcs);
bool unregister_activities(CaDbH *dbhan,
const std::string &s_id,
const std::string &cli_id,
const std::string &chan,
const std::list<CuData> &datalist);
......@@ -39,8 +38,10 @@ public:
const std::string &channel,
const std::list<CuData> &datalist);
bool m_unregister_a(CaDbH *dbhan, const std::string& sid, const std::string& cid,
const std::string& src, const std::string& chan);
bool m_unregister_a(CaDbH *dbhan,
const std::string& cid,
const std::string& src,
const std::string& chan);
};
#endif // CASUPDBFUNCS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment