Example #1
0
 /**
  * Get the project labels.
  *
  * @return  $this
  *
  * @since   1.0
  */
 protected function processLabels()
 {
     $this->out(g11n3t('Fetching labels...'), false);
     /* @type \Joomla\Database\DatabaseDriver $db */
     $db = $this->getContainer()->get('db');
     $table = new LabelsTable($db);
     $labels = $this->github->issues->labels->getList($this->project->gh_user, $this->project->gh_project);
     $names = array();
     $cntUpdated = 0;
     $cntNew = 0;
     foreach ($labels as $label) {
         try {
             $table->label_id = null;
             // Check if the label exists
             $table->load(array('project_id' => $this->project->project_id, 'name' => $label->name));
             // Values that may have changed
             if ($table->color != $label->color) {
                 $table->color = $label->color;
                 $table->store();
                 ++$cntUpdated;
             }
         } catch (\RuntimeException $e) {
             // New label
             $table->project_id = $this->project->project_id;
             $table->name = $label->name;
             $table->color = $label->color;
             $table->store();
             ++$cntNew;
         }
         $names[] = $label->name;
     }
     // Check for deleted labels
     $ids = $db->setQuery($db->getQuery(true)->from($db->quoteName($table->getTableName()))->select('label_id')->where($db->quoteName('project_id') . ' = ' . $this->project->project_id)->where($db->quoteName('name') . ' NOT IN (\'' . implode("', '", $names) . '\')'))->loadColumn();
     if ($ids) {
         // Kill the orphans
         $db->setQuery($db->getQuery(true)->delete($db->quoteName($table->getTableName()))->where($db->quoteName('label_id') . ' IN (' . implode(', ', $ids) . ')'))->execute();
     }
     $cntDeleted = count($ids);
     return $this->out('ok')->logOut(sprintf(g11n3t('Labels: %1$d new, %2$d updated, %3$d deleted.'), $cntNew, $cntUpdated, $cntDeleted));
 }