‪TYPO3CMS  10.4
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  const ‪INSTALL_TOOL_ENABLE_FILE_PATH = 'typo3conf/ENABLE_INSTALL_TOOL';
31 
35  const ‪FIRST_INSTALL_FILE_PATH = 'FIRST_INSTALL';
36 
41 
45  public static function ‪isFirstInstallAllowed()
46  {
48  if (!empty($files)) {
49  return true;
50  }
51  return false;
52  }
53 
59  public static function ‪createInstallToolEnableFile()
60  {
61  $installEnableFilePath = ‪self::getInstallToolEnableFilePath();
62  if (!is_file($installEnableFilePath)) {
63  $result = touch($installEnableFilePath);
64  } else {
65  $result = true;
67  }
68  ‪GeneralUtility::fixPermissions($installEnableFilePath);
69  return $result;
70  }
71 
77  public static function ‪removeInstallToolEnableFile()
78  {
79  return unlink(self::getInstallToolEnableFilePath());
80  }
81 
87  public static function ‪removeFirstInstallFile()
88  {
89  $result = true;
91  foreach ($files as $file) {
92  $result = unlink(‪Environment::getPublicPath() . '/' . $file) && $result;
93  }
94  return $result;
95  }
96 
102  public static function ‪installToolEnableFileExists()
103  {
104  return @is_file(self::getInstallToolEnableFilePath());
105  }
106 
112  public static function ‪checkInstallToolEnableFile()
113  {
114  if (!self::installToolEnableFileExists()) {
115  return false;
116  }
117  if (!self::isInstallToolEnableFilePermanent()) {
118  if (self::installToolEnableFileLifetimeExpired()) {
120  return false;
121  }
123  }
124  return true;
125  }
126 
132  public static function ‪isInstallToolEnableFilePermanent()
133  {
134  if (self::installToolEnableFileExists()) {
135  $content = (string)@file_get_contents(self::getInstallToolEnableFilePath());
136  if (strpos($content, 'KEEP_FILE') !== false) {
137  return true;
138  }
139  }
140  return false;
141  }
142 
149  {
150  if (time() - @filemtime(self::getInstallToolEnableFilePath()) > self::INSTALL_TOOL_ENABLE_FILE_LIFETIME) {
151  return true;
152  }
153  return false;
154  }
155 
159  protected static function ‪extendInstallToolEnableFileLifetime()
160  {
162  // Extend the age of the ENABLE_INSTALL_TOOL file by one hour
163  if (is_file($enableFile)) {
164  $couldTouch = @touch($enableFile);
165  if (!$couldTouch) {
166  // If we can't remove the creation method will call us again.
167  if (self::removeInstallToolEnableFile()) {
169  }
170  }
171  }
172  }
173 
179  protected static function ‪getInstallToolEnableFilePath()
180  {
182  }
183 
189  protected static function ‪getFirstInstallFilePaths()
190  {
191  $files = scandir(‪Environment::getPublicPath() . '/');
192  $files = is_array($files) ? $files : [];
193  $files = array_filter($files, function ($file) {
194  return @is_file(‪Environment::getPublicPath() . '/' . $file) && preg_match('~^' . self::FIRST_INSTALL_FILE_PATH . '.*~i', $file);
195  });
196  return $files;
197  }
198 }
‪TYPO3\CMS\Install\Service\EnableFileService\getFirstInstallFilePaths
‪static array getFirstInstallFilePaths()
Definition: EnableFileService.php:189
‪TYPO3\CMS\Install\Service\EnableFileService\FIRST_INSTALL_FILE_PATH
‪const FIRST_INSTALL_FILE_PATH
Definition: EnableFileService.php:35
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\Install\Service\EnableFileService\installToolEnableFileLifetimeExpired
‪static bool installToolEnableFileLifetimeExpired()
Definition: EnableFileService.php:148
‪TYPO3\CMS\Install\Service\EnableFileService\extendInstallToolEnableFileLifetime
‪static extendInstallToolEnableFileLifetime()
Definition: EnableFileService.php:159
‪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\INSTALL_TOOL_ENABLE_FILE_LIFETIME
‪const INSTALL_TOOL_ENABLE_FILE_LIFETIME
Definition: EnableFileService.php:40
‪TYPO3\CMS\Install\Service\EnableFileService\getInstallToolEnableFilePath
‪static string getInstallToolEnableFilePath()
Definition: EnableFileService.php:179
‪TYPO3\CMS\Install\Service\EnableFileService\checkInstallToolEnableFile
‪static bool checkInstallToolEnableFile()
Definition: EnableFileService.php:112
‪TYPO3\CMS\Install\Service\EnableFileService\removeInstallToolEnableFile
‪static bool removeInstallToolEnableFile()
Definition: EnableFileService.php:77
‪TYPO3\CMS\Install\Service\EnableFileService\installToolEnableFileExists
‪static bool installToolEnableFileExists()
Definition: EnableFileService.php:102
‪TYPO3\CMS\Install\Service\EnableFileService\removeFirstInstallFile
‪static bool removeFirstInstallFile()
Definition: EnableFileService.php:87
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixPermissions
‪static mixed fixPermissions($path, $recursive=false)
Definition: GeneralUtility.php:1863
‪TYPO3\CMS\Install\Service\EnableFileService\isInstallToolEnableFilePermanent
‪static bool isInstallToolEnableFilePermanent()
Definition: EnableFileService.php:132
‪TYPO3\CMS\Install\Service\EnableFileService\isFirstInstallAllowed
‪static bool isFirstInstallAllowed()
Definition: EnableFileService.php:45
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Install\Service
Definition: ClearCacheService.php:16
‪TYPO3\CMS\Install\Service\EnableFileService\createInstallToolEnableFile
‪static bool createInstallToolEnableFile()
Definition: EnableFileService.php:59