Tagging contacts on registration Topic is solved

This forum is for general questions about extensions for Joomla! 3.x.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
PTuson
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Jul 15, 2019 3:31 pm

Tagging contacts on registration

Post by PTuson » Mon Jul 15, 2019 3:59 pm

When users register with our site they are automatically created as contacts. I have been unsuccessfully attempting to assign tags to the contact on registration using a php script.

I have narrowed down the problem to the contentitem_tag_map table, which is not being completed. The other tables involved are being completed properly. My code for adding the tag is:

$tags = JHelperTags::searchTags(array('title' => 'XXXXXXXX'));
$tag_id = $tags[0]->value;
...
$tagsObserver = $contact->getObserverOfClass('JTableObserverTags');
$tagsObserver->setNewTags(array($tag_id), false);

Then check and store as usual. Other than the tags, the correct information is being written to the contact table.

I have monitored what is going on in the code. The most relevant section appears to be the addTagMapping method within TagsHelper. A subset of the query is:

[insert:protected] => JDatabaseQueryElement Object
(
[name:protected] => INSERT INTO
[elements:protected] => Array
(
[0] => #__contentitem_tag_map
)

[glue:protected] => ,
)

[from:protected] =>
[join:protected] =>
[set:protected] =>
[where:protected] =>
[group:protected] =>
[having:protected] =>
[columns:protected] => JDatabaseQueryElement Object
(
[name:protected] => ()
[elements:protected] => Array
(
[0] => `type_alias`
[1] => `core_content_id`
[2] => `content_item_id`
[3] => `tag_id`
[4] => `tag_date`
[5] => `type_id`
)

[glue:protected] => ,
)

[values:protected] => JDatabaseQueryElement Object
(
[name:protected] => ()
[elements:protected] => Array
(
[0] => 'com_contact.contact', 4569, 1374, '1090', CURRENT_TIMESTAMP(), 3
)

[glue:protected] => ),(
)

There are no errors being reported on the execution of this. I tried manually inserting this directly within the database using PhpMyAdmin and it worked correctly. However, when I run my code nothing is entered within the contentitem_tag_map table.

I am running this on my test computer running Debian Linux. I am using MariaDB V10.3, PHP 7.3, Apache 2.4, PhpMyAdmin 4.6.6 and Joomla 3.9.10. I have tried giving the registering user full access rites to everything. I have used this tagging approach successfully before with articles and categories but this is the first time I have used with contacts.

Does anyone have any ideas about what I am doing wrong and how I might correct this?
Last edited by imanickam on Tue Jul 16, 2019 2:18 am, edited 1 time in total.
Reason: Moved the topic from the forum Extensions for Joomla! 3.x to the forum Joomla! 3.x Coding

PTuson
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Jul 15, 2019 3:31 pm

Re: Tagging contacts on registration

Post by PTuson » Sat Jul 20, 2019 1:53 pm

I have managed to resolve this.

I appears the check and store functions remove any tags that mat have been added by setNewTags.

The solution was to add the tags using setNewTags after the check and store functions for the main Contact object.


Post Reply

Return to “Extensions for Joomla! 3.x”