[BUGFIX] TceformsUpdateWizard shows up too often
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Service / EnableFileService.php
1 <?php
2 namespace TYPO3\CMS\Install\Service;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Steffen Ritter, Benjamin Mack <benjamin.mack@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Basic Service to check and create install tool files
32 */
33 class EnableFileService {
34
35 /**
36 * @constant Relative path to ENABLE_INSTALL_TOOL file
37 */
38 const INSTALL_TOOL_ENABLE_FILE_PATH = 'typo3conf/ENABLE_INSTALL_TOOL';
39
40 /**
41 * @constant Relative path to FIRST_INSTALL file
42 */
43 const FIRST_INSTALL_FILE_PATH = 'FIRST_INSTALL';
44
45 /**
46 * @constant Maximum age of ENABLE_INSTALL_TOOL file before it gets removed (in seconds)
47 */
48 const INSTALL_TOOL_ENABLE_FILE_LIFETIME = 3600;
49
50 /**
51 * @return bool
52 */
53 static public function isFirstInstallAllowed() {
54 if (!is_dir(PATH_typo3conf) && is_file(self::getFirstInstallFilePath())) {
55 return TRUE;
56 }
57 return FALSE;
58 }
59
60 /**
61 * Creates the INSTALL_TOOL_ENABLE file
62 *
63 * @return boolean
64 */
65 static public function createInstallToolEnableFile() {
66 $installEnableFilePath = self::getInstallToolEnableFilePath();
67 if (!is_file($installEnableFilePath)) {
68 $result = touch($installEnableFilePath);
69 } else {
70 $result = TRUE;
71 self::extendInstallToolEnableFileLifetime();
72 }
73 \TYPO3\CMS\Core\Utility\GeneralUtility::fixPermissions($installEnableFilePath);
74 return $result;
75 }
76
77 /**
78 * Removes the INSTALL_TOOL_ENABLE file
79 *
80 * @return boolean
81 */
82 static public function removeInstallToolEnableFile() {
83 return unlink(self::getInstallToolEnableFilePath());
84 }
85
86 /**
87 * Removes the FIRST_INSTALL file
88 *
89 * @return boolean
90 */
91 static public function removeFirstInstallFile() {
92 return unlink(self::getFirstInstallFilePath());
93 }
94
95 /**
96 * Checks if the install tool file exists
97 *
98 * @return bool
99 */
100 static public function installToolEnableFileExists() {
101 return @is_file(self::getInstallToolEnableFilePath());
102 }
103
104 /**
105 * Checks if the install tool file exists
106 *
107 * @return boolean
108 */
109 static public function checkInstallToolEnableFile() {
110 if (!self::installToolEnableFileExists()) {
111 return FALSE;
112 }
113 if (!self::isInstallToolEnableFilePermanent()) {
114 if (self::installToolEnableFileLifetimeExpired()) {
115 self::removeInstallToolEnableFile();
116 return FALSE;
117 }
118 self::extendInstallToolEnableFileLifetime();
119 }
120 return TRUE;
121 }
122
123 /**
124 * Checks if the install tool file should be kept
125 *
126 * @return bool
127 */
128 static public function isInstallToolEnableFilePermanent() {
129 if (self::installToolEnableFileExists()) {
130 $content = @file_get_contents(self::getInstallToolEnableFilePath());
131 if (strpos($content, 'KEEP_FILE') !== FALSE) {
132 return TRUE;
133 }
134 }
135 return FALSE;
136 }
137
138
139 /**
140 * Checks if the lifetime of the install tool file is expired
141 *
142 * @return bool
143 */
144 static public function installToolEnableFileLifetimeExpired() {
145 if (time() - @filemtime(self::getInstallToolEnableFilePath()) > self::INSTALL_TOOL_ENABLE_FILE_LIFETIME) {
146 return TRUE;
147 } else {
148 return FALSE;
149 }
150 }
151
152 /**
153 * Updates the last modification of the ENABLE_INSTALL_TOOL file
154 *
155 * @return void
156 */
157 static protected function extendInstallToolEnableFileLifetime() {
158 $enableFile = self::getInstallToolEnableFilePath();
159 // Extend the age of the ENABLE_INSTALL_TOOL file by one hour
160 if (is_file($enableFile)) {
161 $couldTouch = @touch($enableFile);
162 if (!$couldTouch) {
163 // If we can't remove the creation method will call us again.
164 if (self::removeInstallToolEnableFile()) {
165 self::createInstallToolEnableFile();
166 }
167 }
168 }
169 }
170
171 /**
172 * Returns the path to the INSTALL_TOOL_ENABLE file
173 *
174 * @return string
175 */
176 static protected function getInstallToolEnableFilePath() {
177 return PATH_site . self::INSTALL_TOOL_ENABLE_FILE_PATH;
178 }
179
180 /**
181 * Returns the path to the FIRST_INSTALL file
182 *
183 * @return string
184 */
185 static protected function getFirstInstallFilePath() {
186 return PATH_site . self::FIRST_INSTALL_FILE_PATH;
187 }
188 }