You are here

function file_replace_shell_exec_file_replace in File Replace (D8) 8

Implements hook_file_replace().

File

modules/file_replace_shell_exec/file_replace_shell_exec.module, line 13
Contains file_replace_shell_exec functionality.

Code

function file_replace_shell_exec_file_replace(FileInterface $file) {
  $command = \Drupal::config('file_replace_shell_exec.settings')
    ->get('command');
  if (!$command) {
    return;
  }
  $shell_exec = shell_exec($command);
  if ($shell_exec) {
    \Drupal::logger('file_replace_shell_exec')
      ->info('The command %command was executed with message:' . PHP_EOL . '<pre>%message</pre>', [
      '%command' => $command,
      '%message' => $shell_exec,
    ]);
  }
  else {
    \Drupal::logger('file_replace_shell_exec')
      ->error('The command %command could not be executed.', [
      '%command' => $command,
    ]);
  }
}