[TASK] Move and Namespace classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / EnableFileService.php
1 <?php
2 namespace TYPO3\CMS\Install;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 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 * Basic Service to check and create install tool files
31 */
32 class EnableFileService {
33
34 const INSTALL_TOOL_ENABLE_FILE_PATH = 'typo3conf/ENABLE_INSTALL_TOOL';
35 const QUICKSTART_FILE_PATH = 'typo3conf/FIRST_INSTALL';
36 /**
37 * Checks, if the "FIRST_INSTALL" file exists,
38 * if so, deletes it, and adds the ENABLE_INSTALL_TOOL file
39 *
40 * @return void
41 */
42 static protected function checkFirstInstallFile() {
43 $quickstartFile = PATH_site . self::QUICKSTART_FILE_PATH;
44 // If typo3conf/FIRST_INSTALL is present and can be deleted, automatically create typo3conf/ENABLE_INSTALL_TOOL
45 if ((is_file($quickstartFile) && is_writeable($quickstartFile)) && unlink($quickstartFile)) {
46 self::createInstallToolEnableFile();
47 }
48 }
49
50 /**
51 * Creates the INSTALL_TOOL_ENABLE file
52 *
53 * @return bool
54 */
55 static public function createInstallToolEnableFile() {
56 $installEnableFilePath = self::getInstallToolEnableFilePath();
57 $result = touch($installEnableFilePath);
58 \TYPO3\CMS\Core\Utility\GeneralUtility::fixPermissions($installEnableFilePath);
59 return $result;
60 }
61
62 /**
63 * Removes the INSTALL_TOOL_ENABLE file
64 *
65 * @return bool
66 */
67 static public function removeInstallToolEnableFile() {
68 return unlink(self::getInstallToolEnableFilePath());
69 }
70
71 /**
72 * Checks if the install tool file exists
73 *
74 * @return boolean
75 */
76 static public function checkInstallToolEnableFile() {
77 self::checkFirstInstallFile();
78 $enableFile = self::getInstallToolEnableFilePath();
79 if (@file_exists($enableFile)) {
80 $content = @file_get_contents($enableFile);
81 // if the file contains the pattern "KEEP_FILE", it will not be removed
82 if (strpos($content, 'KEEP_FILE') === FALSE) {
83 // maximum age of a valid INSTALL_TOOL_ENABLE file is 1 hour
84 if (time() - @filemtime($enableFile) > 3600) {
85 self::removeInstallToolEnableFile();
86 return FALSE;
87 }
88 }
89 } else {
90 return FALSE;
91 }
92 self::extendInstallToolEnableFileLifetime();
93 return TRUE;
94 }
95
96 /**
97 * Updates the last modification of the ENABLE_INSTALL_TOOL file
98 *
99 * @return void
100 */
101 static public function extendInstallToolEnableFileLifetime() {
102 $enableFile = self::getInstallToolEnableFilePath();
103 // Extend the age of the ENABLE_INSTALL_TOOL file by one hour
104 if (is_file($enableFile)) {
105 touch($enableFile);
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
118 /**
119 * Checks if the install tool password is empty
120 *
121 * @return boolean
122 */
123 static public function isInstallToolPasswordEmpty() {
124 return empty($GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword']);
125 }
126
127 }
128
129
130 ?>