コード例 #1
0
ファイル: JsonHistory.php プロジェクト: playdayteam/jdocgen
 public static function getCrossVersionDiffData()
 {
     $result = [];
     //берем две последние версии
     $versions = self::getLast2Versions();
     if (count($versions) == 2) {
         $modelPrev = JsonHistory::find()->where(['version' => $versions[0]])->orderBy('id DESC')->one();
         $modelCurrent = JsonHistory::find()->where(['version' => $versions[1]])->orderBy('id DESC')->one();
         if ($modelPrev && $modelCurrent) {
             $result = JsonSchemaDiff::diff(json_decode($modelPrev->content, 1), json_decode($modelCurrent->content, 1));
         }
     }
     return $result;
 }
コード例 #2
0
 public function saveToDb()
 {
     $content = $this->getDocData();
     $hash = md5($content);
     $version = $this->getVersion();
     $model = JsonHistory::find()->where(['hash' => $hash, 'version' => $version])->one();
     if (!$model) {
         $model = new JsonHistory();
         $model->content = $content;
         $model->hash = $hash;
         $model->version = $version;
         $model->created_at = time();
         $model->size = strlen($content);
         if (!$model->save()) {
             var_dump($model->errors);
             die(__METHOD__);
         }
     }
 }
コード例 #3
0
ファイル: DiffWidget.php プロジェクト: playdayteam/jdocgen
 public function run()
 {
     $models = JsonHistory::find()->where(['version' => \Yii::$app->docParser->getVersion()])->orderBy('created_at DESC')->all();
     $crossVersionData = JsonHistory::getCrossVersionDiffData();
     return $this->render('diffWidget/main', ['crossVersionData' => $crossVersionData, 'models' => $models]);
 }