Beispiel #1
0
/**
 * save attachments array for a given object id
 * @param  int $objectId
 * @param  array &$attachments attachments array as from getMailContentAndAtachment
 * @return void
 */
function saveObjectAttachments($objectId, &$attachments)
{
    $filesApiObject = new \CB\Api\Files();
    foreach ($attachments as $d) {
        if (empty($d['attachment'])) {
            continue;
        }
        //safe content to a temporary file
        $tmpName = tempnam(sys_get_temp_dir(), 'cbMailAtt');
        file_put_contents($tmpName, $d['content']);
        //call the api method
        $filesApiObject->upload(array('pid' => $objectId, 'localFile' => $tmpName, 'oid' => \CB\User::getId(), 'filename' => $d['filename'], 'content-type' => $d['content-type'], 'fileExistAction' => 'autorename'));
    }
}
Beispiel #2
0
 public static function createCaseboxFile($pid, $name, $data = null)
 {
     $path = \CB\Config::get('incomming_files_dir') . $name;
     file_put_contents($path, $data);
     $param = array('pid' => $pid, 'title' => $name, 'localFile' => $path, 'owner' => $_SESSION['user']['id'], 'tmplId' => \CB\Config::get('default_file_template'), 'fileExistAction' => 'newversion');
     $fl = new \CB\Api\Files();
     $fl->upload($param);
     \CB\Solr\Client::runCron();
 }
Beispiel #3
0
 public static function createCaseboxFile($pid, $name, $data = null)
 {
     $path = \CB\Config::get('incomming_files_dir') . $name;
     file_put_contents($path, $data);
     $action = 'newversion';
     //check if file exists and its size is 0
     $id = \CB\Files::getFileId($pid, $name);
     if (!empty($id)) {
         if (\CB\Files::getSize($id) <= 1) {
             $action = 'replace';
         }
     }
     $param = array('pid' => $pid, 'title' => $name, 'localFile' => $path, 'owner' => $_SESSION['user']['id'], 'tmplId' => \CB\Config::get('default_file_template'), 'fileExistAction' => $action);
     $fl = new \CB\Api\Files();
     $fl->upload($param);
     \CB\Solr\Client::runCron();
 }