hello, i want tu use this in my rules, but in wich type i must provide domain for a node? i mean what in rules i have only text field row for input domain, if i input http://mydomain.com or token for it i have a error on this rule

The domain http://mydomain.com/ does not exist.

here is code of this function

function rules_action_set_node_domain($node, $settings) {
    
    $domain = domain_lookup(NULL, $settings['subdomain'], TRUE);

    if ($domain['domain_id']) {
        $node->domains[$domain['domain_id']] = $domain['domain_id'];
    }
    else {
        drupal_set_message(t('The domain @domain does not exist.', array('@domain' => $settings['subdomain'])), 'error');
    }
    return array('node' => $node);
}

i think what this is not work, because i want to set domain with id 0 for this node and this domain is not a subdomain

i can't write in php so well, any help for fix this issue ?

CommentFileSizeAuthor
#5 default_domain_fix-893450-5.patch552 bytesaron novak

Comments

shushu’s picture

Thanks for the details.
True, seems like a bug.
I will fix it in the near future, but you can try to fix it by chaning the line

if ($domain['domain_id']) {

to:

if (isset($domain['domain_id'])) {

Please let me know whether it solved the problem.

Regards,
Shushu

ionmedia’s picture

ok, now i have

function rules_action_set_node_domain($node, $settings) {
    
    $domain = domain_lookup(NULL, $settings['subdomain'], TRUE);

    if (isset($domain['domain_id'])) {
        $node->domains[$domain['domain_id']] = $domain['domain_id'];
    }
    else {
        drupal_set_message(t('The domain @domain does not exist.', array('@domain' => $settings['subdomain'])), 'error');
    }
    return array('node' => $node);
}

after this action execution i have no errors, but it still not work for a source domain

if i use prefix.domain.com in this action all works fine and node published to this domain

if just use domain.com no errors or warnings appear, but node don't published on the domain.com

aron novak’s picture

Title: rules_action_set_node_domain » rules_action_set_node_domain, use isset() and support default domain
function rules_action_set_node_domain($node, $settings) {
    
    $domain = domain_lookup(NULL, $settings['subdomain'], TRUE);

    if (isset($domain['domain_id'])) {
        $node->domains[$domain['domain_id']]  = ($node->domains[$domain['domain_id']] == 0) ? -1 : $node->domains[$domain['domain_id']] ;
        $node->domains[$domain['domain_id']] = $domain['domain_id'];
    }
    else {
        drupal_set_message(t('The domain @domain does not exist.', array('@domain' => $settings['subdomain'])), 'error');
    }
    return array('node' => $node);
}

This would work. I'm happy to provide a patch if there is any feedback.

shushu’s picture

Please send a patch, I will insert it and release a version :-)

aron novak’s picture

Status: Active » Needs review
StatusFileSize
new552 bytes

Here it is.

shushu’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Assigned: Unassigned » shushu
Status: Needs review » Fixed

Thanks Aron, and sorry for the delay.

shushu’s picture

Version: 6.x-1.x-dev » 6.x-1.2
Status: Fixed » Closed (fixed)
reswild’s picture

Priority: Normal » Major
Status: Closed (fixed) » Needs work

The last patch for version 6.x seems to be missing the line

$domain_id = $domain['domain_id'];

so $domain_id is never defined, and the default domain is always assigned no matter what you put in your rules.

The patch for 7.x seems to be OK.

shushu’s picture

Version: 6.x-1.2 » 6.x-1.3
Status: Needs work » Needs review