24b234395f2d91046c44b038881932d53fc5b0cd
[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 * Creates the INSTALL_TOOL_ENABLE file
42 *
43 * @return boolean
44 */
45 static public function createInstallToolEnableFile() {
46 $installEnableFilePath = self::getInstallToolEnableFilePath();
47 if (!is_file($installEnableFilePath)) {
48 $result = touch($installEnableFilePath);
49 } else {
50 $result = TRUE;
51 self::extendInstallToolEnableFileLifetime();
52 }
53 \TYPO3\CMS\Core\Utility\GeneralUtility::fixPermissions($installEnableFilePath);
54 return $result;
55 }
56
57 /**
58 * Removes the INSTALL_TOOL_ENABLE file
59 *
60 * @return boolean
61 */
62 static public function removeInstallToolEnableFile() {
63 return unlink(self::getInstallToolEnableFilePath());
64 }
65
66 /**
67 * Checks if the install tool file exists
68 *
69 * @return boolean
70 */
71 static public function checkInstallToolEnableFile() {
72 $enableFile = self::getInstallToolEnableFilePath();
73 if (@file_exists($enableFile)) {
74 $content = @file_get_contents($enableFile);
75 // if the file contains the pattern "KEEP_FILE", it will not be removed
76 if (strpos($content, 'KEEP_FILE') === FALSE) {
77 // maximum age of a valid INSTALL_TOOL_ENABLE file is 1 hour
78 if (time() - @filemtime($enableFile) > 3600) {
79 self::removeInstallToolEnableFile();
80 return FALSE;
81 }
82 }
83 } else {
84 return FALSE;
85 }
86 self::extendInstallToolEnableFileLifetime();
87 return TRUE;
88 }
89
90 /**
91 * Updates the last modification of the ENABLE_INSTALL_TOOL file
92 *
93 * @return void
94 */
95 static public function extendInstallToolEnableFileLifetime() {
96 $enableFile = self::getInstallToolEnableFilePath();
97 // Extend the age of the ENABLE_INSTALL_TOOL file by one hour
98 if (is_file($enableFile)) {
99 $couldTouch = @touch($enableFile);
100 if (!$couldTouch) {
101 // If we can't remove the creation method will call us again.
102 if (self::removeInstallToolEnableFile()) {
103 self::createInstallToolEnableFile();
104 }
105 }
106 }
107 }
108
109 /**
110 * Returns the path to the INSTALL_TOOL_ENABLE file
111 *
112 * @return string
113 */
114 static protected function getInstallToolEnableFilePath() {
115 return PATH_site . self::INSTALL_TOOL_ENABLE_FILE_PATH;
116 }
117 }