Beispiel #1
0
 /**
  * This method creates a new db record if such a version does not exist yet.
  * @param string $appversion Version string.
  * @return AppVersion On success, returns AppVersion object; otherwise Null.
  */
 public static function createIfNotExists($appversion, $project_id = null)
 {
     if ($project_id == null) {
         $project_id = Yii::app()->user->getCurProjectId();
     }
     if ($project_id == null) {
         return Null;
     }
     // Ensure that project_id is a valid project ID
     $project = Project::model()->findByPk($project_id);
     if ($project == null) {
         return Null;
     }
     // Try to find an existing version with such a name
     $criteria = new CDbCriteria();
     $criteria->compare('project_id', $project_id, false, 'AND');
     $criteria->compare('version', $appversion, false, 'AND');
     $model = AppVersion::model()->find($criteria);
     if ($model != Null) {
         return $model;
     }
     $model = new AppVersion();
     $model->project_id = $project_id;
     $model->version = $appversion;
     if (!$model->save()) {
         return Null;
     }
     return $model;
 }