You are here

class FileOwnership in Automatic Updates 8

File ownership checker.

Hierarchy

Expanded class hierarchy of FileOwnership

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

File

src/ReadinessChecker/FileOwnership.php, line 8

Namespace

Drupal\automatic_updates\ReadinessChecker
View source
class FileOwnership extends Filesystem {

  /**
   * {@inheritdoc}
   */
  protected function doCheck() {
    $file_path = $this
      ->getRootPath() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, [
      'core',
      'core.api.php',
    ]);
    return $this
      ->ownerIsScriptUser($file_path);
  }

  /**
   * Check if file is owned by the same user as which is running the script.
   *
   * Helps identify scenarios when the check is run by web user and the files
   * are owned by a non-web user.
   *
   * @param string $file_path
   *   The file path to check.
   *
   * @return array
   *   An array of translatable strings if there are file ownership issues.
   */
  protected function ownerIsScriptUser($file_path) {
    $messages = [];
    if (function_exists('posix_getuid')) {
      $file_owner_uid = fileowner($file_path);
      $script_uid = posix_getuid();
      if ($file_owner_uid !== $script_uid) {
        $messages[] = $this
          ->t('Files are owned by uid "@owner" but PHP is running as uid "@actual". The file owner and PHP user should be the same during an update.', [
          '@owner' => $file_owner_uid,
          '@file' => $file_path,
          '@actual' => $script_uid,
        ]);
      }
    }
    return $messages;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileOwnership::doCheck protected function Perform checks. Overrides Filesystem::doCheck 1
FileOwnership::ownerIsScriptUser protected function Check if file is owned by the same user as which is running the script.
Filesystem::$rootPath protected property The root file path.
Filesystem::$vendorPath protected property The vendor file path.
Filesystem::areSameLogicalDisk protected function Determine if the root and vendor file system are the same logical disk. 2
Filesystem::getRootPath protected function Get the root file path.
Filesystem::getVendorPath protected function Get the vendor file path.
Filesystem::run public function Run check. Overrides ReadinessCheckerInterface::run
Filesystem::__construct public function Filesystem constructor. 1
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.