autoupdate-8.x-1.x-dev/autoupdate.module

autoupdate.module
<?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;

/**
 * Implements hook_help().
 */
function autoupdate_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.autoupdate':
      $variables = [
        ':settings' => Url::fromRoute('autoupdate.settings')->toString(),
        ':modules' => Url::fromRoute('autoupdate.modules')->toString(),
      ];

      $output = '';
      $output .= '<p><b>' . t('USE THIS ON YOUR OWN RISK! You can only use this autoupdate if you use composer for module installation! Drush 9 is also required.') . '</b></p>';
      $output .= '<h3>' . t('INTRODUCTION') . '</h3>';
      $output .= '<p>' . t('We want to make your Drupal system secure! If you have write access on your webroot and you have a composer.json and composer.lock in your webroot you can use this autoupdate!'). '<br>';
      $output .= t('You find the settings page for this module <a href=":settings">here</a>. The module report page, on which you see the updates you can find <a href=":modules">here</a>.', $variables) . '<br>';
      $output .= t('This module only provides a update checker for each installed module (source drupal.org). You also need a script which executes the drush command.') . '</p>';

      $output .= '<h3>' . t('Drush commands') . '</h3>';
      $output .= '<p>' . t('To execute a shell script, which updates your Drupal installation, you can use a Drush command.') . '</br>';
      $output .= '<ul>';
      $output .= '<li>drush autoupdate:updates --> Get all module updates.</li>';
      $output .= '<li>drush autoupdate:updates --force --> Force check for new nupdates.</li>';
      $output .= '<li>drush autoupdate:updates --security --> Get only module security updates.</li>';
      $output .= '<li>drush autoupdate:updates --update_string --> Get string with modules.</li>';
      $output .= '<li>drush autoupdate:updates --security --update_string --> Get string only for security updates.</li>';
      $output .= '</ul>';
      $output .= '</p>';

      $output .= '<h3>' . t('Example shell script') . '</h3>';
      $output .= '<p>' . t('If you want to use the whole auto update functionality, you need to create a shell script, which can execute composer. Put this script outside your webroot and create a cronjob which execute it i.e. all 30min. You will find an example in the module root, folder "examples.') . '</p>';

      $output .= '<h3>' . t('Troubleshooting') . '</h3>';
      $output .= '<p>' . t('If you have issues with autoupdate module, check this steps') . '<br>';
      $output .= t('- Please try execute drush command manual') . '<br>';
      $output .= t('- Please try execute shell script manual') . '<br>';
      $output .= t('- Check if shell script is executable (chmod +x)') . '</p>';

      return $output;
  }
}

/**
 * Implements hook_cron().
 */
function autoupdate_cron() {
  // Call service to check for updates.
  \Drupal::service('autoupdate.module_manager')->getUpdates();
}

/**
 * Implements hook_mail().
 */
function autoupdate_mail($key, &$message, $params) {
  $options = array(
    'langcode' => $message['langcode'],
  );
  switch ($key) {
    case 'new_security_updates':
      $message['subject'] = t('New security updates for @site', array('@site' => \Drupal::config('system.site')->get('name')), $options);
      $message['body'][] = $params['message'];
      break;
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc