It would be great to have an admin option of disallowing duplicate links. If a user adds a link that already exists, they should get an error message and/or be redirected to the node that already covers that link.

As always, happy to test or contribute however I can!

thanks

Comments

micheleannj’s picture

Status: Active » Needs work

Here's my hack that seems to accomplish this:

Change links_weblink_validate in links_weblinks.module to

/**
* Implementation of hook_validate().
*/
function links_weblink_validate(&$node) {

if (($row = db_fetch_object( db_query("SELECT l.nid as nid FROM {links} l INNER JOIN
{links_node} ln ON l.lid = ln.lid WHERE l.url ='%s'",
$node->links_weblink_url))) && ($row->nid != $node->nid)){
form_set_error('url', t('Someone\'s already added that link. You can vote
on and add comments to the existing article'));
}
else
{
links_weblink_node_build($node);
}
}

Obviously, this could be done better and would need to to have an admin option for general use, but I thought I'd stick it here for reference.

Thanks

summit’s picture

Hi there was a mistake in above code, NID should be LID on one occasion..
The code I implemented is:

/**
* Implementation of hook_validate().
*/
function links_weblink_validate(&$node) {
if (($row = db_fetch_object( db_query("SELECT l.lid as nid FROM {links} l INNER JOIN
{links_node} ln ON l.lid = ln.lid WHERE l.url ='%s'",
$node->links_weblink_url))) && ($row->nid != $node->nid)){
form_set_error('url', t('Link allready added to the system'));
}
else
{
links_weblink_node_build($node);
}
}

Please advice if this is correct, and if so, please put in the newest version as a patch.
Thanks in advance,
greetings,
Martijn

summit’s picture

Hi, I think there was still another mistake. The NID from links_node was not in the select statement.
Underneath the correct code:

/**
 * Implementation of hook_validate().
 */
function links_weblink_validate(&$node) {
if (($row = db_fetch_object( db_query("SELECT l.lid , ln.nid FROM {links} l INNER JOIN
{links_node} ln ON l.lid = ln.lid WHERE l.url ='%s'",
$node->links_weblink_url))) && ($row->nid != $node->nid)){
form_set_error('url', t('Link allready added in the system'));
}
else
{
links_weblink_node_build($node);
}
}

Please advice if this is correct?
greetings,
Martijn

summit’s picture

Category: feature » bug
Status: Needs work » Active

Hi,

I installed the Location module. This module makes it possible to add localize information to the weblink node-type.
But with above validation hook I have a problem now.

It says that the link is allready in the system, while I only change the location information.
Does anybody know how to alter above to get it not saying I have a dublicate link when I alter only the location info?

thanks in advance!

Greetings,
Martijn