aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Čukić <[email protected]>2016-12-21 11:45:28 +0000
committerIvan Čukić <[email protected]>2016-12-21 11:45:28 +0000
commit4329c08c474f02f2c4e28605f61926f02b0388e1 (patch)
treee82b0fd6cfba7f9706f20115217dbaa506c1d43b
parentc835cc51038f017ccb9f274a035385edfdaf137c (diff)
Support unlinking from any activity
-rw-r--r--src/service/plugins/sqlite/ResourceLinking.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/service/plugins/sqlite/ResourceLinking.cpp b/src/service/plugins/sqlite/ResourceLinking.cpp
index 44343b0..0c10421 100644
--- a/src/service/plugins/sqlite/ResourceLinking.cpp
+++ b/src/service/plugins/sqlite/ResourceLinking.cpp
@@ -73,6 +73,10 @@ void ResourceLinking::LinkResourceToActivity(QString initiatingAgent,
return;
}
+ if (usedActivity == ":any") {
+ usedActivity = ":global";
+ }
+
Q_ASSERT_X(!initiatingAgent.isEmpty(),
"ResourceLinking::LinkResourceToActivity",
"Agent shoud not be empty");
@@ -141,13 +145,21 @@ void ResourceLinking::UnlinkResourceFromActivity(QString initiatingAgent,
"Resource shoud not be empty");
Utils::prepare(resourcesDatabase(), unlinkResourceFromActivityQuery,
- QStringLiteral(
- "DELETE FROM ResourceLink "
- "WHERE "
- "usedActivity = COALESCE(:usedActivity , '') AND "
- "initiatingAgent = COALESCE(:initiatingAgent , '') AND "
- "targettedResource = COALESCE(:targettedResource, '') "
- ));
+ usedActivity == ":any" ?
+ QStringLiteral(
+ "DELETE FROM ResourceLink "
+ "WHERE "
+ "initiatingAgent = COALESCE(:initiatingAgent , '') AND "
+ "targettedResource = COALESCE(:targettedResource, '') "
+ ) :
+ QStringLiteral(
+ "DELETE FROM ResourceLink "
+ "WHERE "
+ "usedActivity = COALESCE(:usedActivity , '') AND "
+ "initiatingAgent = COALESCE(:initiatingAgent , '') AND "
+ "targettedResource = COALESCE(:targettedResource, '') "
+ )
+ );
DATABASE_TRANSACTION(resourcesDatabase());
@@ -219,6 +231,7 @@ bool ResourceLinking::validateArguments(QString &initiatingAgent,
{
// Validating targetted resource
if (targettedResource.isEmpty()) {
+ qDebug() << "Resource is invalid -- empty";
return false;
}
@@ -230,6 +243,7 @@ bool ResourceLinking::validateArguments(QString &initiatingAgent,
QFileInfo file(targettedResource);
if (!file.exists()) {
+ qDebug() << "Resource is invalid -- the file does not exist";
return false;
}
@@ -252,7 +266,10 @@ bool ResourceLinking::validateArguments(QString &initiatingAgent,
// If the activity is not empty and the passed activity
// does not exist, cancel the request
if (!usedActivity.isEmpty()
+ && usedActivity != ":global"
+ && usedActivity != ":any"
&& !StatsPlugin::self()->listActivities().contains(usedActivity)) {
+ qDebug() << "Activity is invalid, it does not exist";
return false;
}