‪TYPO3CMS  ‪main
EnableFileService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
26 {
30  public const ‪INSTALL_TOOL_ENABLE_FILE_PATH = 'ENABLE_INSTALL_TOOL';
31 
35  public const ‪FIRST_INSTALL_FILE_PATH = 'FIRST_INSTALL';
36 
41 
42  public static function ‪isFirstInstallAllowed(): bool
43  {
45  if (!empty($files)) {
46  return true;
47  }
48  return false;
49  }
50 
54  public static function ‪createInstallToolEnableFile(): bool
55  {
56  $installEnableFilePath = ‪self::getInstallToolEnableFilePath();
57  if (!is_file($installEnableFilePath)) {
58  $result = touch($installEnableFilePath);
59  } else {
60  $result = true;
62  }
63  ‪GeneralUtility::fixPermissions($installEnableFilePath);
64  return $result;
65  }
66 
70  public static function ‪removeInstallToolEnableFile(): bool
71  {
72  $result = false;
73  while (is_file(self::getInstallToolEnableFilePath())) {
74  $result = unlink(self::getInstallToolEnableFilePath());
75  }
76  return $result;
77  }
78 
82  public static function ‪removeFirstInstallFile(): bool
83  {
84  $result = true;
86  foreach ($files as $file) {
87  $result = unlink(‪Environment::getPublicPath() . '/' . $file) && $result;
88  }
89  return $result;
90  }
91 
95  public static function ‪installToolEnableFileExists(): bool
96  {
97  return @is_file(self::getInstallToolEnableFilePath());
98  }
99 
103  public static function ‪checkInstallToolEnableFile(): bool
104  {
105  if (!self::installToolEnableFileExists()) {
106  return false;
107  }
108  if (!self::isInstallToolEnableFilePermanent()) {
109  if (self::installToolEnableFileLifetimeExpired()) {
111  return false;
112  }
114  }
115  return true;
116  }
117 
121  public static function ‪isInstallToolEnableFilePermanent(): bool
122  {
123  if (self::installToolEnableFileExists()) {
124  $content = (string)@file_get_contents(self::getInstallToolEnableFilePath());
125  if (str_contains($content, 'KEEP_FILE')) {
126  return true;
127  }
128  }
129  return false;
130  }
131 
135  public static function ‪installToolEnableFileLifetimeExpired(): bool
136  {
137  if (time() - @filemtime(self::getInstallToolEnableFilePath()) > self::INSTALL_TOOL_ENABLE_FILE_LIFETIME) {
138  return true;
139  }
140  return false;
141  }
142 
146  protected static function ‪extendInstallToolEnableFileLifetime()
147  {
149  // Extend the age of the ENABLE_INSTALL_TOOL file by one hour
150  if (is_file($enableFile)) {
151  $couldTouch = @touch($enableFile);
152  if (!$couldTouch) {
153  // If we can't remove the creation method will call us again.
154  if (self::removeInstallToolEnableFile()) {
156  }
157  }
158  }
159  }
160 
166  {
167  return ‪Environment::isComposerMode() ? 'var/transient/' : 'typo3conf/';
168  }
169 
170  public static function ‪getBestLocationForInstallToolEnableFile(): string
171  {
172  $possibleLocations = [
175  ];
176  return ‪Environment::isComposerMode() ? $possibleLocations['default'] : $possibleLocations['permanent'];
177  }
178 
182  protected static function ‪getInstallToolEnableFilePath(): string
183  {
184  $possibleLocations = [
188  ];
189  foreach ($possibleLocations as $location) {
190  if (@is_file($location)) {
191  return $location;
192  }
193  }
195  }
196 
200  protected static function ‪getFirstInstallFilePaths(): array
201  {
202  $files = scandir(‪Environment::getPublicPath() . '/');
203  $files = is_array($files) ? $files : [];
204  $files = array_filter($files, static function ($file) {
205  return @is_file(‪Environment::getPublicPath() . '/' . $file) && preg_match('~^' . self::FIRST_INSTALL_FILE_PATH . '.*~i', $file);
206  });
207  return $files;
208  }
209 }
‪TYPO3\CMS\Install\Service\EnableFileService\checkInstallToolEnableFile
‪static checkInstallToolEnableFile()
Definition: EnableFileService.php:103
‪TYPO3\CMS\Install\Service\EnableFileService\FIRST_INSTALL_FILE_PATH
‪const FIRST_INSTALL_FILE_PATH
Definition: EnableFileService.php:35
‪TYPO3\CMS\Install\Service\EnableFileService\extendInstallToolEnableFileLifetime
‪static extendInstallToolEnableFileLifetime()
Definition: EnableFileService.php:146
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\Service\EnableFileService\INSTALL_TOOL_ENABLE_FILE_PATH
‪const INSTALL_TOOL_ENABLE_FILE_PATH
Definition: EnableFileService.php:30
‪TYPO3\CMS\Install\Service\EnableFileService
Definition: EnableFileService.php:26
‪TYPO3\CMS\Install\Service\EnableFileService\getFirstInstallFilePaths
‪static getFirstInstallFilePaths()
Definition: EnableFileService.php:200
‪TYPO3\CMS\Install\Service\EnableFileService\INSTALL_TOOL_ENABLE_FILE_LIFETIME
‪const INSTALL_TOOL_ENABLE_FILE_LIFETIME
Definition: EnableFileService.php:40
‪TYPO3\CMS\Install\Service\EnableFileService\removeFirstInstallFile
‪static removeFirstInstallFile()
Definition: EnableFileService.php:82
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Core\Core\Environment\getLegacyConfigPath
‪static getLegacyConfigPath()
Definition: Environment.php:268
‪TYPO3\CMS\Install\Service\EnableFileService\createInstallToolEnableFile
‪static createInstallToolEnableFile()
Definition: EnableFileService.php:54
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static getConfigPath()
Definition: Environment.php:212
‪TYPO3\CMS\Install\Service\EnableFileService\getStaticLocationForInstallToolEnableFileDirectory
‪static getStaticLocationForInstallToolEnableFileDirectory()
Definition: EnableFileService.php:165
‪TYPO3\CMS\Install\Service\EnableFileService\installToolEnableFileExists
‪static installToolEnableFileExists()
Definition: EnableFileService.php:95
‪TYPO3\CMS\Install\Service\EnableFileService\getInstallToolEnableFilePath
‪static getInstallToolEnableFilePath()
Definition: EnableFileService.php:182
‪TYPO3\CMS\Install\Service\EnableFileService\isInstallToolEnableFilePermanent
‪static isInstallToolEnableFilePermanent()
Definition: EnableFileService.php:121
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixPermissions
‪static bool fixPermissions(string $path, bool $recursive=false)
Definition: GeneralUtility.php:1496
‪TYPO3\CMS\Install\Service\EnableFileService\removeInstallToolEnableFile
‪static removeInstallToolEnableFile()
Definition: EnableFileService.php:70
‪TYPO3\CMS\Install\Service\EnableFileService\isFirstInstallAllowed
‪static isFirstInstallAllowed()
Definition: EnableFileService.php:42
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Service\EnableFileService\getBestLocationForInstallToolEnableFile
‪static getBestLocationForInstallToolEnableFile()
Definition: EnableFileService.php:170
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Install\Service
Definition: ClearCacheService.php:16
‪TYPO3\CMS\Install\Service\EnableFileService\installToolEnableFileLifetimeExpired
‪static installToolEnableFileLifetimeExpired()
Definition: EnableFileService.php:135