public function actionCommits()
 {
     $http_client = new \Guzzle\Http\Client();
     $client = new \Github\Client();
     try {
         $commits = $client->api('repo')->commits()->all('KnpLabs', 'php-github-api', array('sha' => 'master'));
         foreach ($commits as $commit_info) {
             $commit_info = json_decode($http_client->get($commit_info['url'])->send()->getBody(), true);
             $commit = Commits::findOne(['sha' => $commit_info['sha']]);
             if (!$commit) {
                 $commit = new Commits();
                 $commit->sha = $commit_info['sha'];
                 $commit->user_name = $commit_info['commit']['committer']['name'];
                 $commit->date_commit = date('Y-m-d', strtotime($commit_info['commit']['committer']['date']));
                 $commit->message = $commit_info['commit']['message'];
                 $commit->save();
             }
             echo $commit->id . PHP_EOL;
             foreach ($commit_info['files'] as $file_info) {
                 $commit_file = CommitsFiles::findOne(['sha' => $file_info['sha']]);
                 if (!$commit_file) {
                     $commit_file = new CommitsFiles();
                     $commit_file->sha = $file_info['sha'];
                     $commit_file->commit_id = $commit->id;
                     $commit_file->filename = $file_info['filename'];
                     $commit_file->status = $file_info['status'];
                     $commit_file->additions = $file_info['additions'];
                     $commit_file->deletions = $file_info['deletions'];
                     $commit_file->changes = $file_info['changes'];
                     $commit_file->blob_url = $file_info['blob_url'];
                     $commit_file->date_add = $commit->date_commit;
                     if (!$commit_file->save()) {
                         print_r($commit_file->getErrors());
                         die;
                     }
                 }
                 echo '--' . $commit_file->id . PHP_EOL;
             }
         }
     } catch (\Exception $e) {
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CommitsFiles::find();
     $query->from('commits_files cm');
     $query->groupBy('filename');
     $query->select(['filename', 'date_add', 'status', 'COUNT(*) as count']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 2]]);
     $this->load($params);
     $dataProvider->setSort(['attributes' => ['filename', 'count' => ['asc' => ['count' => SORT_ASC], 'desc' => ['count' => SORT_DESC], 'default' => SORT_DESC]]]);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'commit_id' => $this->commit_id, 'additions' => $this->additions, 'deletions' => $this->deletions, 'changes' => $this->changes]);
     $query->andFilterWhere(['>=', 'date_add', $this->date_from])->andFilterWhere(['<=', 'date_add', $this->date_to]);
     $query->andFilterWhere(['like', 'filename', $this->filename])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'blob_url', $this->blob_url]);
     return $dataProvider;
 }
 /**
  * Finds the CommitsFiles model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CommitsFiles the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CommitsFiles::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }