Exemple #1
0
 /**
  * @param Account $account
  * @return bool
  */
 function SaveMailAliases($account)
 {
     if ($account && $account->IsInternal) {
         if ($this->_connector->Execute($this->_commandCreator->ClearMailAliases($account->Id))) {
             $return = true;
             $aliasTo = $account->MailIncLogin;
             $aliasArray = explode('@', $aliasTo);
             $aliasDomain = isset($aliasArray[1]) ? $aliasArray[1] : '';
             if (strlen($aliasDomain) > 0 && is_array($account->Aliases) && count($account->Aliases) > 0) {
                 $aliases = array_unique($account->Aliases);
                 $addAliases = array();
                 foreach ($aliases as $aliasName) {
                     $add1 = $add2 = false;
                     $result = $this->_connector->Execute($this->_commandCreator->IsAliasValidToCreateInAccounts($aliasName, $aliasDomain));
                     if ($result) {
                         $row = $this->_connector->GetNextRecord();
                         if (is_object($row)) {
                             if (0 === (int) $row->cnt) {
                                 $add1 = true;
                             }
                             $this->_connector->FreeResult();
                         }
                     }
                     $result = $this->_connector->Execute($this->_commandCreator->IsAliasValidToCreateInAliases($aliasName, $aliasDomain));
                     if ($result) {
                         $row = $this->_connector->GetNextRecord();
                         if (is_object($row)) {
                             if (0 === (int) $row->cnt) {
                                 $add2 = true;
                             }
                             $this->_connector->FreeResult();
                         }
                     }
                     if ($add1 && $add2) {
                         $addAliases[] = $aliasName;
                     }
                 }
                 if (count($addAliases) > 0) {
                     foreach ($addAliases as $aliasName) {
                         $return &= $this->_connector->Execute($this->_commandCreator->InsertMailAlias($account->Id, $aliasName, $aliasDomain, $aliasTo));
                     }
                 }
             }
             return $return;
         }
         return false;
     }
     return true;
 }