/** * try to delete a contact and its id * */ public function testDeleteContact() { $contact = $this->testCreateContact(); $this->_backend->delete($contact->getId()); $this->setExpectedException('Tinebase_Exception_NotFound'); $contact = $this->_backend->get($contact->getId()); }
/** * remove autogenerated contacts * * @param Zend_Console_Getopt $opts * * @throws Addressbook_Exception * @throws Tinebase_Exception_InvalidArgument * @todo use OR filter for different locales */ public function removeAutogeneratedContacts($opts) { if (!Tinebase_Application::getInstance()->isInstalled('Calendar')) { throw new Addressbook_Exception('Calendar application not installed'); } $params = $this->_parseArgs($opts); $languages = isset($params['languages']) ? $params['languages'] : array('en', 'de'); $contactBackend = new Addressbook_Backend_Sql(); foreach ($languages as $language) { $locale = new Zend_Locale($language); $translation = Tinebase_Translation::getTranslation('Calendar', $locale); // search all contacts with note "This contact has been automatically added by the system as an event attender" $noteFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'note', 'operator' => 'equals', 'value' => $translation->_('This contact has been automatically added by the system as an event attender')))); $contactIdsToDelete = $contactBackend->search($noteFilter, null, Tinebase_Backend_Sql_Abstract::IDCOL); if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " About to delete " . count($contactIdsToDelete) . ' contacts ...'); } $number = $contactBackend->delete($contactIdsToDelete); if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Deleted " . $number . ' autogenerated contacts for language ' . $language); } } }
/** * test create container */ public function testCreateContainerAndDeleteContents() { $container = $this->_json->saveContainer(array("type" => Tinebase_Model_Container::TYPE_SHARED, "backend" => "Sql", "name" => "asdfgsadfg", "color" => "#008080", "application_id" => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), "model" => "", "note" => "")); // check if the model was set $this->assertEquals($container['model'], 'Addressbook_Model_Contact'); $contact = new Addressbook_Model_Contact(array('n_given' => 'max', 'n_family' => 'musterman', 'container_id' => $container['id'])); $contact = Addressbook_Controller_Contact::getInstance()->create($contact); $this->_json->deleteContainers(array($container['id'])); $cb = new Addressbook_Backend_Sql(); $del = $cb->get($contact->getId(), true); // record should be deleted $this->assertEquals($del->is_deleted, 1); try { Addressbook_Controller_Contact::getInstance()->get($contact->getId(), $container['id']); $this->fail('The expected exception was not thrown'); } catch (Tinebase_Exception_NotFound $e) { // ok; } // record should not be found $this->assertEquals($e->getMessage(), 'Addressbook_Model_Contact record with id = ' . $contact->getId() . ' not found!'); }
/** * migrate from SQL account storage to another one (for example LDAP) * - deletes all users, groups and roles because they will be * imported from new accounts storage backend */ protected function _migrateFromSqlAccountsStorage() { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Deleting all user accounts, groups, roles and rights'); Tinebase_User::factory(Tinebase_User::SQL)->deleteAllUsers(); $contactSQLBackend = new Addressbook_Backend_Sql(); $allUserContactIds = $contactSQLBackend->search(new Addressbook_Model_ContactFilter(array('type' => 'user')), null, true); if (count($allUserContactIds) > 0) { $contactSQLBackend->delete($allUserContactIds); } Tinebase_Group::factory(Tinebase_Group::SQL)->deleteAllGroups(); $listsSQLBackend = new Addressbook_Backend_List(); $allGroupListIds = $listsSQLBackend->search(new Addressbook_Model_ListFilter(array('type' => 'group')), null, true); if (count($allGroupListIds) > 0) { $listsSQLBackend->delete($allGroupListIds); } $roles = Tinebase_Acl_Roles::getInstance(); $roles->deleteAllRoles(); // import users (from new backend) / create initial users (SQL) Tinebase_User::syncUsers(array('syncContactData' => TRUE)); $roles->createInitialRoles(); $applications = Tinebase_Application::getInstance()->getApplications(NULL, 'id'); foreach ($applications as $application) { Setup_Initialize::initializeApplicationRights($application); } }
/** * @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(); }
/** * test if deleted users data is removed * * @see TODO add mantis issue * * TODO add test cases for keepOrganizerEvents and $_keepAsContact and $_keepAsContact */ public function testDeleteUsersData() { // configure removal of data Tinebase_Config::getInstance()->set(Tinebase_Config::ACCOUNT_DELETION_EVENTCONFIGURATION, new Tinebase_Config_Struct(array('_deletePersonalContainers' => true))); // we need a valid group and a contact for this test $userContact = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_given' => 'testuser'))); $testUser = $this->getTestRecord(); $testUser->contact_id = $userContact->getId(); $this->_backend->addUser($testUser); Tinebase_Group::getInstance()->addGroupMember($testUser->accountPrimaryGroup, $testUser->getId()); $this->_setUser($testUser); // add a contact and an event to personal folders $event = Calendar_Controller_Event::getInstance()->create(new Calendar_Model_Event(array('summary' => 'testevent', 'dtstart' => '2015-12-24 12:00:00', 'dtend' => '2015-12-24 13:00:00'), true)); $contact = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_given' => 'testcontact'))); $this->_setUser($this->_originalTestUser); $this->_backend->deleteUser($testUser); // check if contact and event are removed $adbBackend = new Addressbook_Backend_Sql(); try { $adbBackend->get($contact->getId()); $this->fail('contact be deleted'); } catch (Exception $e) { $this->assertTrue($e instanceof Tinebase_Exception_NotFound); } $calBackend = new Calendar_Backend_Sql(); try { $calBackend->get($event->getId()); $this->fail('event should be deleted: ' . print_r($event->toArray(), true)); } catch (Exception $e) { $this->assertTrue($e instanceof Tinebase_Exception_NotFound); } }
/** * try to delete a contact * */ public function testDeleteContact() { $this->_backend->delete($GLOBALS['Addressbook_ControllerTest']['contactId']); $this->setExpectedException('Tinebase_Exception_NotFound'); $contact = $this->_backend->get($GLOBALS['Addressbook_ControllerTest']['contactId']); }
/** * import contact data(phone, address, fax, birthday. photo) * * @param Tinebase_Model_FullUser $syncedUser * @param array $options */ public static function syncContactData($syncedUser, $options) { if (!Tinebase_Config::getInstance()->get(Tinebase_Config::SYNC_USER_CONTACT_DATA, true) || !isset($options['syncContactData']) || !$options['syncContactData'] || !Tinebase_Application::getInstance()->isInstalled('Addressbook') || $syncedUser->visibility === Tinebase_Model_FullUser::VISIBILITY_HIDDEN) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Contact data sync disabled'); } return; } $addressbook = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL); try { $contact = $addressbook->getByUserId($syncedUser->getId()); $originalContact = clone $contact; if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' user: '******'::' . __LINE__ . ' new contact: ' . print_r($contact->toArray(), true) . ' orig contact:' . print_r($originalContact->toArray(), true)); } if (isset($options['syncContactPhoto']) && $options['syncContactPhoto']) { $syncPhoto = true; if ($originalContact->jpegphoto == 1) { // TODO use generic function with ignoreAcl ... //$originalContact->jpegphoto = Tinebase_Controller::getInstance()->getImage('Addressbook', $originalContact->getId())->getBlob(); $adb = new Addressbook_Backend_Sql(); $originalContact->jpegphoto = $adb->getImage($originalContact->getId()); } if ($contact->jpegphoto == 1) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Removing/unset current jpegphoto'); } $contact->jpegphoto = false; } } else { $syncPhoto = false; } $diff = $contact->diff($originalContact, $syncPhoto ? array('n_fn') : array('jpegphoto', 'n_fn')); if (!$diff->isEmpty() || $originalContact->jpegphoto === 0 && !empty($contact->jpegphoto)) { // add modlog info Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'update'); if ($contact->container_id !== null) { Tinebase_Container::getInstance()->increaseContentSequence($contact->container_id); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updating contact data for user ' . $syncedUser->accountLoginName); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Diff: ' . print_r($diff->toArray(), true)); } $addressbook->update($contact); } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' User contact is up to date.'); } } } catch (Addressbook_Exception_NotFound $aenf) { self::createContactForSyncedUser($syncedUser); $syncedUser = Tinebase_User::getInstance()->updateUserInSqlBackend($syncedUser); } catch (Tinebase_Exception_NotFound $tenf) { if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Contact information seems to be missing in sync backend'); } Tinebase_Exception::log($tenf); } }