/**
  * test search results
  * 
  */
 public function testSearchContact()
 {
     $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->objects['initialContact']['container_id'])));
     $contacts = $this->_backend->search($filter);
     $this->assertTrue(count($contacts) >= 1, 'empty search');
     $this->assertTrue(in_array($GLOBALS['Addressbook_ControllerTest']['contactId'], $contacts->getId()), 'contact not found');
     $contact = $contacts[$contacts->getIndexById($GLOBALS['Addressbook_ControllerTest']['contactId'])];
     $this->assertTrue((bool) $contact->jpegphoto, 'contact image is not detected');
 }
 /**
  * test search results
  * 
  * @return Addressbook_Model_Contact
  */
 public function testSearchSpecialNameContact()
 {
     $contact = $this->testCreateSpecialNameContact();
     $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $contact->container_id, 'field' => 'n_family', 'operator' => 'equalsspecial', 'value' => 'Horvat-Čuka')));
     $contacts = $this->_backend->search($filter);
     $this->assertTrue(count($contacts) >= 1, 'empty search');
     $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $contact->container_id, 'field' => 'n_given', 'operator' => 'equalsspecial', 'value' => 'Ana Maria')));
     $contacts = $this->_backend->search($filter);
     $this->assertTrue(count($contacts) >= 1, 'empty search');
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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);
     }
 }