/** * import single record (create password if in data) * * @param Tinebase_Record_Abstract $_record * @param string $_resolveStrategy * @param array $_recordData * @return Tinebase_Record_Interface * @throws Tinebase_Exception_Record_Validation */ protected function _importRecord($_record, $_resolveStrategy = NULL, $_recordData = array()) { $admCfg = Tinebase_Core::getConfig()->get('Admin'); $excludeGroups = array(); $be = new Tinebase_Group_Sql(); $members = explode(' ', $_record->members); $_record->members = null; unset($_record->members); $this->_setController(); try { $group = $be->getGroupByName($_record->name); } catch (Tinebase_Exception_Record_NotDefined $e) { $group = NULL; parent::_importRecord($_record, $_resolveStrategy, $_recordData); } if ($group) { $this->_handleGroupMemberShip($group, $members); } else { $group = Admin_Controller_Group::getInstance()->get($_record->getId()); $list = Addressbook_Controller_List::getInstance()->createByGroup($group); $group->list_id = $list->getId(); $group->visibility = Tinebase_Model_Group::VISIBILITY_DISPLAYED; $be->updateGroupInSqlBackend($group); $memberUids = array(); if (!empty($members)) { $users = $this->_resolveUsers($members); foreach ($users as $userId) { try { $be->addGroupMember($_record->getId(), $userId); } catch (Exception $e) { } } } } return $group; }
/** * import single record (create password if in data) * * @param Tinebase_Record_Abstract $_record * @param string $_resolveStrategy * @param array $_recordData * @return Tinebase_Record_Interface * @throws Tinebase_Exception_Record_Validation */ protected function _importRecord($_record, $_resolveStrategy = NULL, $_recordData = array()) { if ($_record instanceof Tinebase_Model_FullUser && $this->_controller instanceof Admin_Controller_User) { $record = $_record; if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' record Data' . print_r($_recordData, true)); } if (isset($_recordData['smtpUser'])) { $record->smtpUser = new Tinebase_Model_EmailUser($_recordData['smtpUser']); } if (isset($_recordData['imapUser'])) { $record->imapUser = new Tinebase_Model_EmailUser($_recordData['imapUser']); } if (isset($_recordData['samba']) && (!isset($this->_options['samba']) || empty($this->_options['samba']))) { $this->_options['samba'] = $_recordData['samba']; } if (isset($_recordData['accountHomeDirectoryPrefix'])) { $this->_options['accountHomeDirectoryPrefix'] = $_recordData['accountHomeDirectoryPrefix']; } $password = $record->applyOptionsAndGeneratePassword($this->_options, isset($_recordData['password']) ? $_recordData['password'] : NULL); Tinebase_Event::fireEvent(new Admin_Event_BeforeImportUser($record, $this->_options)); // try to create record with password if ($record->isValid()) { if (!$this->_options['dryrun']) { $record = $this->_controller->create($record, $password, $password); } else { $this->_importResult['results']->addRecord($record); } $this->_importResult['totalcount']++; } else { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Record invalid: ' . print_r($record->getValidationErrors(), TRUE)); throw new Tinebase_Exception_Record_Validation('Imported record is invalid.'); } } else { $record = parent::_importRecord($_record, $_resolveStrategy, $_recordData); } return $record; }
/** * import single record (create password if in data) * * @param Tinebase_Record_Abstract $_record * @param string $_resolveStrategy * @param array $_recordData * @return Tinebase_Record_Interface * @throws Tinebase_Exception_Record_Validation */ protected function _importRecord($_record, $_resolveStrategy = NULL, $_recordData = array()) { if ($_record instanceof Tinebase_Model_FullUser && $this->_controller instanceof Admin_Controller_User) { $record = $_record; // create valid login name if (!isset($record->accountLoginName)) { $record->accountLoginName = Tinebase_User::getInstance()->generateUserName($record, $this->_options['userNameSchema']); } // add prefix to login name if given if (!empty($this->_options['accountLoginNamePrefix'])) { $record->accountLoginName = $this->_options['accountLoginNamePrefix'] . $record->accountLoginName; } // add home dir if empty and prefix is given (append login name) if (empty($record->accountHomeDirectory) && !empty($this->_options['accountHomeDirectoryPrefix'])) { $record->accountHomeDirectory = $this->_options['accountHomeDirectoryPrefix'] . $record->accountLoginName; } // create email address if accountEmailDomain if given if (empty($record->accountEmailAddress) && !empty($this->_options['accountEmailDomain'])) { $record->accountEmailAddress = $record->accountLoginName . '@' . $this->_options['accountEmailDomain']; } if (!empty($this->_options['samba'])) { $this->_addSambaSettings($record); } Tinebase_Event::fireEvent(new Admin_Event_BeforeImportUser($record, $this->_options)); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($record->toArray(), true)); } // generate passwd (use accountLoginName or password from options or password from csv in this order) $password = $record->accountLoginName; if (!empty($this->_options['password'])) { $password = $this->_options['password']; } if (isset($_recordData['password']) && !empty($_recordData['password'])) { $password = $_recordData['password']; } $this->_addEmailUser($record, $password); //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding record: ' . print_r($record->toArray(), TRUE)); // try to create record with password if ($record->isValid()) { if (!$this->_options['dryrun']) { $record = $this->_controller->create($record, $password, $password); } else { $this->_importResult['results']->addRecord($record); } $this->_importResult['totalcount']++; } else { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Record invalid: ' . print_r($record->getValidationErrors(), TRUE)); throw new Tinebase_Exception_Record_Validation('Imported record is invalid.'); } } else { $record = parent::_importRecord($_record, $_resolveStrategy, $_recordData); } return $record; }