Skip to content
Snippets Groups Projects

Issue #3192250: Rebuild cache after cache is cleared

Files
3
@@ -7,6 +7,7 @@ use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Link;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
@@ -63,6 +64,13 @@ class ContributionCreditApi {
*/
protected $time;
/**
* The logger factory.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $loggerFactory;
/**
* Fetches and caches Drupal contribution data.
*
@@ -78,6 +86,8 @@ class ContributionCreditApi {
* The state state.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* The logger factory.
*/
public function __construct(
ContributionClientInterface $contribution_client,
@@ -85,7 +95,8 @@ class ContributionCreditApi {
TranslationInterface $string_translation,
ConfigFactoryInterface $config_factory,
StateInterface $state,
TimeInterface $time
TimeInterface $time,
LoggerChannelFactoryInterface $logger_factory
) {
$this->contributionClient = $contribution_client;
$this->cacheBackend = $cache_backend;
@@ -95,6 +106,7 @@ class ContributionCreditApi {
$this->organizationTitle = $config->get('organization_title');
$this->state = $state;
$this->time = $time;
$this->loggerFactory = $logger_factory->get('drupal_contributions');;
}
/**
@@ -106,7 +118,8 @@ class ContributionCreditApi {
$container->get('cache.contribution_cache'),
$container->get('string_translation'),
$container->get('state'),
$container->get('datetime.time')
$container->get('datetime.time'),
$container->get('logger.factory'),
);
}
@@ -117,6 +130,12 @@ class ContributionCreditApi {
* Return an array of issue credits for the contributing organization.
*/
public function getCreditsFetch() {
// Check if module is configured.
if (!$this->configurationValid()) {
// Log a warning.
$this->loggerFactory->warning('Organization ID has not been configured.');
return [];
}
$cid = 'contribution_credits_cache';
// Restore projects from cache if available.
if ($cached_data = $this->getCreditsCache()) {
@@ -242,4 +261,17 @@ class ContributionCreditApi {
return $date_pieces[1] . ' ' . $date_pieces[0] . ', ' . $date_pieces[2];
}
/**
* Check if module is configured.
*
* @return boolean
* True if organization id is set; false otherwise.
*/
protected function configurationValid() {
if (empty($this->organizationId)) {
return FALSE;
}
return TRUE;
}
}
Loading