Commit 2c0f6a47 authored by Fran Garcia-Linares's avatar Fran Garcia-Linares Committed by Chris Wells
Browse files

Issue #3280006 by fjgarlin, chrisfromredfin, bnjmnm, tim.plunkett: May 2022 - Update Fixture

parent 5e94f3a7
Loading
Loading
Loading
Loading
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+32 −10
Original line number Diff line number Diff line
@@ -7,7 +7,8 @@

use Composer\Semver\Semver;
use Drupal\Component\Serialization\Json;
use Drupal\project_browser\DrupalOrg\DrupalOrgProjects;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Database\Database;

/**
@@ -154,7 +155,12 @@ function _project_browser_populate_from_fixture() {
      if ($project['changed'] > $most_recent_change) {
        $most_recent_change = $project['changed'];
      }
      $query->values((array) $project);
      // Map from fixture format to the expected by the database.
      $project_data = unserialize($project['project_data']);
      $project['maintenance_status'] = $project_data['taxonomy_vocabulary_44']['id'];
      $project['development_status'] = $project_data['taxonomy_vocabulary_46']['id'];

      $query->values($project);
    }
    $query->execute();
  }
@@ -251,18 +257,32 @@ function project_browser_hacky_fixture_maker(&$sandbox) {
    ];
    $eariest_possible_timestamp_reached = NULL;
    $drupal_org_response = $current_source->getProjectsFromSource($query);
    $returned_projects = new DrupalOrgProjects($drupal_org_response['list']);
    $returned_projects = $drupal_org_response['list'];

    if ($returned_projects) {
      foreach ($returned_projects as $project) {
      foreach ($returned_projects as &$project) {
        $project['project_usage_total'] = 0;
        if (array_key_exists('project_usage', $project)) {
          foreach ($project['project_usage'] as $usage) {
            $project['project_usage_total'] += $usage;
          }
        }

        if (empty($project['body']['value'])) {
          $project['body']['value'] = '';
        }
        if (empty($project['body']['summary'])) {
          $project['body']['summary'] = $project['body']['value'];
        }
        $project['body']['summary'] = Xss::filter(strip_tags($project['body']['summary']));
        $project['body']['summary'] = Unicode::truncate($project['body']['summary'], 200, TRUE, TRUE);

        // Once we hit projects that haven't been updated since March 13, 2020, we
        // know they aren't compatible because it is before
        // https://www.drupal.org/node/3119415.
        if ($project->changed < 1583985600) {
        if ($project['changed'] < 1583985600) {
          $eariest_possible_timestamp_reached = TRUE;
          continue;
        }

      }
      $sandbox['current_page'] += 1;

@@ -286,6 +306,7 @@ function project_browser_hacky_fixture_maker(&$sandbox) {
                return FALSE;
              }
            }
            return FALSE;
          });
          if (empty($compatible_releases)) {
            // Don't include projects without any compatible releases.
@@ -302,7 +323,7 @@ function project_browser_hacky_fixture_maker(&$sandbox) {
          return [
            'version' => $release['version'],
            'status' => $release['status'],
            'date' => $release['date'],
            'date' => $release['date'] ?? NULL,
            'core_compatibility' => $release['core_compatibility'],
          ];
        }, $compatible_releases);
@@ -342,6 +363,7 @@ function project_browser_hacky_fixture_maker(&$sandbox) {
          ];
        }
      }

      return [
        'nid' => $project['nid'],
        'title' => $project['title'],
@@ -349,8 +371,8 @@ function project_browser_hacky_fixture_maker(&$sandbox) {
        'created' => $project['created'],
        'changed' => $project['changed'],
        'project_usage_total' => $project['project_usage_total'] ?? 0,
        'maintenance_status' => $project['taxonomy_vocabulary_44']['id'],
        'development_status' => $project['taxonomy_vocabulary_46']['id'],
        'taxonomy_vocabulary_44' => $project['taxonomy_vocabulary_44']['id'],
        'taxonomy_vocabulary_46' => $project['taxonomy_vocabulary_46']['id'],
        'status' => $project['status'],
        'field_security_advisory_coverage' => $project['field_security_advisory_coverage'],
        'flag_project_star_user_count' => $project['flag_project_star_user_count'] ?? 0,
+0 −257
Original line number Diff line number Diff line
<?php

namespace Drupal\project_browser\DrupalOrg;

use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\Xss;

/**
 * Represents a single project as it will be consumed by the front-end.
 */
class DrupalOrgProject {

  /**
   * Public properties.
   */
  public $author = [];

  public $body = [];

  public $created;

  public $changed;

  public $changed_ago;

  public $field_project_images = [];

  public $nid;

  public $status;

  public $type;

  public $title;

  public $url;

  public $project_usage = [];

  public $project_usage_total = 0;

  public $field_security_advisory_coverage;

  public $field_project_machine_name;

  public $field_supporting_organizations = [];

  public $flag_project_star_user_count;

  /**
   * Module categories.
   */
  public $field_module_categories;

  /**
   * Maintenance status.
   */
  public $field_maintenance_status;

  /**
   * Development status.
   */
  public $field_development_status;

  /**
   * Non-public properties.
   */
  protected $sticky;

  protected $promote;

  protected $edit_url;

  protected $language;

  protected $is_new;

  protected $vid;

  protected $flag_project_star_user;

  protected $field_issue_summary_template;

  protected $field_replaced_by;

  protected $field_next_major_version_info;

  protected $field_project_ecosystem;

  protected $field_project_issue_version_opts;

  protected $field_project_components = [];

  protected $field_project_docs;

  protected $field_project_license;

  protected $field_project_screenshots = [];

  protected $field_project_documentation;

  protected $field_project_demo;

  protected $upload = [];

  protected $field_project_changelog;

  protected $field_project_homepage;

  protected $field_release_version_format;

  protected $field_project_has_releases;

  protected $field_project_issue_guidelines;

  protected $field_project_default_component;

  protected $field_project_has_issue_queue;

  protected $field_project_type;

  protected $last_comment_timestamp;

  protected $has_new_content;

  protected $flag_tracker_follower_count;

  protected $feed_nid;

  protected $feeds_item_url;

  protected $feeds_item_guid;

  protected $comment_count_new;

  protected $comment_count;

  protected $comments;

  protected $comment;

  protected $book_ancestors;

  /**
   * Constructs a new DrupalOrgProject.
   *
   * @param array $project
   *   The raw data for a project.
   */
  public function __construct(array $project) {
    $this->created = $project['created'];
    $this->changed = $project['changed'];
    /** @var \Drupal\Core\Datetime\DateFormatter $datedate_formatter */
    $date_formatter = \Drupal::service('date.formatter');
    $changed_ago = $date_formatter->formatTimeDiffSince($this->changed, [
      'granularity' => 2,
      'return_as_object' => TRUE,
    ])->toRenderable();
    $this->changed_ago = t('@changed ago', ['@changed' => $changed_ago['#markup']]);
    $this->sticky = $project['sticky'];
    $this->promote = $project['promote'];
    $this->status = $project['status'];
    $this->edit_url = $project['edit_url'];
    $this->language = $project['language'];
    $this->type = $project['type'];
    $this->is_new = $project['is_new'];
    $this->vid = $project['vid'];
    $this->nid = $project['nid'];
    $this->flag_project_star_user = $project['flag_project_star_user'];
    $this->flag_project_star_user_count = count($this->flag_project_star_user);
    $this->field_issue_summary_template = $project['field_issue_summary_template'];
    $this->field_replaced_by = $project['field_replaced_by'];
    $this->field_next_major_version_info = $project['field_next_major_version_info'];
    $this->field_project_ecosystem = $project['field_project_ecosystem'];
    $this->field_security_advisory_coverage = $project['field_security_advisory_coverage'];
    $this->field_project_issue_version_opts = $project['field_project_issue_version_opts'];
    $this->field_project_docs = $project['field_project_docs'];
    $this->field_supporting_organizations = $project['field_supporting_organizations'];
    $this->field_project_images = $project['field_project_images'];
    $this->field_project_license = $project['field_project_license'];
    $this->field_project_screenshots = $project['field_project_screenshots'];
    $this->field_project_documentation = $project['field_project_documentation'];
    $this->field_project_demo = $project['field_project_demo'];
    $this->upload = $project['upload'];
    $this->title = $project['title'];
    $this->url = $project['url'];
    $this->setBody($project['body']);
    $this->field_project_components = $project['field_project_components'];
    $this->field_project_changelog = $project['field_project_changelog'];
    $this->field_project_homepage = $project['field_project_homepage'];
    $this->field_release_version_format = $project['field_release_version_format'];
    $this->field_project_has_releases = $project['field_project_has_releases'];
    $this->field_project_issue_guidelines = $project['field_project_issue_guidelines'];
    $this->field_project_default_component = $project['field_project_default_component'];
    $this->field_project_has_issue_queue = $project['field_project_has_issue_queue'];
    $this->field_project_machine_name = $project['field_project_machine_name'];
    $this->field_project_type = $project['field_project_type'];
    $this->last_comment_timestamp = $project['last_comment_timestamp'];
    $this->has_new_content = $project['has_new_content'];
    $this->flag_tracker_follower_count = $project['flag_tracker_follower_count'];
    $this->feed_nid = $project['feed_nid'];
    $this->feeds_item_url = $project['feeds_item_url'];
    $this->feeds_item_guid = $project['feeds_item_guid'];
    $this->comment_count_new = $project['comment_count_new'];
    $this->comment_count = $project['comment_count'];
    $this->comments = $project['comments'];
    $this->comment = $project['comment'];
    $this->book_ancestors = $project['book_ancestors'];
    if (array_key_exists('author', $project)) {
      $this->author = $project['author'];
    }

    if (array_key_exists('project_usage', $project)) {
      $this->project_usage = $project['project_usage'];

      foreach ($this->project_usage as $usage) {
        $this->project_usage_total += $usage;
      }
    }

    // Module categories.
    $this->field_module_categories = $project['field_module_categories'];

    // Maintenance status.
    if (array_key_exists('field_maintenance_status', $project) && $project['field_maintenance_status']) {
      $this->field_maintenance_status = $project['field_maintenance_status'];
    }

    // Development status.
    if (array_key_exists('field_development_status', $project) && $project['field_development_status']) {
      $this->field_development_status = $project['field_development_status'];
    }
  }

  /**
   * Sets the body of the project while processing specific values.
   *
   * @param array $body
   *   The body array retrieved from raw data.
   */
  protected function setBody(array $body): void {
    $this->body = $body;
    if (!array_key_exists('value', $this->body)) {
      $this->body['value'] = '';
    }
    if (!array_key_exists('summary', $this->body)) {
      $this->body['summary'] = '';
    }

    if (!$this->body['summary']) {
      $this->body['summary'] = $this->body['value'];
    }
    $this->body['summary'] = Xss::filter(strip_tags($this->body['summary']));
    $this->body['summary'] = Unicode::truncate($this->body['summary'], 200, TRUE, TRUE);
  }

}
+0 −34
Original line number Diff line number Diff line
<?php

namespace Drupal\project_browser\DrupalOrg;

/**
 * Class DrupalOrgProjects.
 *
 * This class accepts an array of projects. For each project,
 * it will create a DrupalOrgProject object.
 *
 * @package Drupal\project_browser\DrupalOrg
 */
class DrupalOrgProjects extends \ArrayObject {

  /**
   * Constructs a new DrupalOrgProjects.
   *
   * @param array $projects
   *   An array of project arrays to be converted to
   *   \Drupal\project_browser\DrupalOrg\DrupalOrgProject.
   */
  public function __construct(array $projects) {
    parent::__construct(
      array_map(
        function ($project) {
          return new DrupalOrgProject($project);
        },
        $projects
      ),
      self::ARRAY_AS_PROPS
    );
  }

}
Loading