コード例 #1
0
 /**
  * Projects list
  *
  * @return string
  */
 public function actionIndex()
 {
     $query = Project::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
コード例 #2
0
 /**
  * Collect contributions for specified project and date.
  *
  * If projectId is not set, collect contributions for any project.
  * If dateFrom is not set, collect contributions from last check point.
  * If last check point is not set, collect contributions from 2 last days.
  *
  * @param string $dateFrom Date from in Y-m-d H:i:s format. Null if need collect from last check point
  * @param integer $projectId Project identifier or null if need collect for any project
  */
 public function actionCollectContributions($dateFrom = null, $projectId = null)
 {
     $checkpointFile = Yii::getAlias('@runtime/contribution-collector-date.txt');
     if (is_null($dateFrom) && is_file($checkpointFile)) {
         $dateFrom = trim(file_get_contents($checkpointFile));
     } elseif (is_null($dateFrom)) {
         $dateFrom = date('Y-m-d H:i:s', strtotime('-2 day'));
     }
     file_put_contents($checkpointFile, date('Y-m-d H:i:s'));
     $dateFrom = DateTime::createFromFormat('Y-m-d H:i:s', $dateFrom);
     if ($dateFrom === false) {
         $this->stderr('Wrong date time format', Console::FG_RED);
         return 1;
     }
     /* @var $projectApi ProjectModule */
     $projectApi = Yii::$app->getModule('project');
     /* @var $contributorApi ContributorApi */
     $contributorApi = Yii::$app->contributors;
     $resProject = Project::find();
     if (!is_null($projectId) && is_scalar($projectId)) {
         $resProject->andWhere(['id' => (int) $projectId]);
     }
     $this->logInfo('Total projects count: ', $resProject->count());
     foreach ($resProject->each() as $project) {
         /* @var $project Project */
         $this->logInfo('Collect contributions for: ', $project->title);
         // calculate sum
         $cntCollected = 0;
         $cntErrors = 0;
         foreach ($projectApi->getProjectContributions($project, $dateFrom) as $commit) {
             /* @var $commit BaseCommit */
             $contributor = $contributorApi->getContributor($project->repo_type, $commit->contributorName, $commit->contributorEmail);
             $model = $projectApi->createContributionReview($project, $commit, $contributor);
             if ($model) {
                 $this->stdout('.', Console::FG_GREEN);
                 $cntCollected++;
             } else {
                 $this->stdout('x', Console::FG_RED);
                 $cntErrors++;
             }
         }
         $this->stdout("\n");
         $this->logInfo('Collected: ', $cntCollected);
         $this->logInfo('Errors: ', $cntErrors);
     }
 }