Пример #1
0
 /**
  * Get the project's milestones.
  *
  * @return  $this
  *
  * @since   1.0
  */
 protected function processMilestones()
 {
     $this->out(g11n3t('Fetching milestones...'), false);
     /* @type \Joomla\Database\DatabaseDriver $db */
     $db = $this->getContainer()->get('db');
     $table = new MilestonesTable($db);
     $milestones = array_merge($this->github->issues->milestones->getList($this->project->gh_user, $this->project->gh_project, 'open'), $this->github->issues->milestones->getList($this->project->gh_user, $this->project->gh_project, 'closed'));
     $titles = array();
     $cntUpdated = 0;
     $cntNew = 0;
     foreach ($milestones as $milestone) {
         try {
             $table->milestone_id = null;
             // Check if the milestone exists
             $table->load(array('project_id' => $this->project->project_id, 'milestone_number' => $milestone->number));
             // Values that may have changed
             $table->title = $milestone->title;
             $table->description = $milestone->description;
             $table->state = $milestone->state;
             $table->due_on = $milestone->due_on ? (new Date($milestone->due_on))->format('Y-m-d H:i:s') : null;
             $table->store(true);
             ++$cntUpdated;
         } catch (\RuntimeException $e) {
             // New milestone
             $table->milestone_number = $milestone->number;
             $table->project_id = $this->project->project_id;
             $table->title = $milestone->title;
             $table->description = $milestone->description;
             $table->state = $milestone->state;
             $table->due_on = $milestone->due_on ? (new Date($milestone->due_on))->format('Y-m-d H:i:s') : null;
             $table->store(true);
             ++$cntNew;
         }
         $titles[] = $milestone->title;
     }
     // Check for deleted milestones
     $ids = $db->setQuery($db->getQuery(true)->from($db->quoteName($table->getTableName()))->select('milestone_id')->where($db->quoteName('project_id') . ' = ' . $this->project->project_id)->where($db->quoteName('title') . ' NOT IN (\'' . implode("', '", $titles) . '\')'))->loadRowList();
     if ($ids) {
         // Kill the orphans
         $db->setQuery($db->getQuery(true)->delete($db->quoteName($table->getTableName()))->where($db->quoteName('milestone_id') . ' IN (' . implode(', ', $ids) . ')'))->execute();
     }
     $cntDeleted = count($ids);
     return $this->out('ok')->logOut(sprintf(g11n3t('Milestones: %1$d new, %2$d updated, %3$d deleted.'), $cntNew, $cntUpdated, $cntDeleted));
 }
Пример #2
0
 /**
  * Get the milestones for the active project.
  *
  * @return  array  An associative array of the milestone id's keyed by the Github milestone number.
  *
  * @since   1.0
  */
 private function getMilestones()
 {
     /* @type \Joomla\Database\DatabaseDriver $db */
     $db = $this->getContainer()->get('db');
     $table = new MilestonesTable($db);
     $milestoneList = $db->setQuery($db->getQuery(true)->from($db->quoteName($table->getTableName()))->select(array('milestone_number', 'milestone_id'))->where($db->quoteName('project_id') . ' = ' . $this->project->project_id))->loadAssocList('milestone_number', 'milestone_id');
     return $milestoneList;
 }
Пример #3
0
 /**
  * Get a list of labels defined for the project.
  *
  * @return  array
  *
  * @since   1.0
  */
 public function getMilestones()
 {
     static $milestones = [];
     if (!$milestones) {
         $db = $this->database;
         $table = new MilestonesTable($db);
         $milestones = $db->setQuery($db->getQuery(true)->from($db->quoteName($table->getTableName()))->select(array('milestone_id', 'milestone_number', 'title', 'description', 'state', 'due_on'))->where($db->quoteName('project_id') . ' = ' . $this->project_id)->order($db->quoteName('milestone_number')))->loadObjectList();
     }
     return $milestones;
 }