You are here

entity_share_cron.install in Entity Share Cron 8.2

Same filename and directory in other branches
  1. 8 entity_share_cron.install
  2. 3.0.x entity_share_cron.install

File

entity_share_cron.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Entity Share Cron module.
 */
declare (strict_types=1);
use Drupal\entity_share_cron\EntityShareCronServiceInterface;

/**
 * Implements hook_install().
 */
function entity_share_cron_install() {

  // Initializes the queue.
  $queue_name = EntityShareCronServiceInterface::PENDING_QUEUE_NAME;
  \Drupal::queue($queue_name)
    ->createQueue();
}

/**
 * Set enabled operations for channels.
 */
function entity_share_cron_update_8101() {
  $config = \Drupal::configFactory()
    ->getEditable('entity_share_cron.settings');

  // Enables both operations (create and update) for each channel.
  $remotes = $config
    ->get('remotes');
  foreach ($remotes as $remote_id => $remote_config) {
    $channels = isset($remote_config['channels']) ? $remote_config['channels'] : [];
    foreach (array_keys($channels) as $channel_id) {
      $remotes[$remote_id]['channels'][$channel_id]['operations'] = [
        'create' => TRUE,
        'update' => TRUE,
      ];
    }
  }
  $config
    ->set('remotes', $remotes)
    ->save();
}

/**
 * Switch existing configuration from config to state..
 */
function entity_share_cron_update_8201() {
  $config = \Drupal::configFactory()
    ->getEditable('entity_share_cron.settings');
  $state = \Drupal::state();
  $old_last_run = $config
    ->get('cron_last_run');
  $state
    ->set('entity_share_cron.cron_last_run', $old_last_run);
  $config
    ->clear('cron_last_run')
    ->save();
}

Functions

Namesort descending Description
entity_share_cron_install Implements hook_install().
entity_share_cron_update_8101 Set enabled operations for channels.
entity_share_cron_update_8201 Switch existing configuration from config to state..