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