User tests: Successful: Unsuccessful:
Testing for same alias is not done by Contact Creator Plugin.Due to this, 2 contacts with same alias can be created(which is not desirable). So,the extra code ,line numbers 66 to 76, appends the current time stamp to alias if the same alias is already present.
Before Patch:
After Patch :
The bug is reported at http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8103&tracker_item_id=33291
Please look at: #3131
Contact creator can't create same alias because an error is sent to prevent it when creating a user and the existing contact alias is in the same category as targetted by contactcreator.
That does not mean we should not implement a solution to create a specific alias instead of sending the error, when possible, taking into account the category as shown in PR 3131 code.
@Bakual This is my first time and I'm unaware of the coding standards.Thank you.
@infograf768 Even though an error is generated, new contact with same alias is getting created. So, this small patch will prevent such a situation.Thanks.
@Bakual Thanks again The status of the bug at http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8103&tracker_item_id=33291 is still open. Is there something I should do ?
@Bahanudev
I repeat, a new contact is not created if it is in the same category as the one which contains a contact with same alias.
@Bhanudev thanks for contributing to Joomla!
Some notes:
JDatabaseQuery
to build queries to ensure that queries are compatible with all the existing drivers. This:$db = JFactory::getDbo();
$db->setQuery('SELECT id FROM #__contact_details WHERE alias = "' . $user['name'] . '"');
$id2 = $db->loadResult();
would become:
$query = $db->getQuery(true)
->select("id")
->from('#__contact_details')
->where('alias = ' . $db->quote($user['name']));
$db->setQuery($query);
$id2 = $db->loadResult();
ContactTableContact
instance so you can use it to search an existing contact avoiding to use queries. This is a sample call to search same alias in same category (being $contactTable
a ContactTableContact
instance):$contactTable->load(array('alias' => $alias, 'catid' => $categoryId)
JString::increment()
to increase strings in the same way Joomla! does it in most places. For common strings (name, title...) we use:// Converts "Webmaster" into "Webmaster (2)"
$name = JString::increment($name);
and for aliases we use:
// Converts "webmaster" into "webmaster-2"
$alias = JString::increment($alias, 'dash');
I've sent a PR against @infograf768 branch (#3131) here: infograf768#6
I'm closing this in favour of that pull request. Thanks again for your efforts here!
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-02-20 12:38:30 |
Please have a look at our Coding Style Standards: http://joomla.github.io/coding-standards