function ProjectSecurityRequirement::getDateEndRequirement

Same name in other branches
  1. 9 core/modules/update/src/ProjectSecurityRequirement.php \Drupal\update\ProjectSecurityRequirement::getDateEndRequirement()
  2. 8.9.x core/modules/update/src/ProjectSecurityRequirement.php \Drupal\update\ProjectSecurityRequirement::getDateEndRequirement()
  3. 11.x core/modules/update/src/ProjectSecurityRequirement.php \Drupal\update\ProjectSecurityRequirement::getDateEndRequirement()

Gets the security coverage requirement based on an end date.

Return value

array Requirements array as specified by hook_requirements().

1 call to ProjectSecurityRequirement::getDateEndRequirement()
ProjectSecurityRequirement::getRequirement in core/modules/update/src/ProjectSecurityRequirement.php
Gets the security coverage requirement, if any.

File

core/modules/update/src/ProjectSecurityRequirement.php, line 202

Class

ProjectSecurityRequirement
Class for generating a project's security requirement.

Namespace

Drupal\update

Code

private function getDateEndRequirement() {
    $requirement = [];
    
    /** @var \Drupal\Component\Datetime\Time $time */
    $time = \Drupal::service('datetime.time');
    
    /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
    $date_formatter = \Drupal::service('date.formatter');
    // 'security_coverage_end_date' will either be in format 'Y-m-d' or 'Y-m'.
    if (substr_count($this->securityCoverageInfo['security_coverage_end_date'], '-') === 2) {
        $date_format = 'Y-m-d';
        $full_security_coverage_end_date = $this->securityCoverageInfo['security_coverage_end_date'];
    }
    else {
        $date_format = 'Y-m';
        // If the date does not include a day, use '15'. When calling
        // \DateTime::createFromFormat() the current day will be used if one is
        // not provided. This may cause the month to be wrong at the beginning or
        // end of the month. '15' will never be displayed because we are using the
        // 'Y-m' format.
        $full_security_coverage_end_date = $this->securityCoverageInfo['security_coverage_end_date'] . '-15';
    }
    $comparable_request_date = $date_formatter->format($time->getRequestTime(), 'custom', $date_format);
    if ($this->securityCoverageInfo['security_coverage_end_date'] <= $comparable_request_date) {
        // Security coverage is over.
        $requirement['value'] = $this->t('Coverage has ended');
        $requirement['severity'] = REQUIREMENT_ERROR;
        $requirement['description']['coverage_message'] = [
            '#markup' => $this->getVersionNoSecurityCoverageMessage(),
            '#suffix' => ' ',
        ];
    }
    else {
        $security_coverage_end_timestamp = \DateTime::createFromFormat('Y-m-d', $full_security_coverage_end_date)->getTimestamp();
        $output_date_format = $date_format === 'Y-m-d' ? 'Y-M-d' : 'Y-M';
        $formatted_end_date = $date_formatter->format($security_coverage_end_timestamp, 'custom', $output_date_format);
        $translation_arguments = [
            '@date' => $formatted_end_date,
        ];
        $requirement['value'] = $this->t('Covered until @date', $translation_arguments);
        $requirement['severity'] = REQUIREMENT_INFO;
        // 'security_coverage_ending_warn_date' will always be in the format
        // 'Y-m-d'.
        $request_date = $date_formatter->format($time->getRequestTime(), 'custom', 'Y-m-d');
        if (!empty($this->securityCoverageInfo['security_coverage_ending_warn_date']) && $this->securityCoverageInfo['security_coverage_ending_warn_date'] <= $request_date) {
            $requirement['description']['coverage_message'] = [
                '#markup' => $this->t('Update to a supported minor version soon to continue receiving security updates.'),
                '#suffix' => ' ',
            ];
            $requirement['severity'] = REQUIREMENT_WARNING;
        }
    }
    $requirement['description']['release_cycle_link'] = [
        '#markup' => $this->getReleaseCycleLink(),
    ];
    return $requirement;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.