Mercurial > prosody-modules
comparison mod_http_xep227/mod_http_xep227.lua @ 4871:029ae3c29683
mod_http_xep227: Handle nil/errors opening archive stores
This matches how mod_mam opens archive stores. nil can be returned when there
is no data in the store yet (it doesn't exist).
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 16 Jan 2022 15:01:20 +0000 |
parents | d8a0a8dcdc0d |
children | bc54f651b5a4 |
comparison
equal
deleted
inserted
replaced
4870:d8a0a8dcdc0d | 4871:029ae3c29683 |
---|---|
118 | 118 |
119 for store_name in it.values(selected_stores.archive) do | 119 for store_name in it.values(selected_stores.archive) do |
120 local source_driver = get_config_driver(store_name, session.host); | 120 local source_driver = get_config_driver(store_name, session.host); |
121 local source_archive = source_driver:open(store_name, "archive"); | 121 local source_archive = source_driver:open(store_name, "archive"); |
122 local dest_archive = xep227_driver:open_xep0227(store_name, "archive", user_xml); | 122 local dest_archive = xep227_driver:open_xep0227(store_name, "archive", user_xml); |
123 local count, errs = 0, 0; | 123 local results_iter, results_err = source_archive:find(username); |
124 for id, item, when, with in source_archive:find(username) do | 124 if results_iter then |
125 local ok, err = dest_archive:append(username, id, item, when, with); | 125 local count, errs = 0, 0; |
126 if ok then | 126 for id, item, when, with in results_iter do |
127 count = count + 1; | 127 local ok, err = dest_archive:append(username, id, item, when, with); |
128 else | 128 if ok then |
129 module:log("warn", "Error: %s", err); | 129 count = count + 1; |
130 errs = errs + 1; | 130 else |
131 end | 131 module:log("warn", "Error: %s", err); |
132 if ( count + errs ) % 100 == 0 then | 132 errs = errs + 1; |
133 module:log("info", "%d items migrated, %d errors", count, errs); | 133 end |
134 end | 134 if ( count + errs ) % 100 == 0 then |
135 module:log("info", "%d items migrated, %d errors", count, errs); | |
136 end | |
137 end | |
138 elseif results_err then | |
139 module:log("warn", "Unable to read from '%s': %s", store_name, results_err); | |
140 return 500; | |
135 end | 141 end |
136 end | 142 end |
137 | 143 |
138 local xml_data = user_xml:get_user_xml(username, session.host); | 144 local xml_data = user_xml:get_user_xml(username, session.host); |
139 | 145 |
209 | 215 |
210 for store_name in it.values(selected_stores.archive) do | 216 for store_name in it.values(selected_stores.archive) do |
211 local source_archive = xep227_driver:open_xep0227(store_name, "archive", user_xml); | 217 local source_archive = xep227_driver:open_xep0227(store_name, "archive", user_xml); |
212 local dest_driver = get_config_driver(store_name, session.host); | 218 local dest_driver = get_config_driver(store_name, session.host); |
213 local dest_archive = dest_driver:open(store_name, "archive"); | 219 local dest_archive = dest_driver:open(store_name, "archive"); |
214 local count, errs = 0, 0; | 220 local results_iter, results_err = source_archive:find(username); |
215 for id, item, when, with in source_archive:find(username) do | 221 if results_iter then |
216 local ok, err = dest_archive:append(username, id, item, when, with); | 222 local count, errs = 0, 0; |
217 if ok then | 223 for id, item, when, with in source_archive:find(username) do |
218 count = count + 1; | 224 local ok, err = dest_archive:append(username, id, item, when, with); |
219 else | 225 if ok then |
220 module:log("warn", "Error: %s", err); | 226 count = count + 1; |
221 errs = errs + 1; | 227 else |
222 end | 228 module:log("warn", "Error: %s", err); |
223 if ( count + errs ) % 100 == 0 then | 229 errs = errs + 1; |
224 module:log("info", "%d items migrated, %d errors", count, errs); | 230 end |
225 end | 231 if ( count + errs ) % 100 == 0 then |
232 module:log("info", "%d items migrated, %d errors", count, errs); | |
233 end | |
234 end | |
235 elseif results_err then | |
236 module:log("warn", "Unable to read from '%s': %s", store_name, results_err); | |
237 return 500; | |
226 end | 238 end |
227 end | 239 end |
228 | 240 |
229 return 200; | 241 return 200; |
230 end | 242 end |