Skip to content

fix(submissions): derive source language dynamically, target the other 5#228

Merged
JohnRDOrazio merged 1 commit into
mainfrom
fix/submission-publish-dynamic-source-lang
Jun 16, 2026
Merged

fix(submissions): derive source language dynamically, target the other 5#228
JohnRDOrazio merged 1 commit into
mainfrom
fix/submission-publish-dynamic-source-lang

Conversation

@JohnRDOrazio

@JohnRDOrazio JohnRDOrazio commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace the hardcoded ['it','es','fr','pt','de'] target list and $translations['en'] = $source_id mapping in cdcf_enqueue_translations_for_submission() with a dynamic resolution: source language comes from pll_get_post_language() on the source post, the target set is pll_languages_list() - source_lang, and the Polylang group is keyed under the actual source language.
  • Adds a failing-first regression test (`test_enqueue_translations_uses_dynamic_source_language_for_non_english_source`) covering an ES-source submission: asserts the atomic save receives {es: source, en: ..., it: ..., fr: ..., pt: ..., de: ...} and that every non-source language (including EN) is enqueued.
  • Renames \$en_post_id\$source_post_id and updates the docblock + error_log lines to match the new semantics. Same atomic shape, same deferred-to-shutdown call site as fix(submissions): defer translation enqueue to shutdown action #227.

Production trigger

community_project 1534 ("Enciclopedia Católica") was submitted in Spanish. The hook created siblings for IT/FR/PT/DE only — EN was missing from the hardcoded target list, ES was skipped as "already linked" because the source already carried that language, and the source post was mis-keyed as the EN translation in the atomic save. Polylang rejected the malformed {en: 1534, ...} map → empty group on every post. Recovery on production after this PR merges + deploys: link the existing 5 siblings + create EN sibling via /cdcf/v1/translate.

Test plan

  • composer test --working-dir=wordpress/themes/cdcf-headless — 579/579 pass, including the new ES-source test
  • Verified RED first: the new test failed against the pre-fix code with the exact map diff (en=>42 instead of es=>42)
  • After merge: deploy with gh workflow run deploy.yml -f environment=production, then publish a fresh non-English public submission and verify (a) translations are created for all 5 OTHER languages including EN AND (b) the Polylang group is linked across all 6 siblings

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed translation sibling generation to dynamically detect the source language instead of assuming English, enabling correct multi-language submission workflows for any configured language.
  • Tests

    • Added test coverage for non-English source language scenarios in translation submission handling.

cdcf_enqueue_translations_for_submission() hardcoded the source as
English: target_langs = ['it','es','fr','pt','de'] (no en), and
$translations['en'] = $source_id. A non-English public submission
got siblings for IT/FR/PT/DE only — EN was missing from the target
list, the source language was silently skipped as "already linked",
and the source post was mis-keyed as the EN translation, so
pll_save_post_translations was handed an invalid {en: source, ...}
map and rejected it → empty Polylang group on every post.

Now reads pll_get_post_language() for the source and pll_languages_list()
for the configured set, computes target_langs = all - source_lang,
and keys the map under the actual source language. Same atomic
shape, same deferred-to-shutdown call site from #227.

Production trigger 2026-06-16: community_project 1534 ("Enciclopedia
Católica") submitted in Spanish; group came out empty, siblings
1552/1553/1554/1555 (it/fr/pt/de) created but no EN.

Parameter renamed $en_post_id → $source_post_id and the docblock
+ error_log lines updated to match the new semantics.

Added regression test covering the ES-source case end-to-end:
asserts pll_save_post_translations gets {es: source, en:..., it:...,
fr:..., pt:..., de:...} and cdcf_enqueue_translation is called for
each non-source language (including en). The wp-cron-fallback test
also gains pll_get_post_language + pll_languages_list stubs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

cdcf_enqueue_translations_for_submission() is updated to derive the source language dynamically via pll_get_post_language() (with pll_default_language() fallback) instead of assuming English. The parameter is renamed from $en_post_id to $source_post_id, target languages are computed as all Polylang languages minus the source, and all Phase 1–3 references to the former English-specific variable are replaced. Test stubs and a new regression test for a Spanish-source post are added.

Changes

Dynamic Polylang Source Language Fan-Out

Layer / File(s) Summary
Function signature, docblock, and language derivation
wordpress/themes/cdcf-headless/includes/admin/submission-lifecycle.php
Parameter renamed to $source_post_id; docblock updated; function now validates additional Polylang functions, resolves $source_post, derives $source_lang with fallback, builds $target_langs by excluding the source, and pre-seeds the translation group map under the computed $source_lang key.
Phase 1–3 sibling creation, logging, and enqueueing
wordpress/themes/cdcf-headless/includes/admin/submission-lifecycle.php
Draft sibling post_title is taken from $source_post; no-op early exit, rollback log, success log, and Phase 3 background job enqueue all reference $source_post_id instead of the former $en_post_id.
Test stub updates and non-English source regression test
wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php
stubCommonFunctions() gains pll_get_post_language ('en') and pll_languages_list (six languages); wp-cron fallback test receives matching stubs; new test test_enqueue_translations_uses_dynamic_source_language_for_non_english_source stubs source language as es and asserts a single pll_save_post_translations call with an es-keyed six-language map and five enqueue calls covering all non-source languages including en.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • CatholicOS/cdcf-website#203: Modifies the same cdcf_enqueue_translations_for_submission() Polylang translation-group map/save and sibling-enqueue flow that this PR corrects.
  • CatholicOS/cdcf-website#171: Also changes how the Polylang source language is resolved, targeting cdcf_process_translation() prompt source-language selection instead of the submission lifecycle fan-out.
  • CatholicOS/cdcf-website#208: Adds a Phase 0 for attachment siblings inside cdcf_enqueue_translations_for_submission() that depends on the same language-map setup corrected in this PR.

Poem

🐇 Hoppity-hop, no more English alone,
The source lang is found — whatever it's known!
Spanish or French, or German or twee,
Siblings sprout up for all languages, see?
The test says "¡sí, es!" and the map fills in right,
Dynamic dispatch by Polylang's bright light. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main fix: dynamic source language resolution instead of hardcoded English, with target languages computed from all configured languages except the source.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/submission-publish-dynamic-source-lang

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 10 complexity

Metric Results
Complexity 10

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...f-headless/includes/admin/submission-lifecycle.php 83.33% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php (1)

381-440: 💤 Low value

Solid regression test for the Spanish-source scenario.

The assertions correctly verify that:

  1. pll_save_post_translations receives the map keyed by the actual source language (es)
  2. All five non-source languages (including en) are enqueued for translation
  3. The source language is not re-enqueued against itself

Regarding the static analysis hint about the unused $source_id parameter on line 420: this is intentional since the closure must match the cdcf_enqueue_translation signature. If you want to silence the PHPMD warning, you could prefix it with an underscore ($_source_id), but it's minor and entirely optional.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php` around
lines 381 - 440, To silence the PHPMD static analysis warning about the unused
parameter, rename the `$source_id` parameter in the closure within the
`Functions\when('cdcf_enqueue_translation')->alias()` call to `$_source_id`.
This convention indicates that the parameter is intentionally unused but must be
present to match the expected function signature.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php`:
- Around line 381-440: To silence the PHPMD static analysis warning about the
unused parameter, rename the `$source_id` parameter in the closure within the
`Functions\when('cdcf_enqueue_translation')->alias()` call to `$_source_id`.
This convention indicates that the parameter is intentionally unused but must be
present to match the expected function signature.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dcb8ee41-fbdf-45c2-a5af-4851838c6eba

📥 Commits

Reviewing files that changed from the base of the PR and between a4eca45 and 00854c4.

📒 Files selected for processing (2)
  • wordpress/themes/cdcf-headless/includes/admin/submission-lifecycle.php
  • wordpress/themes/cdcf-headless/tests/SubmissionLifecycleTest.php

@JohnRDOrazio JohnRDOrazio merged commit 86cc615 into main Jun 16, 2026
13 checks passed
@JohnRDOrazio JohnRDOrazio deleted the fix/submission-publish-dynamic-source-lang branch June 16, 2026 19:52
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.

2 participants