User tests: Successful: Unsuccessful:
Pull Request for Issue #35071 .
Add the attachments column to the mail template object when creating a new record with $db->insertObject
in Joomla\CMS\Mail\MailTemplate::createTemplate
.
As a column with data type TEXT, the attachments
column of the #__mail_templates
doesn't have a default value, see PR #27937 and PR #17860 and also https://stackoverflow.com/questions/3466872/why-cant-a-text-column-have-a-default-value-in-mysql for the reasons.
Therefore a property for that column has to exist in the object when creating a new record with $db->insertObject
.
This pull request (PR) only fixes the SQL error reported by the issue. It does not add the ability to specify attachments when using Joomla\CMS\Mail\MailTemplate::createTemplate
or Joomla\CMS\Mail\MailTemplate::updateTemplate
.
This could and in my opinion should be done with a future PR with a suitable milestone, e.g. 4.1.
use Joomla\CMS\Mail\MailTemplate;
$result = MailTemplate::createTemplate(
'com_config.test_mail_' . date('Ymd_His'),
'COM_CONFIG_SENDMAIL_SUBJECT',
'COM_CONFIG_SENDMAIL_BODY',
["sitename","method"]
);
echo $result ? 'Mail template created.' : 'creating mail template failed.';
Result: See section "Actual result BEFORE applying this Pull Request" below.
Apply the patch of this PR.
Go again to the site (frontend) or if still there reload the page.
Result: See 1st screenshot in section "Expected result AFTER applying this Pull Request" below.
Result: See 2nd screenshot in section "Expected result AFTER applying this Pull Request" below.
Hint: The created mail template will not be shown in backend due to the way how mail templates work, as there is no language string for the dynamically created template_id
. But this was necessary in order not to violate the primary key uniqueness.
Result: Editing mail templates works.
Creating mail templates programmatically works:
With every page load a new record has been created:
None.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Status | Pending | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-08-09 10:39:46 |
Closed_By | ⇒ | wilsonge | |
Labels |
Added:
?
|
Thanks
bit late but tested fine.
I know this is closed but shouldn't the createTemplate have the extension element included?
Thanks!