コード例 #1
0
ファイル: FilesTest.php プロジェクト: ameliefranco/casebox
 /**
  * just a test method to upload a file and execute methods from
  * DataModel to check the result
  * @return void
  */
 public function testDataModelFilesMethods()
 {
     $api = new Api\Files();
     $fn = tempnam(sys_get_temp_dir(), 'cb_test');
     file_put_contents($fn, 'testing');
     $data = array('pid' => 1, 'localFile' => $fn, 'oid' => 1);
     $rez = $api->upload($data);
     $this->assertTrue($rez['success'], 'Upload test file failed: ' . $fn);
     $fileData = $rez['data']['file'];
     $id = $fileData['id'];
     $rez = DM\Files::getContentIds($id);
     $this->assertTrue(!empty($rez[$id]), 'Cant get content id');
     $rez = DM\Files::getContentPaths($id);
     $this->assertTrue(!empty($rez[$id]), 'Cant get content path');
     //delete the file from system and check if same actions return empty results
     $f = Objects::getCachedObject($id);
     $f->delete(true);
     // permanently delete
     unset($f);
     $rez = DM\Files::getContentIds($id);
     $this->assertTrue(empty($rez[$id]), 'Obtaining content id for a permanently deleted file');
     $rez = DM\Files::getContentPaths($id);
     $this->assertTrue(empty($rez[$id]), 'Obtaining content path for a permanently deleted file');
 }
コード例 #2
0
ファイル: Client.php プロジェクト: austinvernsonger/casebox
 /**
  * append file contents to content field for file records
  * @param  array &$records
  * @return void
  */
 protected function appendFileContents(&$records)
 {
     $fileRecords = array();
     foreach ($records as &$r) {
         if (!empty($r['template_type']) && $r['template_type'] == 'file') {
             $fileRecords[$r['id']] =& $r;
         }
     }
     if (!empty($fileRecords)) {
         $filesDir = Config::get('files_dir');
         $cpaths = DM\Files::getContentPaths(array_keys($fileRecords));
         foreach ($cpaths as $id => $cpath) {
             $r =& $fileRecords[$id];
             $filename = $filesDir . $cpath . '.gz';
             if (file_exists($filename)) {
                 $content = file_get_contents($filename);
                 $r['content'] .= "\n" . gzuncompress($content);
             }
             unset($content);
             unset($r);
         }
     }
 }
コード例 #3
0
ファイル: Files.php プロジェクト: sebbie42/casebox
 public function restoreVersion($id)
 {
     $rez = array('success' => true, 'data' => array('id' => 0, 'pid' => 0));
     $fileId = 0;
     //detect file id
     $version = DM\FilesVersions::read($id);
     if (!empty($version)) {
         $fileId = $version['file_id'];
         $rez['data']['id'] = $fileId;
     }
     //get its pid
     $r = DM\Tree::read($fileId);
     if (!empty($r['pid'])) {
         $rez['data']['pid'] = $r['pid'];
     }
     $this->saveCurrentVersion($fileId);
     DM\Files::delete($fileId);
     DM\Files::create(array('id' => $fileId, 'content_id' => $version['content_id'], 'date' => $version['date'], 'name' => $version['name'], 'cid' => $version['cid'], 'uid' => User::getId(), 'cdate' => $version['cdate'], 'udate' => $version['udate']));
     Objects::updateCaseUpdateInfo($id);
     Solr\Client::runCron();
     return $rez;
 }
コード例 #4
0
ファイル: File.php プロジェクト: sebbie42/casebox
 /**
  * copy costom files data to targetId
  * @param  int  $targetId
  * @return void
  */
 protected function copyCustomDataTo($targetId)
 {
     DM\Files::copy($this->id, $targetId);
 }
コード例 #5
0
ファイル: Comments.php プロジェクト: sebbie42/casebox
 /**
  * add attachment links below the comments body
  * @param  array reference $rez
  * @return void
  */
 protected static function addAttachmentLinks(&$rez)
 {
     //collect comment ids
     $ids = array();
     foreach ($rez['data'] as $d) {
         $ids[] = $d['id'];
     }
     if (empty($ids)) {
         return;
     }
     //select files for all loaded comments using a single solr request
     $params = array('system' => '[0 TO 2]', 'fq' => array('pid:(' . implode(' OR ', $ids) . ')', 'template_type:"file"'), 'fl' => 'id,pid,name,template_id', 'sort' => 'pid,cdate', 'rows' => 50, 'dir' => 'asc');
     $s = new \CB\Search();
     $sr = $s->query($params);
     $files = array();
     $fileIds = array();
     $fileTypes = array();
     foreach ($sr['data'] as $d) {
         $files[$d['pid']][] = $d;
         $fileIds[] = $d['id'];
     }
     //get file types
     if (!empty($fileIds)) {
         $fileTypes = DM\Files::getTypes($fileIds);
     }
     foreach ($rez['data'] as &$d) {
         if (empty($files[$d['id']])) {
             continue;
         }
         $links = array();
         foreach ($files[$d['id']] as $f) {
             $f['type'] = @$fileTypes[$f['id']];
             $links[] = static::getFileLink($f);
         }
         $d['files'] = '<ul class="comment-attachments"><li>' . implode('</li><li>', $links) . '</li></ul>';
     }
 }
コード例 #6
0
ファイル: Browser.php プロジェクト: sebbie42/casebox
 public function rename($p)
 {
     $id = explode('/', $p['path']);
     $id = array_pop($id);
     $p['name'] = trim($p['name']);
     if (!is_numeric($id) || empty($p['name'])) {
         return array('success' => false);
     }
     /* check security access */
     if (!Security::canWrite($id)) {
         throw new \Exception(L\get('Access_denied'));
     }
     $p['name'] = Purify::filename($p['name']);
     $rez = array('success' => true, 'data' => array('id' => $id, 'pid' => null, 'newName' => $p['name']));
     $objectType = Objects::getType($id);
     if ($objectType == 'shortcut') {
         $r = DM\Tree::read($id);
         if (!empty($r['target_id'])) {
             $id = $r['target_id'];
             $objectType = Objects::getType($id);
         }
     }
     DM\Tree::update(array('id' => $id, 'name' => $p['name']));
     if ($objectType == 'file') {
         DM\Files::update(array('id' => $id, 'name' => $p['name']));
     }
     /*updating renamed document into solr directly (before runing background cron)
       so that it'll be displayed with new name without delay*/
     $solrClient = new Solr\Client();
     $solrClient->updateTree(array('id' => $id));
     //running background cron to index other nodes
     $solrClient->runBackgroundCron();
     $p['name'] = htmlspecialchars($p['name'], ENT_COMPAT);
     //get pid
     $r = DM\Tree::read($rez['data']['id']);
     if (!empty($r['pid'])) {
         $rez['data']['pid'] = $r['pid'];
     }
     return $rez;
 }