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));
 }
Example #2
0
 /**
  * Get a set of ids from label names.
  *
  * @param   array  $labelObjects  Array of label objects
  *
  * @return  array
  *
  * @since   1.0
  */
 private function getLabelIds($labelObjects)
 {
     static $labels = array();
     if (!$labels) {
         /* @type \Joomla\Database\DatabaseDriver $db */
         $db = $this->getContainer()->get('db');
         $table = new LabelsTable($db);
         $labelList = $db->setQuery($db->getQuery(true)->from($db->quoteName($table->getTableName()))->select(array('label_id', 'name'))->where($db->quoteName('project_id') . ' = ' . $this->project->project_id))->loadObjectList();
         foreach ($labelList as $labelObject) {
             $labels[$labelObject->name] = $labelObject->label_id;
         }
     }
     $ids = array();
     foreach ($labelObjects as $label) {
         if (!array_key_exists($label->name, $labels)) {
             // @todo Label does not exist :( - reload labels for the project
         } else {
             $ids[] = $labels[$label->name];
         }
     }
     return $ids;
 }
Example #3
0
 /**
  * Get a list of labels defined for the project.
  *
  * @return  array
  *
  * @since   1.0
  */
 public function getLabels()
 {
     static $labels = array();
     if (!$labels) {
         $db = $this->database;
         $table = new LabelsTable($db);
         $labelList = $db->setQuery($db->getQuery(true)->from($db->quoteName($table->getTableName()))->select(array('label_id', 'name', 'color'))->where($db->quoteName('project_id') . ' = ' . $this->project_id))->loadObjectList();
         foreach ($labelList as $labelObject) {
             $l = new \stdClass();
             $l->name = $labelObject->name;
             $l->color = $labelObject->color;
             $labels[$labelObject->label_id] = $l;
         }
     }
     return $labels;
 }