Changeset

8022:05e201468f27

mod_storage_internal: Add support for removing archived items
author Kim Alvefur <zash@zash.se>
date Fri, 31 Mar 2017 17:48:50 +0200
parents 8021:83f18982bcfd
children 8023:5a9d491cc714
files plugins/mod_storage_internal.lua
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_storage_internal.lua	Fri Mar 31 17:47:06 2017 +0200
+++ b/plugins/mod_storage_internal.lua	Fri Mar 31 17:48:50 2017 +0200
@@ -120,4 +120,23 @@
 	end, count;
 end
 
+function archive:delete(username, query)
+	if not query or next(query) == nil then
+		return datamanager.list_store(username, host, self.store, nil);
+	end
+	for k in pairs(query) do
+		if k ~= "end" then return nil, "unsupported-query-field"; end
+	end
+	local items, err = datamanager.list_load(username, host, self.store);
+	if not items then return items, err; end
+	items = array(items);
+	items:filter(function (item)
+		return item.when > query["end"];
+	end);
+	local count = #items;
+	local ok, err = datamanager.list_store(username, host, self.store, items);
+	if not ok then return ok, err; end
+	return count;
+end
+
 module:provides("storage", driver);