Beispiel #1
0
 /**
  * Saves the properties to the database.
  * 
  * This performs an intelligent insert/update, and reloads the 
  * properties with fresh data from the table on success.
  * 
  * @return int 0 on failure, 1 on success.
  */
 public function save()
 {
     // convenience var for the primary key name
     $primary = $this->_info['primary'];
     // check the primary key value for insert/update
     if (empty($this->_data[$primary])) {
         // no primary key value, must be an insert.
         // make sure it's null.
         $this->_data[$primary] = null;
         // attempt the insert.
         $result = $this->_table->insert($this->_data);
         if (is_numeric($result)) {
             // insert worked, refresh with data from the table
             $this->_data[$primary] = $result;
             $this->_refresh();
         }
         // regardless of success return the result
         return $result;
     } else {
         // has a primary key value, update only that key.
         $where = $this->_db->quoteInto("{$primary} = ?", $this->_data[$primary]);
         // return the result of the update attempt,
         // no need to update the row object.
         $result = $this->_table->update($this->_data, $where);
         if (is_int($result)) {
             // update worked, refresh with data from the table
             $this->_refresh();
         }
     }
 }
 /**
  * updates email properties for an existing user
  * 
  * @param  Tinebase_Model_FullUser  $_updatedUser
  * @param  Tinebase_Model_FullUser  $_newUserProperties
  */
 protected function _updateUser(Tinebase_Model_FullUser $_updatedUser, Tinebase_Model_FullUser $_newUserProperties)
 {
     $imapSettings = $this->_recordToRawData($_updatedUser, $_newUserProperties);
     if ($this->_hasTine20Userid === true) {
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailUserId']) . ' = ?', $_updatedUser->getId()), $this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailGID']) . ' = ?', $this->_config['emailGID']));
     } else {
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailUserId']) . ' = ?', $this->_convertToInt($_updatedUser->getId())), $this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailGID']) . ' = ?', $this->_convertToInt($this->_config['emailGID'])));
     }
     unset($imapSettings[$this->_propertyMapping['emailUserId']]);
     $this->_removeNonDBValues($imapSettings);
     $this->_update($imapSettings, $where);
     $this->inspectGetUserByProperty($_updatedUser);
 }
Beispiel #3
0
 /**
  * updates email properties for an existing user
  * 
  * @param  Tinebase_Model_FullUser  $_updatedUser
  * @param  Tinebase_Model_FullUser  $_newUserProperties
  */
 protected function _updateUser(Tinebase_Model_FullUser $_updatedUser, Tinebase_Model_FullUser $_newUserProperties)
 {
     $imapSettings = $this->_recordToRawData($_updatedUser, $_newUserProperties);
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updating Dbmail user ' . $imapSettings[$this->_propertyMapping['emailUsername']]);
     }
     if ($this->_hasTine20Userid === true) {
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailUserId']) . ' = ?', $_updatedUser->getId()), $this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailGID']) . ' = ?', $this->_config['emailGID']));
     } else {
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailUserId']) . ' = ?', $this->_convertToInt($_updatedUser->getId())), $this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailGID']) . ' = ?', $this->_convertToInt($this->_config['emailGID'])));
     }
     unset($imapSettings[$this->_propertyMapping['emailMailSize']]);
     unset($imapSettings[$this->_propertyMapping['emailSieveSize']]);
     unset($imapSettings[$this->_propertyMapping['emailLastLogin']]);
     unset($imapSettings[$this->_propertyMapping['emailUserId']]);
     $this->_db->update($this->_userTable, $imapSettings, $where);
     $this->inspectGetUserByProperty($_updatedUser);
 }
Beispiel #4
0
 /**
  * updates email properties for an existing user
  * 
  * @param  Tinebase_Model_FullUser  $_updatedUser
  * @param  Tinebase_Model_FullUser  $_newUserProperties
  */
 protected function _updateUser(Tinebase_Model_FullUser $_updatedUser, Tinebase_Model_FullUser $_newUserProperties)
 {
     $imapSettings = $this->_recordToRawData($_updatedUser, $_newUserProperties);
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updating Dovecot user ' . $imapSettings[$this->_propertyMapping['emailUsername']]);
     }
     #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($imapSettings, TRUE));
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailUserId']) . ' = ?', $imapSettings[$this->_propertyMapping['emailUserId']]));
     // append domain if set or domain IS NULL
     if (array_key_exists('domain', $this->_config) && !empty($this->_config['domain'])) {
         $where[] = $this->_db->quoteInto($this->_db->quoteIdentifier($this->_userTable . '.domain') . ' = ?', $this->_config['domain']);
     } else {
         $where[] = $this->_db->quoteIdentifier($this->_userTable . '.domain') . ' IS NULL';
     }
     #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($where, TRUE));
     try {
         $this->_db->update($this->_userTable, $imapSettings, $where);
         $this->inspectGetUserByProperty($_updatedUser);
     } catch (Zend_Db_Statement_Exception $zdse) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' Error while updating email user: ' . $zdse->getMessage());
     }
 }
Beispiel #5
0
 /**
  * set email aliases and forwards
  * 
  * removes all aliases for user
  * creates default email->email alias if not forward only
  * creates aliases
  * creates forwards
  * 
  * @param  array  $_smtpSettings  as returned from _recordToRawData
  * @return void
  */
 protected function _setAliases($_smtpSettings)
 {
     #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting default alias/forward for ' . print_r($_smtpSettings, true));
     // remove all current aliases and forwards for user
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($this->_propertyMapping['emailUserId']) . ' = ?', $_smtpSettings[$this->_propertyMapping['emailUserId']]));
     $this->_db->delete($this->_destinationTable, $where);
     #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting default alias/forward for ' . $_smtpSettings[$this->_propertyMapping['emailUsername']]);
     // create default alias/forward
     // check if it should be forward only
     if (!$_smtpSettings[$this->_propertyMapping['emailForwardOnly']]) {
         // create email -> username alias
         $aliasArray = array('userid' => $_smtpSettings[$this->_propertyMapping['emailUserId']], 'source' => $_smtpSettings[$this->_propertyMapping['emailAddress']], 'destination' => $_smtpSettings[$this->_propertyMapping['emailUsername']]);
         // insert into table
         $this->_db->insert($this->_destinationTable, $aliasArray);
         // create username -> username alias if email and username are different
         if ($_smtpSettings[$this->_propertyMapping['emailUsername']] != $_smtpSettings[$this->_propertyMapping['emailAddress']]) {
             $aliasArray = array('userid' => $_smtpSettings[$this->_propertyMapping['emailUserId']], 'source' => $_smtpSettings[$this->_propertyMapping['emailUsername']], 'destination' => $_smtpSettings[$this->_propertyMapping['emailUsername']]);
             // insert into table
             $this->_db->insert($this->_destinationTable, $aliasArray);
         }
     }
     // Set Aliases
     #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting aliases for ' . $_smtpSettings[$this->_propertyMapping['emailUsername']] . ': ' . print_r($_smtpSettings[$this->_propertyMapping['emailAliases']], TRUE));
     if (array_key_exists($this->_propertyMapping['emailAliases'], $_smtpSettings) && is_array($_smtpSettings[$this->_propertyMapping['emailAliases']])) {
         foreach ($_smtpSettings[$this->_propertyMapping['emailAliases']] as $aliasAddress) {
             // check if in primary or secondary domains
             if (!empty($aliasAddress) && $this->_checkDomain($aliasAddress)) {
                 // create alias -> email
                 $aliasArray = array('userid' => $_smtpSettings[$this->_propertyMapping['emailUserId']], 'source' => $aliasAddress, 'destination' => $_smtpSettings[$this->_propertyMapping['emailAddress']]);
                 // insert into table
                 $this->_db->insert($this->_destinationTable, $aliasArray);
             }
         }
     }
     // Set Forwards
     #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting forwards for ' . $_smtpSettings[$this->_propertyMapping['emailUsername']] . ': ' . print_r($_smtpSettings[$this->_propertyMapping['emailForwards']], TRUE));
     if (array_key_exists($this->_propertyMapping['emailForwards'], $_smtpSettings) && is_array($_smtpSettings[$this->_propertyMapping['emailForwards']])) {
         foreach ($_smtpSettings[$this->_propertyMapping['emailForwards']] as $forwardAddress) {
             if (!empty($forwardAddress)) {
                 // create email -> forward
                 $forwardArray = array('userid' => $_smtpSettings[$this->_propertyMapping['emailUserId']], 'source' => $_smtpSettings[$this->_propertyMapping['emailAddress']], 'destination' => $forwardAddress);
                 // insert into table
                 $this->_db->insert($this->_destinationTable, $forwardArray);
             }
         }
     }
 }