Repository navigation
Log types as constants (andrixnet's refactoring) - #658
Conversation
Follow-up to the constants commit, so that it stays a pure refactoring: - LOGTYPE_NAME_NEEDMAINTENANCE stays 'Needs maintenance' (the documented OKAPI name; 'Needs Maintenance' would change logs/entries output). - logtypeid2name(14) returns the name 'Locked' as before, not the ID 13. - logs/capabilities: fix the LOGTYPE_NAME_COMMENT typo (OGTYPE_...), which made every call that reaches can_set_needs_maintenance fail; on OCPL disable only the current status log type again (a temporarily unavailable cache can still be archived). - Remove trailing whitespace from the added lines.
jrmajor
left a comment
There was a problem hiding this comment.
Apart from the nits above, looks good to me.
| and cl.type in ( | ||
| '".Db::escape_string(Okapi::logtypename2id("Found it"))."', | ||
| '".Db::escape_string(Okapi::logtypename2id("Attended"))."' | ||
| '".Db::escape_string(Okapi::logtypename2id(Okapi::LOGTYPE_NAME_FOUNDIT))."', |
There was a problem hiding this comment.
Now that the IDs are available in named constants, we can just use them directly:
| '".Db::escape_string(Okapi::logtypename2id(Okapi::LOGTYPE_NAME_FOUNDIT))."', | |
| '".Db::escape_string(Okapi::LOGTYPE_ID_FOUNDIT)."', |
|
|
||
| self::LOGTYPE_NAME_MOVED => self::LOGTYPE_ID_MOVED, | ||
| self::LOGTYPE_NAME_NEEDMAINTENANCE => self::LOGTYPE_ID_NEEDMAINTENANCE, # submittable by type=Comment&needs_maintenance2=true | ||
| self::LOGTYPE_NAME_MADEMAINTENANCE => self::LOGTYPE_ID_MADEMAINTENANCE, # see https://github.com/opencaching/okapi/issues/548 |
There was a problem hiding this comment.
| self::LOGTYPE_NAME_MADEMAINTENANCE => self::LOGTYPE_ID_MADEMAINTENANCE, # see https://github.com/opencaching/okapi/issues/548 | |
| self::LOGTYPE_NAME_MADEMAINTENANCE => self::LOGTYPE_ID_MADEMAINTENANCE, # submittable by type=Comment&needs_maintenance2=false |
…ormed From the review of opencaching#658: Okapi::logtypename2id() of a LOGTYPE_NAME_* constant is just the matching LOGTYPE_ID_* constant (7 places), and 'Maintenance performed' is submittable via needs_maintenance2=false since opencaching#643.
|
Thanks, @jrmajor! Both applied in 676d8cf. The ID constants are now used directly in all seven places where @andrixnet, I'd still like your OK on the follow-up commit (7a854f6) before this is merged. |
|
Thank you all for your support. I look over the diff and looks good. I hope we covered all hardcoded uses. :-) |
|
Thanks, @andrixnet! I checked what's left: the remaining literals are comments, error messages, docs, cache status values ('Archived', 'Temporarily unavailable') and the GPX attribute name "Needs maintenance", none of them log types in code. So yes, all hardcoded uses are covered. Merging. |
@andrixnet's change from his
log_typesbranch (167a657, 2026-09-19), brought onto the current master as he asked, with him as the author of the main commit. A preparation for #637: no new features.What it does: the log type IDs and names are defined once as constants in
Okapi(LOGTYPE_ID_*,LOGTYPE_NAME_*, with a link to the wiki page on log types). The services use the constants instead of literal names and IDs:logs/submit,edit,capabilities,entries,LogsCommon,caches/geocachesandcaches/search.Two commits:
logs/submitandlogs/capabilities, which came later. I kept OCPL: needs_maintenance2=false creates a 'Maintenance performed' log #643's logic and wrote its names with the new constants. This also fixed a missingOkapi::beforeLOGTYPE_NAME_ARCHIVEDin the conflicting line.LOGTYPE_NAME_NEEDMAINTENANCEstays'Needs maintenance'.'Needs Maintenance'would change the documented name in thelogs/entriesoutput.logtypeid2name(14)returns the name'Locked'as before, not the ID 13.logs/capabilities: the typoOkapi::OGTYPE_NAME_COMMENTis fixed; it made every call that reachescan_set_needs_maintenancefail.logs/capabilities, on OCPL: again only the log type of the current status is disabled. Otherwise a temporarily unavailable cache could no longer be archived.The one addition is
'Locked, invisible' => 14in the internal table of non-submittable types. The public output for type 14 stays'Locked'.Tested with the suite from #653, on an OCDE installation and two OCPL installations (the official 2018 devel dump with all updates, on MariaDB 10.11 and on MariaDB 10.0), PHP 8.2-FPM behind Apache:
--writelogs/capabilitieswas checked on all three. On both OCPL installationslogs/submit,editanddeletepassed. On OCDE log submission is skipped, since the test OKAPI runs without the website there. All changed PHP files passphp -lon PHP 7.4. A check that everyOkapi::constant used in the code is defined found none missing.@andrixnet: could you check that this is what you intended, especially the follow-up commit? @kojoty, @jrmajor, @stefopl: reviews welcome.