060e2918b93f9cd3766e8d0c0e07d5e8cb17857a
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Resources / Public / JavaScript / Modules / UpgradeWizards.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 /**
15 * Module: TYPO3/CMS/Install/UpgradeWizards
16 */
17 define([
18 'jquery',
19 'TYPO3/CMS/Install/FlashMessage',
20 'TYPO3/CMS/Install/ProgressBar',
21 'TYPO3/CMS/Install/InfoBox',
22 'TYPO3/CMS/Install/Severity'
23 ],
24 function($, FlashMessage, ProgressBar, InfoBox, Severity) {
25 'use strict';
26
27 return {
28 selectorGridderOpener: '.t3js-upgradeWizards-open',
29 selectorMarkUndoneToken: '#t3js-upgradeWizards-markUndone-token',
30 selectorOutputWizardsContainer: '.t3js-upgradeWizards-wizards-output',
31 selectorOutputDoneContainer: '.t3js-upgradeWizards-done-output',
32 selectorWizardsBlockingAddsTemplate: '.t3js-upgradeWizards-blocking-adds-template',
33 selectorWizardsBlockingAddsRows: '.t3js-upgradeWizards-blocking-adds-rows',
34 selectorWizardsBlockingAddsExecute: '.t3js-upgradeWizards-blocking-adds-execute',
35 selectorWizardsBlockingCharsetTemplate: '.t3js-upgradeWizards-blocking-charset-template',
36 selectorWizardsBlockingCharsetFix: '.t3js-upgradeWizards-blocking-charset-fix',
37 selectorWizardsDoneBodyTemplate: '.t3js-upgradeWizards-done-body-template',
38 selectorWizardsDoneRows: '.t3js-upgradeWizards-done-rows',
39 selectorWizardsDoneRowTemplate: '.t3js-upgradeWizards-done-row-template table tbody',
40 selectorWizardsDoneRowMarkUndone: '.t3js-upgradeWizards-done-markUndone',
41 selectorWizardsDoneRowTitle: '.t3js-upgradeWizards-done-title',
42 selectorWizardsListTemplate: '.gridder-show .t3js-upgradeWizards-list-template',
43 selectorWizardsListRows: '.t3js-upgradeWizards-list-rows',
44 selectorWizardsListRowTemplate: '.gridder-show .t3js-upgradeWizards-list-row-template',
45 selectorWizardsListRowTitle: '.t3js-upgradeWizards-list-row-title',
46 selectorWizardsListRowExplanation: '.t3js-upgradeWizards-list-row-explanation',
47 selectorWizardsListRowExecute: '.t3js-upgradeWizards-list-row-execute',
48 selectorWizardsInputToken: '#t3js-upgradeWizards-input-token',
49 selectorWizardsInputTemplate: '.gridder-show .t3js-upgradeWizards-input',
50 selectorWizardsInputTitle: '.t3js-upgradeWizards-input-title',
51 selectorWizardsInputHtml: '.t3js-upgradeWizards-input-html',
52 selectorWizardsInputPerform: '.t3js-upgradeWizards-input-perform',
53 selectorWizardsExecuteToken: '#t3js-upgradeWizards-execute-token',
54
55 loadingMessage: ProgressBar.render(Severity.loading, 'Loading...', ''),
56
57 initialize: function() {
58 var self = this;
59
60 // Load main content on first open
61 $(document).on('click', this.selectorGridderOpener, function(event) {
62 var $element = $(event.target).closest(self.selectorGridderOpener);
63 if (!$element.data('upgradeWizardInitialized')) {
64 $element.data('upgradeWizardInitialized', true);
65 self.silentUpgrades();
66 self.doneUpgrades();
67 }
68 });
69
70 // Mark a done wizard undone
71 $(document).on('click', this.selectorWizardsDoneRowMarkUndone, function(event) {
72 var identifier = $(event.target).data('identifier');
73 self.markUndone(identifier);
74 });
75
76 // Execute "fix default mysql connection db charset" blocking wizard
77 $(document).on('click', this.selectorWizardsBlockingCharsetFix, function(event) {
78 self.blockingUpgradesDatabaseCharsetFix();
79 });
80
81 // Execute "add required fields + tables" blocking wizard
82 $(document).on('click', this.selectorWizardsBlockingAddsExecute, function(event) {
83 self.blockingUpgradesDatabaseAddsExecute();
84 });
85
86 // Get user input of a single upgrade wizard
87 $(document).on('click', this.selectorWizardsListRowExecute, function(event) {
88 var identifier = $(event.target).data('identifier');
89 self.wizardInput(identifier);
90 });
91
92 // Execute one upgrade wizard
93 $(document).on('click', this.selectorWizardsInputPerform, function(event) {
94 var identifier = $(event.target).data('identifier');
95 self.wizardExecute(identifier);
96 });
97 },
98
99 silentUpgrades: function() {
100 var self = this;
101 var url = location.href + '&install[controller]=ajax&install[action]=upgradeWizardsSilentUpgrades';
102 if (location.hash) {
103 url = url.replace(location.hash, "");
104 }
105 var $outputContainer = $(this.selectorOutputWizardsContainer);
106 $outputContainer.empty().html(self.loadingMessage);
107 $.ajax({
108 url: url,
109 cache: false,
110 success: function(data) {
111 $outputContainer.empty();
112 if (data.success === true && Array.isArray(data.status)) {
113 if (data.status.length > 0) {
114 data.status.forEach((function (element) {
115 var message = InfoBox.render(element.severity, element.title, element.message);
116 $outputContainer.append(message);
117 }));
118 }
119 self.blockingUpgradesDatabaseCharsetTest();
120 }
121 },
122 error: function() {
123 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
124 $outputContainer.empty().html(message);
125 }
126 });
127 },
128
129 blockingUpgradesDatabaseCharsetTest: function() {
130 var self = this;
131 var url = location.href + '&install[controller]=ajax&install[action]=upgradeWizardsBlockingDatabaseCharsetTest';
132 if (location.hash) {
133 url = url.replace(location.hash, "");
134 }
135 var $outputContainer = $(this.selectorOutputWizardsContainer);
136 var charsetTemplate = $(this.selectorWizardsBlockingCharsetTemplate).html();
137 $outputContainer.append().html(self.loadingMessage);
138 $.ajax({
139 url: url,
140 cache: false,
141 success: function(data) {
142 self.removeLoadingMessage($outputContainer);
143 if (data.success === true) {
144 if (data.needsUpdate === true) {
145 $outputContainer.append($(charsetTemplate).clone());
146 } else {
147 self.blockingUpgradesDatabaseAdds();
148 }
149 }
150 },
151 error: function() {
152 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
153 self.removeLoadingMessage($outputContainer);
154 $outputContainer.append(message);
155 }
156 });
157 },
158
159 blockingUpgradesDatabaseCharsetFix: function() {
160 var self = this;
161 var url = location.href + '&install[controller]=ajax&install[action]=upgradeWizardsBlockingDatabaseCharsetFix';
162 if (location.hash) {
163 url = url.replace(location.hash, "");
164 }
165 var $outputContainer = $(this.selectorOutputWizardsContainer);
166 $outputContainer.append().html(self.loadingMessage);
167 $.ajax({
168 url: url,
169 cache: false,
170 success: function(data) {
171 self.removeLoadingMessage($outputContainer);
172 if (data.success === true) {
173 if (Array.isArray(data.status) && data.status.length > 0) {
174 data.status.forEach(function(element) {
175 var message = InfoBox.render(element.severity, element.title, element.message);
176 $outputContainer.append(message);
177 });
178 }
179 }
180 },
181 error: function() {
182 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
183 self.removeLoadingMessage($outputContainer);
184 $outputContainer.append(message);
185 }
186 });
187 },
188
189 blockingUpgradesDatabaseAdds: function() {
190 var self = this;
191 var url = location.href + '&install[controller]=ajax&install[action]=upgradeWizardsBlockingDatabaseAdds';
192 if (location.hash) {
193 url = url.replace(location.hash, "");
194 }
195 var $outputContainer = $(this.selectorOutputWizardsContainer);
196 var breakingAddsTemplate = $(this.selectorWizardsBlockingAddsTemplate).html();
197 $outputContainer.append().html(self.loadingMessage);
198 $.ajax({
199 url: url,
200 cache: false,
201 success: function(data) {
202 self.removeLoadingMessage($outputContainer);
203 if (data.success === true) {
204 if (data.needsUpdate === true) {
205 var adds = $(breakingAddsTemplate).clone();
206 if (typeof(data.adds.tables) === 'object') {
207 data.adds.tables.forEach(function(element) {
208 adds.find(self.selectorWizardsBlockingAddsRows).append('Table: ' + element.table + '<br>');
209 });
210 }
211 if (typeof(data.adds.columns) === 'object') {
212 data.adds.columns.forEach(function(element) {
213 adds.find(self.selectorWizardsBlockingAddsRows).append('Table: ' + element.table + ', Field: ' + element.field + '<br>');
214 });
215 }
216 if (typeof(data.adds.indexes) === 'object') {
217 data.adds.indexes.forEach(function(element) {
218 adds.find(self.selectorWizardsBlockingAddsRows).append('Table: ' + element.table + ', Index: ' + element.index + '<br>');
219 });
220 }
221 $outputContainer.append(adds);
222 } else {
223 self.wizardsList();
224 }
225 }
226 },
227 error: function() {
228 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
229 self.removeLoadingMessage($outputContainer);
230 $outputContainer.append(message);
231 }
232 });
233 },
234
235 blockingUpgradesDatabaseAddsExecute: function() {
236 var self = this;
237 var url = location.href + '&install[controller]=ajax&install[action]=upgradeWizardsBlockingDatabaseExecute';
238 if (location.hash) {
239 url = url.replace(location.hash, "");
240 }
241 var $outputContainer = $(this.selectorOutputWizardsContainer);
242 $outputContainer.empty().html(self.loadingMessage);
243 $.ajax({
244 url: url,
245 cache: false,
246 success: function(data) {
247 self.removeLoadingMessage($outputContainer);
248 if (data.success === true) {
249 if (Array.isArray(data.status) && data.status.length > 0) {
250 data.status.forEach(function(element) {
251 var message = InfoBox.render(element.severity, element.title, element.message);
252 $outputContainer.append(message);
253 });
254 self.wizardsList();
255 }
256 }
257 },
258 error: function() {
259 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
260 self.removeLoadingMessage($outputContainer);
261 $outputContainer.append(message);
262 }
263 });
264 },
265
266 wizardsList: function() {
267 var self = this;
268 var url = location.href + '&install[controller]=ajax&install[action]=upgradeWizardsList';
269 if (location.hash) {
270 url = url.replace(location.hash, "");
271 }
272 var listTemplate = $(this.selectorWizardsListTemplate);
273 var wizardTemplate = $(this.selectorWizardsListRowTemplate);
274 var $outputContainer = $(this.selectorOutputWizardsContainer);
275 $outputContainer.append(self.loadingMessage);
276 $.ajax({
277 url: url,
278 cache: false,
279 success: function(data) {
280 self.removeLoadingMessage($outputContainer);
281 var list = $(listTemplate).clone();
282 list.removeClass('t3js-upgradeWizards-list-template');
283 if (data.success === true) {
284 var numberOfWizardsTodo = 0;
285 var numberOfWizards = 0;
286 if (Array.isArray(data.wizards) && data.wizards.length > 0) {
287 numberOfWizards = data.wizards.length;
288 data.wizards.forEach(function(element) {
289 if (element.shouldRenderWizard === true) {
290 var aRow = $(wizardTemplate).clone();
291 numberOfWizardsTodo = numberOfWizardsTodo +1;
292 aRow.removeClass('t3js-upgradeWizards-list-row-template');
293 aRow.find(self.selectorWizardsListRowTitle).empty().text(element.title);
294 aRow.find(self.selectorWizardsListRowExplanation).empty().html(element.explanation);
295 aRow.find(self.selectorWizardsListRowExecute).data('identifier', element.identifier);
296 list.find(self.selectorWizardsListRows).append(aRow);
297 }
298 });
299 }
300 var percent = 100;
301 if (numberOfWizardsTodo > 0) {
302 percent = ((numberOfWizards - numberOfWizardsTodo) / data.wizards.length) * 100;
303 }
304 list.find('.progress-bar')
305 .css('width', percent + '%')
306 .attr('aria-valuenow', percent)
307 .find('span')
308 .text(parseInt(percent) + '%');
309 $outputContainer.append(list);
310 }
311 },
312 error: function() {
313 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
314 self.removeLoadingMessage($outputContainer);
315 $outputContainer.append(message);
316 }
317 });
318 },
319
320 wizardInput: function(identifier) {
321 var self = this;
322 var url = location.href + '&install[controller]=ajax';
323 var postData = {
324 'install': {
325 'action': 'upgradeWizardsInput',
326 'token': $(this.selectorWizardsInputToken).text(),
327 'identifier': identifier
328 }
329 };
330 var $outputContainer = $(this.selectorOutputWizardsContainer);
331 var inputTemplate = $(this.selectorWizardsInputTemplate);
332 $outputContainer.empty().html(this.loadingMessage);
333 $.ajax({
334 method: 'POST',
335 data: postData,
336 url: url,
337 cache: false,
338 success: function(data) {
339 $outputContainer.empty();
340 var input = $(inputTemplate).clone();
341 input.removeClass('t3js-upgradeWizards-input');
342 if (data.success === true) {
343 if (Array.isArray(data.status)) {
344 data.status.forEach(function(element) {
345 var message = FlashMessage.render(element.severity, element.title, element.message);
346 $outputContainer.append(message);
347 });
348 }
349 if (data.userInput.wizardHtml.length > 0) {
350 input.find(self.selectorWizardsInputHtml).html(data.userInput.wizardHtml);
351 }
352 input.find(self.selectorWizardsInputTitle).text(data.userInput.title);
353 input.find(self.selectorWizardsInputPerform).data('identifier', data.userInput.identifier);
354 }
355 $outputContainer.append(input);
356 },
357 error: function() {
358 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
359 $outputContainer.empty().html(message);
360 }
361 });
362 },
363
364 wizardExecute: function(identifier) {
365 var self = this;
366 var url = location.href + '&install[controller]=ajax';
367 var postData = {
368 'install[action]': 'upgradeWizardsExecute',
369 'install[token]': $(this.selectorWizardsExecuteToken).text(),
370 'install[identifier]': identifier
371 };
372 $($('.gridder-show ' + this.selectorOutputWizardsContainer + ' form').serializeArray()).each(function() {
373 postData[this.name] = this.value;
374 });
375 var $outputContainer = $(this.selectorOutputWizardsContainer);
376 var $outputDoneContainer = $(this.selectorOutputDoneContainer);
377 $outputContainer.empty().html(this.loadingMessage);
378 $.ajax({
379 method: 'POST',
380 data: postData,
381 url: url,
382 cache: false,
383 success: function(data) {
384 $outputContainer.empty();
385 if (data.success === true) {
386 if (Array.isArray(data.status)) {
387 data.status.forEach(function(element) {
388 var message = InfoBox.render(element.severity, element.title, element.message);
389 $outputContainer.append(message);
390 });
391 }
392 self.wizardsList();
393 $outputDoneContainer.empty();
394 self.doneUpgrades();
395 }
396 },
397 error: function() {
398 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
399 $outputContainer.empty().html(message);
400 }
401 });
402 },
403
404 doneUpgrades: function() {
405 var self = this;
406 var url = location.href + '&install[controller]=ajax&install[action]=upgradeWizardsDoneUpgrades';
407 if (location.hash) {
408 url = url.replace(location.hash, "");
409 }
410 var $outputContainer = $(this.selectorOutputDoneContainer);
411 var rowTemplate = $(this.selectorWizardsDoneRowTemplate).html();
412 var bodyTemplate = $(this.selectorWizardsDoneBodyTemplate).html();
413 $outputContainer.append(this.loadingMessage);
414 $.ajax({
415 url: url,
416 cache: false,
417 success: function(data) {
418 self.removeLoadingMessage($outputContainer);
419 if (data.success === true) {
420 if (Array.isArray(data.status) && data.status.length > 0) {
421 data.status.forEach(function(element) {
422 var message = InfoBox.render(element.severity, element.title, element.message);
423 $outputContainer.append(message);
424 });
425 }
426 var body = $(bodyTemplate).clone();
427 var hasBodyContent = false;
428 var $wizardsDoneContainer = body.find(self.selectorWizardsDoneRows);
429 if (Array.isArray(data.wizardsDone) && data.wizardsDone.length > 0) {
430 data.wizardsDone.forEach(function(element) {
431 hasBodyContent = true;
432 var aRow = $(rowTemplate).clone();
433 aRow.find(self.selectorWizardsDoneRowMarkUndone).data('identifier', element.identifier);
434 aRow.find(self.selectorWizardsDoneRowTitle).text(element.title);
435 $wizardsDoneContainer.append(aRow);
436 });
437 }
438 if (Array.isArray(data.rowUpdatersDone) && data.rowUpdatersDone.length > 0) {
439 data.rowUpdatersDone.forEach(function(element) {
440 hasBodyContent = true;
441 var aRow = $(rowTemplate).clone();
442 aRow.find(self.selectorWizardsDoneRowMarkUndone).data('identifier', element.identifier);
443 aRow.find(self.selectorWizardsDoneRowTitle).html(element.title);
444 $wizardsDoneContainer.append(aRow);
445 });
446 }
447 if (hasBodyContent === true) {
448 $outputContainer.append(body);
449 }
450 }
451 },
452 error: function() {
453 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
454 self.removeLoadingMessage($outputContainer);
455 $outputContainer.append(message);
456 }
457 });
458 },
459
460 markUndone: function(identifier) {
461 var self = this;
462 var url = location.href + '&install[controller]=ajax';
463 var postData = {
464 'install': {
465 'action': 'upgradeWizardsMarkUndone',
466 'token': $(this.selectorMarkUndoneToken).text(),
467 'identifier': identifier
468 }
469 };
470 var $outputContainer = $(this.selectorOutputDoneContainer);
471 $outputContainer.empty().html(this.loadingMessage);
472 $.ajax({
473 method: 'POST',
474 data: postData,
475 url: url,
476 cache: false,
477 success: function(data) {
478 $outputContainer.empty();
479 if (data.success === true && Array.isArray(data.status)) {
480 data.status.forEach(function(element) {
481 var message = InfoBox.render(element.severity, element.title, element.message);
482 $outputContainer.append(message);
483 self.doneUpgrades();
484 self.blockingUpgradesDatabaseCharsetTest();
485 });
486 }
487 },
488 error: function() {
489 var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
490 $outputContainer.empty().html(message);
491 }
492 });
493 },
494
495 removeLoadingMessage: function($container) {
496 $container.find('.alert-loading').remove();
497 }
498 };
499 });