domain_error_unique when there is no domain in db table

Discussion in 'Developers' Forum' started by vaio1, Apr 18, 2012.

  1. vaio1

    vaio1 Member

    Hi guys,

    I have tested this simple code:

    Code:
    $params = array(
    			'server_id' => $ServerId,
    			'domain' => $domain['domain'],
    			'active' => 'y');
    try{
    	// Get the domain name ID
    	$record = $client->mail_domain_get_by_domain($this->getSession(), $domain['domain']);
    
    	// Create the mail domain
    	if(empty($record['domain_id'])){
    		$domainId = $client->mail_domain_add($this->getSession(), $clientId, $params);
    	}else{
    		$domainId = $record['domain_id'];
    	}
    
         echo $domainId;	
    
    } catch ( SoapFault $e ) {
    	throw new Exception("There was a problem with the Mail Domain creation: " . $e->getMessage() . " - " . __METHOD__ . " - Paramenters: " . json_encode($params) , "3506");
    }
    
    If you execute this code you'll get the exception domain_error_unique

    why this happens?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Either there is already a email domain with that value or the domain variable is empty or a similar problem.
     
  3. vaio1

    vaio1 Member

    these issues suggested are already tested.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Take a look at the mail_domain table in the ispconfig database with phpmyadmin to ensure that it is really empty.
     
    Last edited: Apr 18, 2012
  5. vaio1

    vaio1 Member

    It's not important if there is already a domain saved in the db because I check if the domain exist before.
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    It is important if there is a domain in the DB as you cant add a duplicate domain and the error that you get tells you that there is already that domain in the mail_domain table. So check with phpmyadmin if the mail_domain table is empty or not.
     
  7. vaio1

    vaio1 Member

    As you can see in the code posted I check if the domain exists in the db using the mail_domain_get_by_domain method.

    If the domain exists the creation of the new mail domain is not a problem because the condition check if it exists or not.

    So if the problem is not of the mail_domain_add method maybe the problem is mail_domain_get_by_domain that doesn't get the domain from the db.
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    Try:

    $record = $client->mail_domain_get($this->getSession(), array('domain' => $domain['domain']));

    if(coun($record) > 0) {
    echo 'domain exists';
    } else {
    echo 'domain does not exist';
    }
     
  9. vaio1

    vaio1 Member

    Hi,

    done but the problem persists. count(record) = 0 even if there is a mail domain.

    regards
     
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    Then it might be that the variable $domain['domain'] does not contain the domain, as the query functions for mail domains work properly on my servers.
     

Share This Page