You are here

class ModifiedFiles in Automatic Updates 8

Same name in this branch
  1. 8 src/ReadinessChecker/ModifiedFiles.php \Drupal\automatic_updates\ReadinessChecker\ModifiedFiles
  2. 8 src/Services/ModifiedFiles.php \Drupal\automatic_updates\Services\ModifiedFiles

Modified code checker.

Hierarchy

Expanded class hierarchy of ModifiedFiles

1 file declares its use of ModifiedFiles
ModifiedFilesTest.php in tests/src/Kernel/ReadinessChecker/ModifiedFilesTest.php
1 string reference to 'ModifiedFiles'
automatic_updates.services.yml in ./automatic_updates.services.yml
automatic_updates.services.yml
1 service uses ModifiedFiles
automatic_updates.modified_files_checker in ./automatic_updates.services.yml
Drupal\automatic_updates\ReadinessChecker\ModifiedFiles

File

src/ReadinessChecker/ModifiedFiles.php, line 14

Namespace

Drupal\automatic_updates\ReadinessChecker
View source
class ModifiedFiles implements ReadinessCheckerInterface {
  use StringTranslationTrait;
  use ProjectInfoTrait;

  /**
   * The modified files service.
   *
   * @var \Drupal\automatic_updates\Services\ModifiedFilesInterface
   */
  protected $modifiedFiles;

  /**
   * The module extension list.
   *
   * @var \Drupal\Core\Extension\ExtensionList
   */
  protected $module;

  /**
   * The profile extension list.
   *
   * @var \Drupal\Core\Extension\ExtensionList
   */
  protected $profile;

  /**
   * The theme extension list.
   *
   * @var \Drupal\Core\Extension\ExtensionList
   */
  protected $theme;

  /**
   * An array of array of strings of extension paths.
   *
   * @var string[]string[]
   */
  protected $paths;

  /**
   * ModifiedFiles constructor.
   *
   * @param \Drupal\automatic_updates\Services\ModifiedFilesInterface $modified_files
   *   The modified files service.
   *   The config factory.
   * @param \Drupal\Core\Extension\ExtensionList $modules
   *   The module extension list.
   * @param \Drupal\Core\Extension\ExtensionList $profiles
   *   The profile extension list.
   * @param \Drupal\Core\Extension\ExtensionList $themes
   *   The theme extension list.
   */
  public function __construct(ModifiedFilesInterface $modified_files, ExtensionList $modules, ExtensionList $profiles, ExtensionList $themes) {
    $this->modifiedFiles = $modified_files;
    $this->module = $modules;
    $this->profile = $profiles;
    $this->theme = $themes;
  }

  /**
   * {@inheritdoc}
   */
  public function run() {
    return $this
      ->modifiedFilesCheck();
  }

  /**
   * Check if the site contains any modified code.
   *
   * @return array
   *   An array of translatable strings if any checks fail.
   */
  protected function modifiedFilesCheck() {
    $messages = [];
    $extensions = [];
    foreach ($this
      ->getExtensionsTypes() as $extension_type) {
      $extensions[] = $this
        ->getInfos($extension_type);
    }
    $extensions = array_merge(...$extensions);
    $filtered_modified_files = new IgnoredPathsIteratorFilter($this->modifiedFiles
      ->getModifiedFiles($extensions));
    foreach ($filtered_modified_files as $file) {
      $messages[] = $this
        ->t('The hash for @file does not match its original. Updates that include that file will fail and require manual intervention.', [
        '@file' => $file,
      ]);
    }
    return $messages;
  }

  /**
   * Get the extension types.
   *
   * @return array
   *   The extension types.
   */
  protected function getExtensionsTypes() {
    return [
      'module',
      'profile',
      'theme',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ModifiedFiles::$modifiedFiles protected property The modified files service.
ModifiedFiles::$module protected property The module extension list.
ModifiedFiles::$paths protected property An array of array of strings of extension paths.
ModifiedFiles::$profile protected property The profile extension list.
ModifiedFiles::$theme protected property The theme extension list.
ModifiedFiles::getExtensionsTypes protected function Get the extension types.
ModifiedFiles::modifiedFilesCheck protected function Check if the site contains any modified code.
ModifiedFiles::run public function Run check. Overrides ReadinessCheckerInterface::run
ModifiedFiles::__construct public function ModifiedFiles constructor.
ProjectInfoTrait::getComposerJson protected function Get the composer.json as a JSON array.
ProjectInfoTrait::getExtensionList protected function Get extension list.
ProjectInfoTrait::getExtensionVersion protected function Get the extension version.
ProjectInfoTrait::getInfos protected function Returns an array of info files information of available extensions. 1
ProjectInfoTrait::getProjectName protected function Get the extension's project name.
ProjectInfoTrait::getSuffix protected function Get string suffix.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.