/**
  * test if image is in contact
  * 
  * 
  */
 public function testImage()
 {
     $contact = $this->testCreateContact();
     $image = $this->_backend->getImage($contact->getId());
     $tmpPath = tempnam(Tinebase_Core::getTempDir(), 'tine20_tmp_gd');
     file_put_contents($tmpPath, $image);
     $this->assertFileEquals(dirname(__FILE__) . '/../../Tinebase/ImageHelper/phpunit-logo.gif', $tmpPath);
     unset($tmpPath);
 }
Ejemplo n.º 2
0
 /**
  * test if image is in contact
  * 
  */
 public function testImage()
 {
     //$contact = $this->_backend->get($GLOBALS['Addressbook_ControllerTest']['contactId']);
     $image = $this->_backend->getImage($GLOBALS['Addressbook_ControllerTest']['contactId']);
     $tmpPath = tempnam(Tinebase_Core::getTempDir(), 'tine20_tmp_gd');
     file_put_contents($tmpPath, $image);
     $this->assertFileEquals(dirname(__FILE__) . '/../../Tinebase/ImageHelper/phpunit-logo.gif', $tmpPath);
     unset($tmpPath);
 }
 /**
  * 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);
     }
 }