Skip to content

Commit 99dd689

Browse files
committed
adjust OCPL 'Attended' log handling; updates #449
1 parent d0180fe commit 99dd689

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

okapi/services/logs/submit/WebService.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,29 +405,42 @@ private static function _call(OkapiRequest $request)
405405

406406
# Check if already found it (and make sure the user is not the owner).
407407
#
408-
# OCPL forbids logging 'Found it' or "Didn't find" for an already found cache,
409-
# while OCDE allows all kinds of duplicate logs.
408+
# OCPL forbids logging 'Found it', 'Attended' and "Didn't find" for an
409+
# already found/attended cache, while OCDE allows all kinds of duplicate logs.
410+
#
411+
# Duplicate 'Will attend' logs are currently allowed by OCPL code, though
412+
# this may be unintentional and change in the future.
410413

411414
if (
412415
Settings::get('OC_BRANCH') == 'oc.pl'
413-
&& (($logtype == 'Found it') || ($logtype == "Didn't find it"))
416+
&& in_array($logtype, ['Found it', 'Attended', "Didn't find it"])
414417
) {
418+
$matching_logtype = ($logtype == "Didn't find it" ? 'Found it' : $logtype);
415419
$has_already_found_it = Db::select_value("
416420
select 1
417421
from cache_logs
418422
where
419423
user_id = '".Db::escape_string($user['internal_id'])."'
420424
and cache_id = '".Db::escape_string($cache['internal_id'])."'
421-
and type = '".Db::escape_string(Okapi::logtypename2id("Found it"))."'
425+
and type = '".Db::escape_string(Okapi::logtypename2id($matching_logtype))."'
422426
and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true")."
427+
limit 1
428+
/* there should be maximum 1 of these logs, but who knows ... */
423429
");
424430
if ($has_already_found_it) {
425-
throw new CannotPublishException(_(
426-
"You have already submitted a \"Found it\" log entry once. ".
427-
"Now you may submit \"Comments\" only!"
428-
));
431+
throw new CannotPublishException(
432+
$matching_logtype == 'Found it'
433+
? _("You have already submitted a \"Found it\" log entry once. ".
434+
"Now you may submit \"Comments\" only!")
435+
: _("You have already submitted an \"Attended\" log entry once. ".
436+
"Now you may submit \"Comments\" only!")
437+
);
429438
}
430-
if ($user['uuid'] == $cache['owner']['uuid']) {
439+
440+
# OCPL owners are allowed to attend their own events, but not to
441+
# search their own caches.
442+
443+
if ($user['uuid'] == $cache['owner']['uuid'] && $logtype != 'Attended') {
431444
throw new CannotPublishException(_(
432445
"You are the owner of this cache. You may submit ".
433446
"\"Comments\" only!"

0 commit comments

Comments
 (0)