You are here

function hackedProject::identify_project in Hacked! 8.2

Identify the project from the name we've been created with.

We leverage the update (status) module to get the data we require about projects. We just pull the information in, and make descisions about this project being from CVS or not.

3 calls to hackedProject::identify_project()
hackedProject::download_remote_project in src/hackedProject.php
Downloads the remote project to be hashed later.
hackedProject::title in src/hackedProject.php
Get the Human readable title of this project.
hackedProject::__construct in src/hackedProject.php
Constructor.

File

src/hackedProject.php, line 75

Class

hackedProject
Encapsulates a Hacked! project.

Namespace

Drupal\hacked

Code

function identify_project() {

  // Only do this once, no matter how many times we're called.
  if (!empty($this->project_identified)) {
    return;
  }

  // Fetch the required data from the update (status) module.
  // TODO: clean this up.
  $available = update_get_available(TRUE);
  $data = update_calculate_project_data($available);
  $releases = \Drupal::keyValueExpirable('update_available_releases')
    ->getAll();
  foreach ($data as $key => $project) {
    if ($key == $this->name) {
      $this->project_info = $project;
      if (!isset($this->project_info['releases']) || !is_array($this->project_info['releases'])) {
        $this->project_info['releases'] = array();
      }
      if (isset($releases[$key]['releases']) && is_array($releases[$key]['releases'])) {
        $this->project_info['releases'] += $releases[$key]['releases'];
      }

      // Add in the additional info that update module strips out.
      // This is a really naff way of doing this, but update (status) module
      // ripped out a lot of useful stuff in issue:
      // http://drupal.org/node/669554
      $this->project_identified = TRUE;
      $this->existing_version = $this->project_info['existing_version'];
      $this->project_type = $this->project_info['project_type'];
      break;
    }
  }

  // Logging.
  if (!$this->project_identified) {
    $message = $this
      ->t('Could not identify project: @name', array(
      '@name' => $this->name,
    ));
    \Drupal::logger('hacked')
      ->warning($message
      ->render());
  }
}