1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cSetupSystemtest extends cSetupMask {
24:
25: private $systemtest;
26:
27: function cSetupSystemtest($step, $previous, $next) {
28: global $cfg;
29:
30: cSetupMask::cSetupMask("templates/setup/forms/systemtest.tpl", $step);
31:
32: $errors = false;
33:
34: $this->setHeader(i18n("System Test", "setup"));
35: $this->_oStepTemplate->set("s", "TITLE", i18n("System Test", "setup"));
36: $this->_oStepTemplate->set("s", "DESCRIPTION", i18n("Your system has been tested for compatibility with CONTENIDO:", "setup"));
37:
38:
39: i18nInit('../data/locale/', $_SESSION['language']);
40:
41: $this->systemtest = new cSystemtest($cfg);
42: $this->systemtest->runTests(false);
43: $this->systemtest->testFilesystem($_SESSION["configmode"] == "save", false);
44: $this->systemtest->testFrontendFolderCreation();
45:
46: $cHTMLErrorMessageList = new cHTMLErrorMessageList();
47:
48: if (is_null(getMySQLDatabaseExtension())) {
49: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_ERROR, i18n("PHP MySQL Extension missing", "setup"), i18n("CONTENIDO requires the MySQL or MySQLi extension to access MySQL databases. Please configure PHP to use either MySQL or MySQLi.", "setup"));
50: } else if ($this->systemtest->testMySQL($_SESSION["dbhost"], $_SESSION["dbuser"], $_SESSION["dbpass"]) == cSystemtest::CON_MYSQL_OK) {
51: $this->initDB();
52: }
53:
54: $this->checkCountryLanguageCode();
55:
56: $cHTMLFoldableErrorMessages = array();
57:
58: if ($_SESSION["setuptype"] == 'upgrade') {
59:
60:
61: $this->doExistingOldPluginTests();
62:
63:
64: $this->doChangedDirsFilesTest();
65: }
66:
67: if((int)ini_get('max_execution_time') < 60){
68: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_WARNING, i18n("Unable to set max_execution_time", "setup"), i18n("Your PHP configuration for max_execution_time can not be changed via this script. We recommend setting the value for the installation or upgrade process to 60 seconds. You can try to execute the process with your current configuration. If the process is stopped, the system is not usable (any longer)", "setup"));
69: }
70:
71: $results = $this->systemtest->getResults();
72:
73: foreach ($results as $result) {
74: if ($result["result"]) {
75: continue;
76: }
77:
78: switch ($result["severity"]) {
79: case cSystemtest::C_SEVERITY_INFO:
80: $icon = "images/icons/info.png";
81: $iconDescription = i18n("Information", "setup");
82: break;
83: case cSystemtest::C_SEVERITY_WARNING:
84: $icon = "images/icons/warning.png";
85: $iconDescription = i18n("Warning", "setup");
86: break;
87: case cSystemtest::C_SEVERITY_ERROR:
88: $icon = "images/icons/error.png";
89: $iconDescription = i18n("Fatal error", "setup");
90: $errors = true;
91: break;
92: }
93: $cHTMLFoldableErrorMessages[] = new cHTMLFoldableErrorMessage($result["headline"], $result["message"], $icon, $iconDescription);
94: }
95:
96: if (count($cHTMLFoldableErrorMessages) == 0) {
97: $cHTMLFoldableErrorMessages[] = new cHTMLFoldableErrorMessage(i18n("No problems detected", "setup"), i18n("Setup could not detect any problems with your system environment", "setup"), "images/icons/info.png");
98: }
99:
100: $cHTMLErrorMessageList->setContent($cHTMLFoldableErrorMessages);
101:
102: $this->_oStepTemplate->set("s", "CONTROL_TESTRESULTS", $cHTMLErrorMessageList->render());
103:
104: if ($errors == true) {
105: $this->setNavigation($previous, "");
106:
107: switch ($_SESSION['setuptype']) {
108: case "upgrade":
109: $thisStep = 'upgrade' . $step;
110: break;
111: case "setup":
112: default:
113: $thisStep = 'setup' . $step;
114: break;
115: }
116:
117: $link = new cHTMLLink("#");
118: $link->attachEventDefinition("pageAttach", "onclick", "document.setupform.step.value = '" . $thisStep . "';");
119: $link->attachEventDefinition("submitAttach", "onclick", "document.setupform.submit();");
120: $link->setClass("nav navRefresh");
121: $link->setContent("<span>R</span>");
122:
123: $this->_oStepTemplate->set("s", "NEXT", $link->render());
124: } else {
125: $this->setNavigation($previous, $next);
126: }
127: }
128:
129: function doExistingOldPluginTests() {
130: $db = getSetupMySQLDBConnection(false);
131: $message = '';
132:
133:
134: $avariableTableNames = array();
135: $tableNames = $db->getTableNames();
136: if (!is_array($tableNames)) {
137: return;
138: }
139:
140: foreach ($tableNames as $table) {
141: $avariableTableNames[] = $table['table_name'];
142: }
143:
144:
145: $oldPluginTables = array(
146: 'Workflow' => array(
147: 'piwf_actions',
148: 'piwf_allocation',
149: 'piwf_art_allocation',
150: 'piwf_items',
151: 'piwf_user_sequences',
152: 'piwf_workflow'
153: ),
154: 'Content allocation' => array(
155: 'pica_alloc',
156: 'pica_alloc_con',
157: 'pica_lang'
158: ),
159: 'Linkchecker' => array(
160: 'pi_externlinks',
161: 'pi_linkwhitelist'
162: )
163: );
164:
165: foreach ($oldPluginTables as $plugin => $tables) {
166: $pluginExists = false;
167: foreach ($tables as $currentTable) {
168: if (in_array($currentTable, $avariableTableNames)) {
169: $pluginExists = true;
170: }
171: }
172:
173: if ($pluginExists) {
174: $message .= sprintf(i18n('An old Version of Plugin %s is installed on your system.', "setup") . "<br>\n", $plugin);
175: }
176: }
177:
178: if ($message) {
179: $message .= '<br>' . i18n('Please remove all old plugins before you continue. To transfer old plugin data, please copy the old plugin data tables into the new plugin data tables after the installation. The new plugintable names are the same, but contains the table prefix of CONTENIDO. Also delete the old plugin tables after data transfer.', "setup");
180:
181: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_WARNING, i18n("Old Plugins are still installed", "setup"), $message);
182: }
183: }
184:
185: function doChangedDirsFilesTest() {
186: global $cfg;
187:
188: $db = getSetupMySQLDBConnection(false);
189: $version = getContenidoVersion($db, $cfg['tab']['system_prop']);
190:
191:
192:
193: if ($version && version_compare('4.9', $version) > 0) {
194: $message = i18n("You are updating a previous version of CONTENIDO to %s. Some directories/files have been moved to other sections in %s.\n\nPlease ensure to copy contenido/includes/config.php to data/config/production/config.php and also other configuration files within contenido/includes/ to data/config/production/.", "setup");
195: $message = sprintf($message, '4.9', '4.9');
196: $message = nl2br($message);
197: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_WARNING, i18n("Attention: Some directories/files have been moved", "setup"), $message);
198: }
199: }
200:
201: function checkCountryLanguageCode() {
202: if ($_SESSION["setuptype"] != 'upgrade') {
203: return;
204: }
205:
206: $errors = array();
207:
208: cDb::setDefaultConfiguration($GLOBALS['cfg']['db']);
209:
210: $clientLanguageCollection = new cApiClientLanguageCollection();
211: $clientLanguageCollection->query();
212:
213: while ($item = $clientLanguageCollection->next()) {
214: $client = $item->getField('idclient');
215: $lang = $item->getField('idlang');
216:
217: $oLanguage = new cApiLanguage();
218: $oLanguage->loadByPrimaryKey($lang);
219:
220: $languageCode = $oLanguage->getProperty("language", "code", $client);
221: $contryCode = $oLanguage->getProperty("country", "code", $client);
222:
223: $oClient = new cApiClient();
224: $oClient->loadByPrimaryKey($client);
225: $clientName = $oClient->getField('name');
226:
227: if (strlen($languageCode) == 0 || strlen($contryCode) == 0) {
228: $langName = $oLanguage->getField('name');
229:
230: $oClient = new cApiClient();
231: $oClient->loadByPrimaryKey($client);
232:
233: array_push($errors, sprintf(i18n('Language "%s" (%s) of the client "%s" (%s) is configured without ISO language code.', "setup"), $langName, $lang, $clientName, $client));
234: }
235: }
236:
237: if (count($errors) > 0) {
238: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_ERROR, i18n("The ISO codes are necessary to convert module translations.", "setup"), implode('<br/>', $errors) );
239: }
240: }
241:
242: function initDB() {
243: switch ($_SESSION["setuptype"]) {
244: case "setup":
245:
246: $db = getSetupMySQLDBConnection(false);
247:
248:
249: $status = checkMySQLDatabaseExists($db, $_SESSION["dbname"]);
250:
251: if ($status) {
252:
253: $db = getSetupMySQLDBConnection();
254: $db->connect();
255:
256:
257: $db->query('SHOW TABLES LIKE "%s_actions"', $_SESSION["dbprefix"]);
258:
259: if ($db->nextRecord()) {
260: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_ERROR, i18n("MySQL database already exists and seems to be filled", "setup"), sprintf(i18n("Setup checked the database %s and found the table %s. It seems that you already have a CONTENIDO installation in this database. If you want to install anyways, change the database prefix. If you want to upgrade from a previous version, choose 'upgrade' as setup type.", "setup"), $_SESSION["dbname"], sprintf("%s_actions", $_SESSION["dbprefix"])));
261: return;
262: }
263:
264:
265: $db->query('SHOW TABLES LIKE "%s_test"', $_SESSION["dbprefix"]);
266: if ($db->nextRecord()) {
267: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_ERROR, i18n("MySQL test table already exists in the database", "setup"), sprintf(i18n("Setup checked the database %s and found the test table %s. Please remove it before continuing.", "setup"), $_SESSION["dbname"], sprintf("%s_test", $_SESSION["dbprefix"])));
268: return;
269: }
270:
271:
272: $status = checkMySQLTableCreation($db, $_SESSION["dbname"], sprintf("%s_test", $_SESSION["dbprefix"]));
273: if (!$status) {
274: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_ERROR, i18n("Unable to create tables in the selected MySQL database", "setup"), sprintf(i18n("Setup tried to create a test table in the database %s and failed. Please assign table creation permissions to the database user you entered, or ask an administrator to do so.", "setup"), $_SESSION["dbname"]));
275: return;
276: }
277:
278:
279: $status = checkMySQLDropTable($db, $_SESSION["dbname"], sprintf("%s_test", $_SESSION["dbprefix"]));
280: if (!$status) {
281: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_WARNING, i18n("Unable to remove the test table", "setup"), sprintf(i18n("Setup tried to remove the test table %s in the database %s and failed due to insufficient permissions. Please remove the table %s manually.", "setup"), sprintf("%s_test", $_SESSION["dbprefix"]), $_SESSION["dbname"], sprintf("%s_test", $_SESSION["dbprefix"])));
282: }
283: } else {
284: $db->connect();
285:
286: $status = checkMySQLDatabaseCreation($db, $_SESSION["dbname"]);
287: if (!$status) {
288: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_ERROR, i18n("Unable to create the database in the MySQL server", "setup"), sprintf(i18n("Setup tried to create a test database and failed. Please assign database creation permissions to the database user you entered, ask an administrator to do so, or create the database manually.", "setup")));
289: return;
290: }
291:
292:
293: $status = checkMySQLTableCreation($db, $_SESSION["dbname"], sprintf("%s_test", $_SESSION["dbprefix"]));
294: if (!$status) {
295: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_ERROR, i18n("Unable to create tables in the selected MySQL database", "setup"), sprintf(i18n("Setup tried to create a test table in the database %s and failed. Please assign table creation permissions to the database user you entered, or ask an administrator to do so.", "setup"), $_SESSION["dbname"]));
296: return;
297: }
298:
299:
300: $status = checkMySQLDropTable($db, $_SESSION["dbname"], sprintf("%s_test", $_SESSION["dbprefix"]));
301: if (!$status) {
302: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_WARNING, i18n("Unable to remove the test table", "setup"), sprintf(i18n("Setup tried to remove the test table %s in the database %s and failed due to insufficient permissions. Please remove the table %s manually.", "setup"), sprintf("%s_test", $_SESSION["dbprefix"]), $_SESSION["dbname"], sprintf("%s_test", $_SESSION["dbprefix"])));
303: }
304: }
305: break;
306: case "upgrade":
307: $db = getSetupMySQLDBConnection(false);
308:
309:
310: $status = checkMySQLDatabaseExists($db, $_SESSION["dbname"]);
311: if (!$status) {
312: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_ERROR, i18n("No data found for the upgrade", "setup"), sprintf(i18n("Setup tried to locate the data for the upgrade, however, the database %s doesn't exist. You need to copy your database first before running setup.", "setup"), $_SESSION["dbname"]));
313: return;
314: }
315:
316: $db = getSetupMySQLDBConnection();
317:
318:
319: $sql = 'SHOW TABLES LIKE "%s_actions"';
320: $db->query(sprintf($sql, $_SESSION["dbprefix"]));
321: if (!$db->nextRecord()) {
322: $this->systemtest->storeResult(false, cSystemtest::C_SEVERITY_ERROR, i18n("No data found for the upgrade", "setup"), sprintf(i18n("Setup tried to locate the data for the upgrade, however, the database %s contains no tables. You need to copy your database first before running setup.", "setup"), $_SESSION["dbname"]));
323: return;
324: }
325:
326: break;
327: }
328: }
329:
330: }