protected function findOrCreateEnvironmentId($text)
 {
     $text = preg_replace('/\\x0d\\x0a|\\x0d|\\x0a/', "\n", (string) $text);
     $text = trim($text);
     if ($text === '') {
         return null;
     }
     $hash = rtrim(base64_encode(hash('sha256', $text, true)), '=');
     $model = Environment::findOne(['sha256sum' => $hash]);
     if ($model) {
         return $model->id;
     }
     $model = new Environment();
     $model->sha256sum = $hash;
     $model->text = $text;
     if (!$model->save()) {
         throw new \Exception();
     }
     return $model->id;
 }
Exemple #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEnv()
 {
     return $this->hasOne(Environment::className(), ['id' => 'env_id']);
 }