FIX : ModuleBuilder list page derives email trackid from object name (#38906)

The generated list page set $trackid = 'xxxx'.$object->id, where 'xxxx'
is not a NamingContract substitution token. It leaked verbatim into every
generated module and made the mass-emailing trackid collide across modules.

Align it with the card page (myobject_card.php) and core list pages
(comm/propal/list.php => 'pro', societe/list.php => 'thi') by using the
substitutable 'myobject' token, so the trackid derives from the object name.

Addresses #32460 (item 14, email/trackid handling).

Next: push to remote quentin, open upstream PR on Dolibarr/dolibarr:develop
Next: linking #32460 item 14

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
VIAL-GOUTEYRON Quentin 2026-06-21 23:27:34 +02:00 committed by GitHub
parent 4eaa846739
commit d67ac89a65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 1 deletions

View file

@ -177,6 +177,7 @@ For developers:
NEW: Use another hash algorithm v2 based on sha256/hmac for immutable logs (#37725)
NEW: Replace MyObject MyModule occurrences (#38370)
NEW: ModuleBuilder - Allow selecting which optional tabs (contact, note, document, agenda) are generated for an object (#38570)
FIX: ModuleBuilder - Generated list page derives the email trackid from the object name instead of the leftover 'xxxx' placeholder (#32460)
NEW: add hooks in reception card (#37214)
NEW: add new hook in BonPrelevement::EnregDestinataireSEPA() function (#37419)
NEW: Add hook selectForFormsListUrl in Form::selectForForms (#37447)

View file

@ -603,7 +603,7 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sort
$topicmail = "SendMyObjectRef";
$modelmail = "myobject";
$objecttmp = new MyObject($db);
$trackid = 'xxxx'.$object->id;
$trackid = 'myobject'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($search_all) {

View file

@ -154,6 +154,32 @@ class NamingContractTest extends \PHPUnit\Framework\TestCase
$this->assertSame($content, $nc->applyTo($content)); // @phpstan-ignore method.notFound
}
// ── Generated list template — trackid placeholder (#32460 item 14) ────
/**
* The generated list page must derive its e-mail trackid from the object name,
* exactly like the card page (myobject_card.php) and core list pages
* (comm/propal/list.php => 'pro', societe/list.php => 'thi'). The legacy literal
* 'xxxx' placeholder is not a substitution token, so it used to leak verbatim into
* every generated module and collide across modules in the mass e-mailing trackid.
* Regression guard for #32460 (item 14, e-mail/trackid handling).
*
* @return void
*/
public function testListTemplateTrackidIsSubstituted(): void
{
$template = file_get_contents(dirname(__FILE__) . '/../../htdocs/modulebuilder/template/myobject_list.php');
$this->assertIsString($template); // @phpstan-ignore method.notFound
// The non-substitutable 'xxxx' placeholder must no longer carry the trackid.
$this->assertStringNotContainsString("\$trackid = 'xxxx'", $template, "The list template must not carry the 'xxxx' trackid placeholder"); // @phpstan-ignore method.notFound
// After generation the trackid derives from the object name, like the card page and core.
$nc = new NamingContract('invoice', 'request');
$result = $nc->applyTo($template);
$this->assertStringContainsString("\$trackid = 'request'.\$object->id;", $result, 'Generated trackid must derive from the object name'); // @phpstan-ignore method.notFound
}
// ── NamingContract — applyToFilename ─────────────────────────────────
/**