/**
  * set file attachments of a record
  * 
  * @param Tinebase_Record_Interface $record
  */
 public function setRecordAttachments(Tinebase_Record_Interface $record)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Record: ' . print_r($record->toArray(), TRUE));
     }
     $currentAttachments = $record->getId() ? $this->getRecordAttachments(clone $record) : new Tinebase_Record_RecordSet('Tinebase_Model_Tree_Node');
     $attachmentsToSet = $record->attachments instanceof Tinebase_Record_RecordSet ? $record->attachments : new Tinebase_Record_RecordSet('Tinebase_Model_Tree_Node', (array) $record->attachments, TRUE);
     $attachmentDiff = $currentAttachments->diff($attachmentsToSet);
     foreach ($attachmentDiff->added as $added) {
         try {
             $this->addRecordAttachment($record, $added->name, $added);
         } catch (Tinebase_Exception_InvalidArgument $teia) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Could not add new attachment ' . print_r($added->toArray(), TRUE) . ' to record: ' . print_r($record->toArray(), TRUE));
             }
             Tinebase_Exception::log($teia);
         } catch (Tinebase_Exception_NotFound $tenf) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Could not add new attachment ' . print_r($added->toArray(), TRUE) . ' to record: ' . print_r($record->toArray(), TRUE));
             }
             Tinebase_Exception::log($tenf);
         }
     }
     foreach ($attachmentDiff->removed as $removed) {
         $this->_fsController->deleteFileNode($removed);
     }
     foreach ($attachmentDiff->modified as $modified) {
         $this->_fsController->update($attachmentsToSet->getById($modified->getId()));
     }
 }