No Code Attached Yet bug
avatar garkell
garkell
23 Dec 2022

Steps to reproduce the issue

Create a simple component with an install script containing a function to addEmailTemplate for this 3rd party component.
`

       /**
	 * Create a new Mail Template
	 */
	public function addMailTemplate($template_id)
	{
        $result = MailTemplate::createTemplate(
        	'com_'.$this->compName.'.'.$template_id,
        	'COM_'.STRTOUPPER($this->compName).'_EMAILTMPL_'.STRTOUPPER($template_id).'_SUBJECT',
        	'COM_'.STRTOUPPER($this->compName).'_EMAILTMPL_'.STRTOUPPER($template_id).'_BODY',
        	array("name","sitename","link_text")
        );

		Factory::getApplication()->enqueueMessage('Email Template Record Created . . . ');

	}

`

Expected result

A new record to be created in the database with all the relevant data elements.

Actual result

Missing extension data element and the tags are double arrayed (if that's a thing). So the record doesn't appear in the template listing in the backend. After manually inserting the extension element, trying to open the record from the admin list to edit, fails due to the tags array is within a blank array.

System information (as much as possible)

PHP 8.1
Joomla 4.2.6
MySQL 8.0.27

Additional comments

If I update the createTemplate function in MailTemplate to the following all works as expected.
`

    /**
     * Insert a new mail template into the system
     *
     * @param   string  $key       Mail template key
     * @param   string  $extension Extension
     * @param   string  $subject   A default subject (normally a translatable string)
     * @param   string  $body      A default body (normally a translatable string)
     * @param   array   $tags      Associative array of tags to replace
     * @param   string  $htmlbody  A default htmlbody (normally a translatable string)
     *
     * @return  boolean  True on success, false on failure
     *
     * @since   4.0.0
     */
    public static function createTemplate($key, $extension, $subject, $body, $tags, $htmlbody = '')
    {
        $db = Factory::getDbo();

        $template = new \stdClass();
        $template->template_id = $key;
        $template->extension = $extension;
        $template->language = '';
        $template->subject = $subject;
        $template->body = $body;
        $template->htmlbody = $htmlbody;
        $template->attachments = '';
        $params = new \stdClass();
        $params->tags = $tags;
        $template->params = json_encode($params);

        return $db->insertObject('#__mail_templates', $template);
    }

`

avatar garkell garkell - open - 23 Dec 2022
avatar joomla-cms-bot joomla-cms-bot - change - 23 Dec 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 23 Dec 2022
avatar garkell garkell - change - 23 Dec 2022
The description was changed
avatar garkell garkell - edited - 23 Dec 2022
avatar garkell garkell - change - 23 Dec 2022
The description was changed
avatar garkell garkell - edited - 23 Dec 2022
avatar garkell garkell - change - 23 Dec 2022
The description was changed
avatar garkell garkell - edited - 23 Dec 2022
avatar Fedik Fedik - change - 27 Dec 2022
Labels Added: bug
avatar Fedik Fedik - labeled - 27 Dec 2022
avatar Fedik
Fedik - comment - 27 Dec 2022

There a PR for fixing it #37898 but it have a potential backward compatibility issue.

avatar richard67 richard67 - close - 2 Jan 2023
avatar richard67
richard67 - comment - 2 Jan 2023

Meanwhile there is another PR: #39540 . Please test. Thanks in advance.

avatar richard67 richard67 - change - 2 Jan 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-01-02 07:19:11
Closed_By richard67
avatar Fedik
Fedik - comment - 2 Jan 2023

That one even worse than previous :)

Add a Comment

Login with GitHub to post a comment