Example #1
0
 /**
  * This method saves uploaded file to its persistent location. 
  * @throws Exception
  */
 public function saveFileAttachment()
 {
     // Set filename attribute
     $this->filename = basename($this->fileAttachment->getName());
     // Set filesize attribute
     $this->filesize = $this->fileAttachment->getSize();
     // Get bug model this attachment belongs to.
     $bugChange = BugChange::model()->findByPk($this->bug_change_id);
     $bug = Bug::model()->findByPk($bugChange->bug_id);
     // Check project quota
     if ($bug->project->bug_attachment_files_disc_quota > 0) {
         $totalFileSize = 0;
         $percentOfDiskQuota = 0;
         $bug->project->getBugAttachmentCount($totalFileSize, $percentOfDiskQuota);
         if ($bug->project->bug_attachment_files_disc_quota * 1024 * 1024 - $totalFileSize - $this->filesize < 0) {
             $this->addError('fileAttachment', 'Bug attachment quota for this project has exceeded.');
             throw new Exception('Bug attachment quota constrained.');
         }
     }
     // Calc md5 hash and save it as model attribute
     $this->md5 = md5_file($this->fileAttachment->getTempName());
     // Create the directory where we will place the uploaded file
     $subDir1 = substr($this->md5, 0, 3);
     $subDir2 = substr($this->md5, 3, 3);
     $dirName = Yii::app()->getBasePath() . "/data/bugAttachments/" . $subDir1 . "/" . $subDir2;
     if (!@is_dir($dirName)) {
         if (False == @mkdir($dirName, 0777, TRUE)) {
             $error = error_get_last();
             $this->addError("fileAttachment", "Couldn't make directory for file attachment.");
             throw new Exception('Could not make directory for file attachment.');
         }
     }
     // Move uploaded file to an appropriate directory and delete temp file
     $fileName = $dirName . "/" . $this->md5;
     if (!$this->fileAttachment->saveAs($fileName, true) && !$this->ignoreFileAttachmentErrors) {
         $this->addError("fileAttachment", "Couldn't save file attachment");
         throw new Exception('Could not save file attachment');
     }
 }
Example #2
0
 /**
  * Returns the array of recent bugs. 
  * @param Optional. If specified, search is performed for the given version.
  * @return boolean The list of BugChange models.
  */
 public function getRecentBugChanges($appver = null)
 {
     $criteria = new CDbCriteria();
     $criteria->compare('bug.project_id', $this->id, false, 'AND');
     if ($appver != null) {
         if ($appver != '-1') {
             $criteria->compare('bug.appversion_id', $appver, false, 'AND');
         }
     }
     $criteria->order = 'crashReportCount DESC';
     $criteria->with = 'bug';
     $criteria->order = 't.timestamp DESC';
     $criteria->limit = 10;
     $bugChanges = BugChange::model()->findAll($criteria);
     return $bugChanges;
 }
Example #3
0
 /**
  * Generates a bug status dynamics graph for current project and desired
  * time period.
  * @param integer $w Image width.
  * @param integer $h Image height.
  * @param integer $period Time period (7, 30 or 365). 
  * @return void
  */
 public static function generateBugStatusDynamicsGraph($w, $h, $period, $file = null)
 {
     if (!is_numeric($w) || $w <= 0 || $w > 1024) {
         throw new CHttpException(403, 'Invalid parameter');
     }
     if (!is_numeric($h) || $h <= 0 || $h > 960) {
         throw new CHttpException(403, 'Invalid parameter');
     }
     if (!is_numeric($period) || $period <= 0 || $period > 365) {
         throw new CHttpException(403, 'Invalid parameter');
     }
     // Get current project info
     $curProjectId = Yii::app()->user->getCurProjectId();
     $curVer = Yii::app()->user->getCurProjectVer();
     // Prepare data
     $dataAll = array();
     $dataOpen = array();
     $dataClosed = array();
     $dataFixed = array();
     $dataVerified = array();
     $tomorrow = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
     $finishDate = $tomorrow - 1;
     $curDate = $finishDate;
     $dateFrom = $curDate;
     while ($finishDate - $curDate < $period * 24 * 60 * 60) {
         // Calc the beginning of time interval
         if ($period > 30) {
             $dateFrom = mktime(0, 0, 0, date("m", $curDate) - 1, date("d", $curDate), date("Y", $curDate));
         } else {
             if ($period > 7) {
                 $dateFrom = mktime(0, 0, 0, date("m", $curDate), date("d", $curDate) - 6, date("Y", $curDate));
             } else {
                 $dateFrom = mktime(0, 0, 0, date("m", $curDate), date("d", $curDate), date("Y", $curDate));
             }
         }
         // Get bug changes within the period
         $criteria = new CDbCriteria();
         $criteria->compare('bug.project_id', $curProjectId, false, 'AND');
         if ($curVer != -1) {
             $criteria->compare('bug.appversion_id', $curVer, false, 'AND');
         }
         $criteria->addCondition('t.status_change_id IS NOT NULL', 'AND');
         $criteria->addCondition('t.timestamp <=' . $curDate, 'AND');
         $criteria->addCondition('t.id IN (SELECT MAX({{bug_change}}.id) FROM {{bug_change}} GROUP BY {{bug_change}}.bug_id)', 'AND');
         $criteria->with = array('bug', 'statuschange');
         $bugChanges = BugChange::model()->findAll($criteria);
         $countAll = 0;
         $countOpen = 0;
         $countClosed = 0;
         $countFixed = 0;
         $countVerified = 0;
         foreach ($bugChanges as $bugChange) {
             //print_r($bugChange->statuschange->status);
             if ($bugChange->statuschange->status < Bug::STATUS_OPEN_MAX) {
                 $countOpen++;
             } else {
                 if ($bugChange->statuschange->status > Bug::STATUS_OPEN_MAX) {
                     $countClosed++;
                 }
             }
             if ($bugChange->statuschange->status == Bug::STATUS_FIXED) {
                 $countFixed++;
             }
             if ($bugChange->statuschange->status == Bug::STATUS_VERIFIED) {
                 $countVerified++;
             }
         }
         // Add an item to data
         $key = $period > 30 ? date('M y', $curDate) : date('j M', $curDate);
         $dataAll = array($key => $countOpen + $countClosed) + $dataAll;
         $dataOpen = array($key => $countOpen) + $dataOpen;
         $dataClosed = array($key => $countClosed) + $dataClosed;
         $dataFixed = array($key => $countFixed) + $dataFixed;
         $dataVerified = array($key => $countVerified) + $dataVerified;
         // Next time interval
         $curDate = $dateFrom - 1;
     }
     /*var_dump($dataAll);
     		var_dump($dataOpen);
     		var_dump($dataClosed);
     		var_dump($dataFixed);
     		var_dump($dataVerified);
     		return;*/
     // Create graph
     $graph = new ezcGraphLineChart();
     $graph->palette = new ezcGraphPaletteEzBlue();
     $graph->palette->dataSetColor = array('#0000FF', '#FF0000', '#00FF00', '#000000');
     $graph->data['All'] = new ezcGraphArrayDataSet($dataAll);
     $graph->data['Open'] = new ezcGraphArrayDataSet($dataOpen);
     $graph->data['Fixed'] = new ezcGraphArrayDataSet($dataFixed);
     $graph->data['Verified'] = new ezcGraphArrayDataSet($dataVerified);
     $graph->yAxis->majorStep = 10;
     $graph->yAxis->minorStep = 1;
     $graph->xAxis->labelCount = 30;
     $graph->options->fillLines = 210;
     $graph->legend = true;
     $graph->legend->position = ezcGraph::BOTTOM;
     $graph->options->font->name = 'Tahoma';
     if ($file === null) {
         $graph->renderToOutput($w, $h);
     } else {
         $graph->render($w, $h, $file);
     }
 }