/** * add attachement to record * * @param Tinebase_Record_Abstract $record * @param string $name * @param mixed $attachment @see Tinebase_FileSystem::copyTempfile * @return null|Tinebase_Model_Tree_Node */ public function addRecordAttachment(Tinebase_Record_Abstract $record, $name, $attachment) { // only occurs via unittests if (!$name && isset($attachment->tempFile) && !is_resource($attachment->tempFile)) { $attachment = Tinebase_TempFile::getInstance()->getTempFile($attachment->tempFile); $name = $attachment->name; } if ($attachment instanceof Tinebase_Model_Tree_Node && empty($name)) { $name = $attachment->name; } if (empty($name)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Could not evaluate attachment name.'); } return null; } $attachmentsDir = $this->getRecordAttachmentPath($record, TRUE); $attachmentPath = $attachmentsDir . '/' . $name; if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating new record attachment ' . $attachmentPath); } if ($this->_fsController->fileExists($attachmentPath)) { throw new Tinebase_Exception_InvalidArgument('File already exists'); } $this->_fsController->copyTempfile($attachment, $attachmentPath); $node = $this->_fsController->stat($attachmentPath); return $node; }
/** * create node in backend * * @param string $_statpath * @param type * @param string $_tempFileId * @return Tinebase_Model_Tree_Node */ protected function _createNodeInBackend($_statpath, $_type, $_tempFileId = NULL) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating new path ' . $_statpath . ' of type ' . $_type); } $node = NULL; switch ($_type) { case Tinebase_Model_Tree_Node::TYPE_FILE: $this->_backend->copyTempfile($_tempFileId, $_statpath); break; case Tinebase_Model_Tree_Node::TYPE_FOLDER: $node = $this->_backend->mkdir($_statpath); break; } return $node ? $node : $this->_backend->stat($_statpath); }