Пример #1
0
 public function testGetCrashReportCount()
 {
     // Login as root
     $loginForm = new LoginForm('RegularLogin');
     $loginForm->username = "******";
     $loginForm->password = "******";
     $this->assertTrue($loginForm->login());
     // Find a crash group
     $model = CrashGroup::model()->findByPk(1);
     // Ensure found
     $this->assertTrue($model != null);
     // Get crash report count in group
     $totalFileSize = 0;
     $percentOfQuota = 0;
     $count = $model->getCrashReportCount(1, $totalFileSize, $percentOfQuota);
     $this->assertTrue($count == 1);
     $this->assertTrue($totalFileSize == 23870);
     $this->assertTrue($percentOfQuota > 0);
 }
Пример #2
0
 /**
  * This method looks for an existing crash group for the given crash report
  * and if the crash group doesn't exist, it creates a new one.
  * @return CrashGroup crash group model, or Null on error.
  */
 public function createCrashGroup()
 {
     // Get crash group title
     $crashGroupMD5 = "";
     $crashGroupTitle = $this->getCrashGroupTitle($crashGroupMD5);
     Yii::log('Crash group title = ' . $crashGroupTitle, 'info');
     Yii::log('Crash group MD5 = ' . $crashGroupMD5, 'info');
     $criteria = new CDbCriteria();
     $criteria->compare('project_id', $this->project_id);
     $criteria->compare('appversion_id', $this->appversion_id);
     $criteria->compare('md5', $crashGroupMD5);
     // Look for existing crash group
     $crashGroup = CrashGroup::model()->find($criteria);
     if ($crashGroup === Null) {
         // Not found, create new crash group
         // First check if such a title already presents
         $criteria = new CDbCriteria();
         $criteria->compare('project_id', $this->project_id);
         $criteria->compare('appversion_id', $this->appversion_id);
         $criteria->addSearchCondition('title', $crashGroupTitle);
         $count = CrashGroup::model()->count($criteria);
         if ($count != 0) {
             // Add suffix to the title to avoid similar group names
             $postfix = ' (' . ($count + 1) . ')';
             $crashGroupTitle .= $postfix;
         }
         // Create new crash group
         $crashGroup = new CrashGroup();
         $crashGroup->title = $crashGroupTitle;
         $crashGroup->md5 = $crashGroupMD5;
         $crashGroup->project_id = $this->project_id;
         $crashGroup->appversion_id = $this->appversion_id;
         if (!$crashGroup->save()) {
             // Error saving crash group record
             return Null;
         }
     }
     // Return crash group
     return $crashGroup;
 }
Пример #3
0
 /**
  * Returns the array of top crash groups. 
  * @param Optional. If specified, search is performed for the given version.
  * @return array The list of CrashGroup models.
  */
 public function getTopCrashGroups($appver = null)
 {
     $criteria = new CDbCriteria();
     $criteria->select = 't.*, COUNT({{crashreport}}.id) AS crashReportCount';
     $criteria->compare('t.project_id', $this->id, false, 'AND');
     if ($appver != null && $appver != -1) {
         $criteria->compare('t.appversion_id', $appver, false, 'AND');
     }
     $criteria->join = 'INNER JOIN {{crashreport}} ON {{crashreport}}.groupid = t.id';
     $criteria->group = 't.id';
     $criteria->order = 'crashReportCount DESC';
     $criteria->limit = 10;
     $crashGroups = CrashGroup::model()->findAll($criteria);
     return $crashGroups;
 }
Пример #4
0
 /**
  * This method is executed before AR is saved to database.
  * In this method, we set some model attributes.
  * @return boolean True on success.
  */
 protected function beforeSave()
 {
     if (!parent::beforeSave()) {
         return false;
     }
     // Check if this is a new record.
     if ($this->isNewRecord) {
         // Set project id
         $this->project_id = Yii::app()->user->getCurProjectId();
         // Set project version
         $curVer = false;
         $versions = Yii::app()->user->getCurProjectVersions($curVer);
         if ($curVer != Project::PROJ_VER_ALL) {
             $this->appversion_id = $curVer;
         } else {
             // Project version '<all>' currently selected.
             // We have to determine bug version from associated
             // crash reports/collections.
             $numbers = MiscHelpers::splitNumberList($this->crashgroups);
             foreach ($numbers as $number) {
                 $crashGroup = CrashGroup::model()->findByPk($number);
                 if ($crashGroup === Null) {
                     throw new HttpException('Invalid crash group ID');
                 }
                 $curVer = $crashGroup->appversion_id;
                 break;
             }
             if ($curVer == -1) {
                 $numbers = MiscHelpers::splitNumberList($this->crashreports);
                 foreach ($numbers as $number) {
                     $crashReport = CrashReport::model()->findByPk($number);
                     if ($crashReport === Null) {
                         throw new HttpException('Invalid crash report ID');
                     }
                     $curVer = $crashReport->appversion_id;
                     break;
                 }
             }
             if ($curVer == -1) {
                 throw new CHttpException(403, 'Invalid request');
             }
             $this->appversion_id = $curVer;
         }
         // Set date created
         $this->date_created = time();
         // Set date last modified
         $this->date_last_modified = $this->date_created;
         // Set reported by
         $this->reported_by = Yii::app()->user->id;
         if ($this->assigned_to < 0) {
             unset($this->assigned_to);
         }
     } else {
         // Set date last modified
         $this->date_last_modified = time();
         if ($this->status > Bug::STATUS_OPEN_MAX) {
             $this->date_closed = $this->date_last_modified;
         } else {
             unset($this->date_closed);
         }
     }
     // Success.
     return true;
 }
Пример #5
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 = CrashGroup::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }