Example #1
0
 /**
  * This validator method checks if srcid is a valid crash report ID or
  * debug info ID. 
  */
 public function checkSrcId()
 {
     if ($this->type == ProcessingError::TYPE_CRASH_REPORT_ERROR) {
         $crashReport = CrashReport::model()->find('id=' . $this->srcid);
         if ($crashReport === Null) {
             $this->addError('srcid', 'SrcID must be a valid crash report ID.');
             return false;
         }
     } else {
         if ($this->type == ProcessingError::TYPE_DEBUG_INFO_ERROR) {
             $debugInfo = DebugInfo::model()->find('id=' . $this->srcid);
             if ($debugInfo === Null) {
                 $this->addError('srcid', 'SrcID must be a valid debug info ID.');
                 return false;
             }
         }
     }
     return true;
 }
Example #2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = DebugInfo::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #3
0
 /**
  * Returns count of debug info files in this project.
  * @param integer  $totalFileSize Total file size in bytes.
  * @param integer $percentOfDiskQuota Percent of disk quita.
  * @return integer file count.
  */
 public function getDebugInfoCount(&$totalFileSize, &$percentOfDiskQuota)
 {
     // Find all debug info files belonging to this project and having
     // $appver application version.
     $criteria = new CDbCriteria();
     $criteria->compare('project_id', $this->id, false, 'AND');
     $debugInfoFiles = DebugInfo::model()->findAll($criteria);
     // Calculate count of debug info
     $count = count($debugInfoFiles);
     // Calculate total file size
     $totalFileSize = 0;
     foreach ($debugInfoFiles as $debugInfo) {
         $totalFileSize += $debugInfo->filesize;
     }
     // Calc percent of disk quota
     if ($this->debug_info_files_disc_quota <= 0) {
         $percentOfDiskQuota = -1;
     } else {
         $percentOfDiskQuota = 100 * $totalFileSize / ($this->debug_info_files_disc_quota * 1024 * 1024);
     }
     // Return file count
     return $count;
 }
Example #4
0
 /**
  * Generates a debug info upload statistics for current project and
  * desired time period.
  * @param type $w Image width.
  * @param type $h Image height.
  * @param type $period Time period (7, 30 or 365).
  * @return void
  */
 public static function generateDebugInfoUploadStat($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();
     // Prepare data
     $data = 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 count of crash reports received within the period
         $criteria = new CDbCriteria();
         $criteria->compare('project_id', $curProjectId);
         $criteria->addBetweenCondition('dateuploaded', $dateFrom, $curDate);
         $count = DebugInfo::model()->count($criteria);
         // Add an item to data
         $item = array($period > 30 ? date('M y', $curDate) : date('j M', $curDate) => $count);
         $data = $item + $data;
         // Next time interval
         $curDate = $dateFrom - 1;
     }
     $graph = new ezcGraphLineChart();
     $graph->palette = new ezcGraphPaletteEzBlue();
     $graph->data['Versions'] = new ezcGraphArrayDataSet($data);
     $majorStep = round(max($data));
     if ($majorStep == 0) {
         $majorStep = 1;
     }
     $graph->yAxis->majorStep = $majorStep;
     $graph->yAxis->minorStep = $graph->yAxis->majorStep / 5;
     $graph->xAxis->labelCount = 30;
     $graph->options->fillLines = 210;
     $graph->legend = false;
     $graph->legend->position = ezcGraph::RIGHT;
     $graph->options->font->name = 'Tahoma';
     $graph->options->font->maxFontSize = 12;
     $graph->options->font->minFontSize = 1;
     if ($file === null) {
         $graph->renderToOutput($w, $h);
     } else {
         $graph->render($w, $h, $file);
     }
 }
Example #5
0
 public function testDumpFileAttachmentContent()
 {
     // Login as root
     $model = new LoginForm('RegularLogin');
     $model->username = "******";
     $model->password = "******";
     $this->assertTrue($model->login());
     // Create temp file
     $tmpfile = tempnam(Yii::app()->getRuntimePath(), "test");
     // Find a debug info file
     $debugInfo = DebugInfo::model()->findByPk(1);
     $this->assertTrue($debugInfo != null);
     // Dump file content
     $debugInfo->dumpFileAttachmentContent($tmpfile);
     // Ensure the file exists
     $this->assertTrue(file_exists($tmpfile));
     // Ensure file size is not 0
     $this->assertTrue(filesize($tmpfile) > 0);
     // Remove temp file
     unlink($tmpfile);
 }
Example #6
0
 private function deletePendingDebugInfoFiles()
 {
     // Add a message to log
     Yii::log("Checking for debug info records marked for deletion...", "info");
     // Get debug info files that have status 'Pending Delete'
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     $criteria->condition = 'status=' . DebugInfo::STATUS_PENDING_DELETE;
     $criteria->limit = 20;
     $debugInfoFiles = DebugInfo::model()->findAll($criteria);
     if ($debugInfoFiles == Null) {
         Yii::log('There are no debug info files waiting for deletion', 'info');
     } else {
         Yii::log('Found ' . count($debugInfoFiles) . ' debug info file(s) ready for deletion', 'info');
     }
     foreach ($debugInfoFiles as $debugInfo) {
         // Determine path to debug info file
         $fileName = $debugInfo->getLocalFilePath();
         // Format daemon command
         $command = 'assync dumper --delete-debug-info "' . $fileName . '"';
         // Execute the command
         $responce = "";
         $retCode = Yii::app()->daemon->execCommand($command, $responce);
         if ($retCode != 0) {
             Yii::log('Error executing command ' . $command . ', response = ' . $responce, 'error');
             continue;
         }
         // Check responce and get command ID from server responce
         $matches = array();
         $check = preg_match('#Assync command \\{([0-9]{1,6}.[0-9]{1,9})\\} has been added to the request queue.#', $responce, $matches);
         if (!$check || !isset($matches[1])) {
             Yii::log('Unexpected response from command ' . $command . ', responce = ' . $responce, 'error');
             continue;
         }
         // Begin DB transaction
         $transaction = Yii::app()->db->beginTransaction();
         try {
             // Create a new operation record in {{operation}} table.
             $op = new Operation();
             $op->status = Operation::STATUS_STARTED;
             $op->timestamp = time();
             $op->srcid = $debugInfo->id;
             $op->cmdid = $matches[1];
             $op->optype = Operation::OPTYPE_DELETE_DEBUG_INFO;
             $op->operand1 = $fileName;
             if (!$op->save()) {
                 throw new Exception('Could not save an operation record');
             }
             // Update existing debug info record in {{debuginfo}} table.
             $debugInfo->status = DebugInfo::STATUS_DELETE_IN_PROGRESS;
             if (!$debugInfo->save()) {
                 //$errors = $crashReport->getErrors();
                 //print_r($errors);
                 throw new Exception('Could not save a debug info record ');
             }
             // Commit transaction
             $transaction->commit();
         } catch (Exception $e) {
             // Roll back transaction
             $transaction->rollBack();
             // Add an error message to log
             Yii::log('An exception caught: ' . $e->getMessage(), "error");
         }
     }
     Yii::log("Finished checking for debug info files ready for deletion.", "info");
 }