You are here

class OpcodeCache in Automatic Updates 8

Error if opcode caching is enabled and updates are executed via CLI.

Hierarchy

Expanded class hierarchy of OpcodeCache

1 string reference to 'OpcodeCache'
automatic_updates.services.yml in ./automatic_updates.services.yml
automatic_updates.services.yml
1 service uses OpcodeCache
automatic_updates.opcode_cache in ./automatic_updates.services.yml
Drupal\automatic_updates\ReadinessChecker\OpcodeCache

File

src/ReadinessChecker/OpcodeCache.php, line 10

Namespace

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

  /**
   * {@inheritdoc}
   */
  public function run() {
    $messages = [];
    if ($this
      ->isCli() && $this
      ->hasOpcodeFileCache()) {
      $messages[] = $this
        ->t('Automatic updates cannot run via CLI  when opcode file cache is enabled.');
    }
    return $messages;
  }

  /**
   * Determine if PHP is running via CLI.
   *
   * @return bool
   *   TRUE if CLI, FALSE otherwise.
   */
  protected function isCli() {
    return PHP_SAPI === 'cli';
  }

  /**
   * Determine if opcode cache is enabled.
   *
   * If opcache.validate_timestamps is disabled or enabled with
   * opcache.revalidate_freq greater then 2, then a site is considered to have
   * opcode caching. The default php.ini setup is
   * opcache.validate_timestamps=TRUE and opcache.revalidate_freq=2.
   *
   * @return bool
   *   TRUE if opcode file cache is enabled, FALSE otherwise.
   */
  protected function hasOpcodeFileCache() {
    if (!ini_get('opcache.validate_timestamps')) {
      return TRUE;
    }
    if (ini_get('opcache.revalidate_freq') > 2) {
      return TRUE;
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OpcodeCache::hasOpcodeFileCache protected function Determine if opcode cache is enabled.
OpcodeCache::isCli protected function Determine if PHP is running via CLI.
OpcodeCache::run public function Run check. Overrides ReadinessCheckerInterface::run
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.