Example #1
0
 public function testDumpFileAttachmentContent()
 {
     // Find
     $model = BugAttachment::model()->findByPk(1);
     $this->assertTrue($model != null);
     // Create temp file for output
     $outFile = tempnam(Yii::app()->getRuntimePath(), "test");
     $model->dumpFileAttachmentContent($outFile);
     // Ensure the file exists
     $this->assertTrue(file_exists($outFile));
     // Ensure file size is not 0
     $this->assertTrue(filesize($outFile) > 0);
     // Delete file
     @unlink($outFile);
 }
Example #2
0
 /**
  * Downloads a bug attachment file.
  * @param type $id
  * @throws CHttpException 
  */
 public function actionDownloadAttachment($id)
 {
     $bugAttachment = BugAttachment::model()->findByPk($id);
     if ($bugAttachment === null) {
         throw new CHttpException(403, 'Invalid request');
     }
     // Get the bug this attachment belongs to
     $bug = $bugAttachment->bugChange->bug;
     // Check that user is authorized to access this model
     $this->checkAuthorization($bug);
     // Dump contents of the attachment
     $bugAttachment->dumpFileAttachmentContent();
 }
Example #3
0
 /**
  * Returns count of bug attachment files in this project. 
  * @param integer $totalFileSize On output, receives the total size in bytes of files.
  * @param integer $percentOfDiskQuota On output, receives percent of disk quota.
  * @param integer $appver Optional. If specified, count of files is calculated for the given version.
  * @return integer count of bug attachment files.
  */
 public function getBugAttachmentCount(&$totalFileSize, &$percentOfDiskQuota, $appver = Project::PROJ_VER_ALL)
 {
     // Find all bug attachment files belonging to this project and having
     // $appver application version.
     $criteria = new CDbCriteria();
     $criteria->compare('b.project_id', $this->id, false, 'AND');
     if ($appver != Project::PROJ_VER_ALL) {
         $criteria->compare('b.appversion_id', $appver, false, 'AND');
     }
     $criteria->join = 'LEFT JOIN {{bug_change}} bc ON t.bug_change_id=bc.id';
     $criteria->join .= ' LEFT JOIN {{bug}} b ON bc.bug_id=b.id';
     $bugAttachments = BugAttachment::model()->findAll($criteria);
     // Calculate count of bug attachments
     $count = count($bugAttachments);
     // Calculate total file size
     $totalFileSize = 0;
     foreach ($bugAttachments as $bugAttachment) {
         $totalFileSize += $bugAttachment->filesize;
     }
     // Calc percent of disk quota
     if ($this->bug_attachment_files_disc_quota <= 0) {
         $percentOfDiskQuota = -1;
     } else {
         $percentOfDiskQuota = 100 * $totalFileSize / ($this->bug_attachment_files_disc_quota * 1024 * 1024);
     }
     // Return file count
     return $count;
 }