Skip to content

Log types as constants (andrixnet's refactoring) - #658

Merged
hxdimpf merged 3 commits into
opencaching:masterfrom
OpencachingDeutschland:up/log-type-constants
Oct 19, 2026
Merged

hxdimpf merged 3 commits into
opencaching:masterfrom
OpencachingDeutschland:up/log-type-constants

Conversation

@hxdimpf

@hxdimpf hxdimpf commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

@andrixnet's change from his log_types branch (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/geocaches and caches/search.

Two commits:

  1. andrixnet's commit, cherry-picked onto master. It conflicted with OCPL: needs_maintenance2=false creates a 'Maintenance performed' log #643 in logs/submit and logs/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 missing Okapi:: before LOGTYPE_NAME_ARCHIVED in the conflicting line.
  2. A follow-up commit so that this stays a pure refactoring, with no change to what clients see:
    • LOGTYPE_NAME_NEEDMAINTENANCE stays 'Needs maintenance'. 'Needs Maintenance' would change the documented name in the logs/entries output.
    • logtypeid2name(14) returns the name 'Locked' as before, not the ID 13.
    • logs/capabilities: the typo Okapi::OGTYPE_NAME_COMMENT is fixed; it made every call that reaches can_set_needs_maintenance fail.
    • 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.
    • Trailing whitespace is removed from the added lines.

The one addition is 'Locked, invisible' => 14 in 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:

read-only --write
OCDE 11 passed, 0 failed 12 passed, 0 failed
OCPL, MariaDB 10.11 11 passed, 0 failed 13 passed, 0 failed
OCPL, MariaDB 10.0 11 passed, 0 failed 13 passed, 0 failed

logs/capabilities was checked on all three. On both OCPL installations logs/submit, edit and delete passed. On OCDE log submission is skipped, since the test OKAPI runs without the website there. All changed PHP files pass php -l on PHP 7.4. A check that every Okapi:: 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.

andrixnet and others added 2 commits October 19, 2026 15:57
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 jrmajor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))."',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the IDs are available in named constants, we can just use them directly:

Suggested change
'".Db::escape_string(Okapi::logtypename2id(Okapi::LOGTYPE_NAME_FOUNDIT))."',
'".Db::escape_string(Okapi::LOGTYPE_ID_FOUNDIT)."',

Comment thread okapi/core/Okapi.php Outdated

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
@hxdimpf

hxdimpf commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @jrmajor! Both applied in 676d8cf. The ID constants are now used directly in all seven places where logtypename2id() was called with a name constant (caches/geocaches, caches/search, logs/entries), not just the line you marked. Tested again on OCDE and both OCPL installations, 0 failures.

@andrixnet, I'd still like your OK on the follow-up commit (7a854f6) before this is merged.

@andrixnet

Copy link
Copy Markdown
Contributor

Thank you all for your support.
This is what I inteded, to improve the code with clear definitions instead of hardcoded literals. No change intended to functioning logic or features.

I look over the diff and looks good. I hope we covered all hardcoded uses. :-)

@hxdimpf

hxdimpf commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants