/** * @see Tinebase_Setup_DemoData_Abstract */ protected function _beforeCreate() { $be = new Addressbook_Backend_Sql(); foreach ($this->_personas as $login => $fullName) { try { $user = Tinebase_User::getInstance()->getFullUserByLoginName($login); $contact = Addressbook_Controller_Contact::getInstance()->get($user->contact_id); } catch (Tinebase_Exception_NotFound $e) { list($given, $last) = explode(' ', $fullName); $group = Tinebase_Group::getInstance()->getGroupByName('Users'); $groupId = $group->getId(); $emailDomain = $this->_getMailDomain(); $user = new Tinebase_Model_FullUser(array('accountLoginName' => $login, 'accountPrimaryGroup' => $groupId, 'accountDisplayName' => $fullName, 'accountLastName' => $last, 'accountFirstName' => $given, 'accountFullName' => $fullName, 'accountEmailAddress' => $login . '@' . $emailDomain)); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $internalAddressbook = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Internal Contacts', Tinebase_Model_Container::TYPE_SHARED); $user->container_id = $internalAddressbook->getId(); $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($user); $user->contact_id = $contact->getId(); } Tinebase_Timemachine_ModificationLog::setRecordMetaData($user, 'create'); $user = Tinebase_User::getInstance()->addUser($user); Tinebase_Group::getInstance()->addGroupMember($groupId, $user); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $listBackend = new Addressbook_Backend_List(); $listBackend->addListMember($group->list_id, $user->contact_id); } $this->_setUserPassword($user); } if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $ar = array_merge($this->_dataMapping[$login], $this->_dataMapping['default']); $filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'DemoData' . DIRECTORY_SEPARATOR . 'persona_' . $login . '.jpg'; if (file_exists($filename)) { $handle = fopen($filename, "r"); $content = fread($handle, filesize($filename)); fclose($handle); $be->_saveImage($contact->getId(), $content); } foreach ($ar as $property => $value) { $contact->{$property} = $value; } Addressbook_Controller_Contact::getInstance()->update($contact); } $this->_personas[$login] = $user; } $this->_createGroups(); $this->_createRoles(); $this->_createSharedTags(); }
/** * inits (adds) some test users * */ public function initTestUsers() { $personas = array('jsmith' => 'John Smith', 'sclever' => 'Susan Clever', 'pwulf' => 'Paul Wulf', 'jmcblack' => 'James McBlack', 'rwright' => 'Roberta Wright'); foreach ($personas as $login => $fullName) { try { $user = Tinebase_User::getInstance()->getFullUserByLoginName($login); } catch (Tinebase_Exception_NotFound $e) { list($given, $last) = explode(' ', $fullName); $group = Tinebase_Group::getInstance()->getGroupByName('Users'); $groupId = $group->getId(); $user = new Tinebase_Model_FullUser(array('accountLoginName' => $login, 'accountPrimaryGroup' => $groupId, 'accountDisplayName' => $fullName, 'accountLastName' => $last, 'accountFirstName' => $given, 'accountFullName' => $fullName, 'accountEmailAddress' => $login . '@tine20.org')); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $internalAddressbook = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Internal Contacts', Tinebase_Model_Container::TYPE_SHARED); $user->container_id = $internalAddressbook->getId(); $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($user); $user->contact_id = $contact->getId(); } $user = Tinebase_User::getInstance()->addUser($user); Tinebase_Group::getInstance()->addGroupMember($groupId, $user); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $listBackend = new Addressbook_Backend_List(); $listBackend->addListMember($group->list_id, $user->contact_id); } // give additional testusers the same password as the primary test account Tinebase_User::getInstance()->setPassword($user, Zend_Registry::get('testConfig')->password); } $personas[$login] = $user; } Zend_Registry::set('personas', $personas); }