TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
EnableFileService.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Install\Service;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
25  const INSTALL_TOOL_ENABLE_FILE_PATH = 'typo3conf/ENABLE_INSTALL_TOOL';
26 
30  const FIRST_INSTALL_FILE_PATH = 'FIRST_INSTALL';
31 
36 
42  protected static $sitePath = PATH_site;
43 
47  public static function isFirstInstallAllowed()
48  {
49  $files = self::getFirstInstallFilePaths();
50  if (!empty($files) && !\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->checkIfEssentialConfigurationExists()) {
51  return true;
52  }
53  return false;
54  }
55 
61  public static function createInstallToolEnableFile()
62  {
63  $installEnableFilePath = self::getInstallToolEnableFilePath();
64  if (!is_file($installEnableFilePath)) {
65  $result = touch($installEnableFilePath);
66  } else {
67  $result = true;
68  self::extendInstallToolEnableFileLifetime();
69  }
71  return $result;
72  }
73 
79  public static function removeInstallToolEnableFile()
80  {
81  return unlink(self::getInstallToolEnableFilePath());
82  }
83 
89  public static function removeFirstInstallFile()
90  {
91  $result = true;
92  $files = self::getFirstInstallFilePaths();
93  foreach ($files as $file) {
94  $result = unlink(self::$sitePath . $file) && $result;
95  }
96  return $result;
97  }
98 
104  public static function installToolEnableFileExists()
105  {
106  return @is_file(self::getInstallToolEnableFilePath());
107  }
108 
114  public static function checkInstallToolEnableFile()
115  {
116  if (!self::installToolEnableFileExists()) {
117  return false;
118  }
119  if (!self::isInstallToolEnableFilePermanent()) {
120  if (self::installToolEnableFileLifetimeExpired()) {
121  self::removeInstallToolEnableFile();
122  return false;
123  }
124  self::extendInstallToolEnableFileLifetime();
125  }
126  return true;
127  }
128 
134  public static function isInstallToolEnableFilePermanent()
135  {
136  if (self::installToolEnableFileExists()) {
137  $content = @file_get_contents(self::getInstallToolEnableFilePath());
138  if (strpos($content, 'KEEP_FILE') !== false) {
139  return true;
140  }
141  }
142  return false;
143  }
144 
150  public static function installToolEnableFileLifetimeExpired()
151  {
152  if (time() - @filemtime(self::getInstallToolEnableFilePath()) > self::INSTALL_TOOL_ENABLE_FILE_LIFETIME) {
153  return true;
154  } else {
155  return false;
156  }
157  }
158 
164  protected static function extendInstallToolEnableFileLifetime()
165  {
166  $enableFile = self::getInstallToolEnableFilePath();
167  // Extend the age of the ENABLE_INSTALL_TOOL file by one hour
168  if (is_file($enableFile)) {
169  $couldTouch = @touch($enableFile);
170  if (!$couldTouch) {
171  // If we can't remove the creation method will call us again.
172  if (self::removeInstallToolEnableFile()) {
173  self::createInstallToolEnableFile();
174  }
175  }
176  }
177  }
178 
184  protected static function getInstallToolEnableFilePath()
185  {
186  return PATH_site . self::INSTALL_TOOL_ENABLE_FILE_PATH;
187  }
188 
194  protected static function getFirstInstallFilePaths()
195  {
196  $files = array_filter(scandir(self::$sitePath), function ($file) {
197  return @is_file(self::$sitePath . $file) && preg_match('~^' . self::FIRST_INSTALL_FILE_PATH . '.*~i', $file);
198  });
199  return $files;
200  }
201 }
static fixPermissions($path, $recursive=false)