Skip to content

Conversation

@JonBendtsen
Copy link
Contributor

@JonBendtsen JonBendtsen commented Nov 9, 2025

FIX #32457 adding tms and datec to email templates

This PR adds tms and datec to email templates. It's added but not shown on creation and modify, where as it is shown when just listing email templates. The fields already existed in the database. A few more hurl tests are introduced to ensure that API post and create are not done with wrong fields.

This PR also adds id="" fields to the forms and the tables - so it easier to find them if you inspect the html.

This PR fixes #32457 but changing the Code column to Label which matches what you get in the json using the API

@JonBendtsen
Copy link
Contributor Author

build STILL complains about non escaped string, but you clearly see that it is being escaped

1) CodingPhpTest::testPHP with data set #170 (array('mails_templates.php', '/home/travis/build/Dolibarr/d.../admin', 'admin', 'admin/mails_templates.php', '/home/travis/build/Dolibarr/d...es.php', '', '', 'file'))
Found non escaped string in building of a sql request (case 3) in admin/mails_templates.php: $sql .= '"'.$db->escap - Bad.
Failed asserting that false is true.

Why?

@JonBendtsen
Copy link
Contributor Author

@hregis You commented on my other PR with changes to the database, so maybe you can help me here with the build system? Why does it complain about a non escaped string when it clearly says escape in the string it complains about?

@JonBendtsen JonBendtsen force-pushed the adding_tms_datec_to_email_templates branch from 0bfbe2f to cc12caf Compare November 9, 2025 11:59
@hregis
Copy link
Contributor

hregis commented Nov 9, 2025

@JonBendtsen don't use dol_print_date
Check another code to have an example

@JonBendtsen
Copy link
Contributor Author

@JonBendtsen don't use dol_print_date Check another code to have an example

why not? it is a function in Dolibarr?

And I even escape the output?

What other code to check?

@JonBendtsen
Copy link
Contributor Author

Change Code to label to match the database content

image

AND this also matches what is shown in the json from the API

{
  "module": "",
  "id": 59,
  "entity": 1,
  "contacts_ids_internal": null,
  "model_pdf": null,
  "date_creation": 1762687782,
  "tms": "2025-11-09 12:29:55",
  "totalpaid_multicurrency": null,
  "type_template": "all",
  "datec": 2025,
  "active": 1,
  "enabled": "1",
  "defaultfortype": 0,
  "label": "1229",
  "fk_user": 0,
  "private": 0,
  "topic": "1229 edit",
  "content": "1229 edit",
  "content_lines": "",
  "lang": "",
  "joinfiles": 0,
  "email_from": "",
  "email_to": "",
  "email_tocc": "",
  "email_tobcc": "",
  "position": 1
}

Fixes #29116

@hregis
Copy link
Contributor

hregis commented Nov 9, 2025

@JonBendtsen use this code, and remove the field "tms"

$now = dol_now();

.......

$sql .= "'".$db->idate(now)."'";

@JonBendtsen
Copy link
Contributor Author

@JonBendtsen use this code, and remove the field "tms"

I replaced tms with Modif. Date something I find valuable to know when I edited the field

@JonBendtsen
Copy link
Contributor Author

now using idate in almost all places @hregis

@hregis
Copy link
Contributor

hregis commented Nov 9, 2025

@JonBendtsen What I meant was that the SQL server should handle the timestamp of the "tms" field. The "tms" field is only used in SELECT statements.

@JonBendtsen
Copy link
Contributor Author

JonBendtsen commented Nov 9, 2025

@JonBendtsen What I meant was that the SQL server should handle the timestamp of the "tms" field. The "tms" field is only used in SELECT statements.

Okay, but didn't both you @hregis and @eldy state that you wanted to shift away from letting the database server handle timestamps since the database server might be in a different time zone?

@hregis
Copy link
Contributor

hregis commented Nov 9, 2025

@JonBendtsen For datec we use dol_now, but for tms we let the SQL server handle it.

@hregis
Copy link
Contributor

hregis commented Nov 9, 2025

@JonBendtsen i send a fix for the travis error : #36195

@eldy
Copy link
Member

eldy commented Nov 9, 2025

@JonBendtsen For datec we use dol_now, but for tms we let the SQL server handle it.

In a future we will have to manage the tms field in php code too. Just not the current priority.

@eldy
Copy link
Member

eldy commented Nov 9, 2025

@JonBendtsen For datec we use dol_now, but for tms we let the SQL server handle it.

In a future we will have to manage the tms field in php code too. Just not the current priority, so for the moment we must foll[own regis comment: datec using php and tms still using current timestamp (with in mind that it will be managed by php in future).

$tabname = array();
$tabname[25] = MAIN_DB_PREFIX."c_email_templates";

// Used by the GUI during creation so we don't ask the user to fill in tms and datec
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to introduce another table.
We know that tms and datec are date update and creation and should not be requested.
We can just add a hard coded if on this 2 fields when we forge the form to not show them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eldy requested changes has been made, it builds cleanup and test works

@eldy eldy added the Discussion Some questions or discussions are opened and wait answers of author or other people to be processed label Nov 9, 2025
@JonBendtsen JonBendtsen force-pushed the adding_tms_datec_to_email_templates branch from f725f0f to 52b1215 Compare November 9, 2025 18:42
@JonBendtsen
Copy link
Contributor Author

adding

image

After adding

image

@JonBendtsen
Copy link
Contributor Author

editing

image

after edit

image

@JonBendtsen JonBendtsen marked this pull request as ready for review November 9, 2025 21:04
@hregis
Copy link
Contributor

hregis commented Nov 9, 2025

@JonBendtsen

You're told not to modify TMS, and you modify TMS anyway!
How do you have to tell you?

@JonBendtsen
Copy link
Contributor Author

JonBendtsen commented Nov 9, 2025

@JonBendtsen

You're told not to modify TMS, and you modify TMS anyway! How do you have to tell you?

@hregis Please comment in the code the line you mean - that is much easier to find the line you think is erroneous

if (GETPOST($keycode) == '' && $keycode != 'langcode') {
if ($keycode == 'datec') {
$sql .= "'".$db->idate($now)."'";
} elseif ($keycode == 'tms') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hregis you probably mean this line nr 439 - 441

This is during

		if ($ok && GETPOST('actionadd')) {

in line 396, meaning this is during INSERT, and the configuration of the tms field is
image

So it only uses CURRENT_TIMESTAMP() during update, not during INSERT. So if I remove the tms line, then it does not get a value in tms, and I'd argue that creation of an object is a modification of the current state.

@hregis
Copy link
Contributor

hregis commented Nov 10, 2025

@JonBendtsen remove "datec" from the update function, datec is never update

@hregis
Copy link
Contributor

hregis commented Nov 10, 2025

@JonBendtsen

1 remove tms
2 use datec only in create and select

@JonBendtsen
Copy link
Contributor Author

@JonBendtsen

1 remove tms 2 use datec only in create and select

This is the new INSERT line from dolibarr.log - no tms

sql=INSERT INTO llx_c_email_templates (label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content,datec,entity, active, enabled) VALUES('001912', '', 'all', null, 0, 1, '001912', null, 0, 0, '001912', '2025-11-10 19:13:07', 1, 1, 1)

But, the database still has a value in the tms column?
image

Is that the expected?
image

@JonBendtsen
Copy link
Contributor Author

latest hurl tests


JonSweet16:hurl jonbendtsen$ ./run.sh 
----- Run hurl test on APIs ---
First we run tests that do not require authentication
Success gui/00_HOME.hurl (1 request(s) in 44 ms)
Success api/00_foobar.hurl (1 request(s) in 49 ms)
Success api/00_explorer.hurl (1 request(s) in 53 ms)
Success api/status/00_status.hurl (1 request(s) in 61 ms)
Success public/payment/00_payment_newpayment.hurl (1 request(s) in 73 ms)
Success public/onlinesign/00_onlinesign_newonlinesign.hurl (1 request(s) in 75 ms)
Success api/login/00_login_POST.hurl (1 request(s) in 1065 ms)
Success api/login/00_login_GET.hurl (1 request(s) in 1066 ms)
--------------------------------------------------------------------------------
Executed files:    8
Executed requests: 8 (7.5/s)
Succeeded files:   8 (100.0%)
Failed files:      0 (0.0%)
Duration:          1067 ms

Now we are ready to run API tests that do require authentication
Success api/status/10_status.hurl (1 request(s) in 84 ms)
Success api/setup/10_setup_company.hurl (1 request(s) in 483 ms)
Success api/setup/10_setup_conf.hurl (1 request(s) in 490 ms)
Success api/users/10_groups.hurl (15 request(s) in 3059 ms)
Success api/mailings/10_mailings.hurl (34 request(s) in 3138 ms)
Success api/users/10_users.hurl (17 request(s) in 3354 ms)
Success api/emailtemplates/10_emailtemplates.hurl (23 request(s) in 3659 ms)
Success api/contracts/10_contracts.hurl (22 request(s) in 3915 ms)
Success api/warehouses/10_warehouses.hurl (34 request(s) in 4543 ms)
Success api/setup/10_setup_modules.hurl (14 request(s) in 5168 ms)
--------------------------------------------------------------------------------
Executed files:    10
Executed requests: 162 (31.3/s)
Succeeded files:   10 (100.0%)
Failed files:      0 (0.0%)
Duration:          5172 ms

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

Labels

Discussion Some questions or discussions are opened and wait answers of author or other people to be processed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WISH: date column for last modified on page with Email templates for automatic notifications

3 participants