You are here

filelog.install in File Log 8

Install functions for the filelog module.

File

filelog.install
View source
<?php

/**
 * @file
 * Install functions for the filelog module.
 */
use Drupal\Component\FileSecurity\FileSecurity;

/**
 * Implements hook_install().
 */
function filelog_install() {
  $config = Drupal::configFactory()
    ->getEditable('filelog.settings');
  $path = $config
    ->get('location');
  $fileSystem = Drupal::service('file_system');

  // Set up the logging directory.
  if ($fileSystem
    ->prepareDirectory($path, $fileSystem::CREATE_DIRECTORY) || !FileSecurity::writeHtaccess($path)) {
    $config
      ->set('enabled', TRUE);
  }
  else {
    Drupal::messenger()
      ->addError(t('The logs/ directory could not be created, or is not writable. File logging is disabled.'));
  }

  // Check if we can compress.
  if (!extension_loaded('zlib')) {
    $config
      ->set('rotation.gzip', FALSE);
  }
  $config
    ->save();
}

/**
 * Adds the new 'channels_type' and 'channels' keys to the module settings.
 */
function filelog_update_8101(&$sandbox) {
  $config = Drupal::configFactory()
    ->getEditable('filelog.settings');
  $config
    ->set('channels_type', $config
    ->get('channels_type') ?? 'exclude');
  $config
    ->set('channels', $config
    ->get('channels') ?? []);
  $config
    ->save();
}

Functions

Namesort descending Description
filelog_install Implements hook_install().
filelog_update_8101 Adds the new 'channels_type' and 'channels' keys to the module settings.