2eec61e2334baa5d448b407f78c1f1fda3790867
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Resources / Public / JavaScript / Modules / ExtensionCompatTester.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/ExtensionCompatTester
16 */
17 define([
18 'jquery',
19 'TYPO3/CMS/Install/Router',
20 'TYPO3/CMS/Install/FlashMessage',
21 'TYPO3/CMS/Install/ProgressBar',
22 'TYPO3/CMS/Install/InfoBox',
23 'TYPO3/CMS/Install/Severity',
24 'TYPO3/CMS/Install/Cache',
25 'TYPO3/CMS/Backend/Notification'
26 ], function($, Router, FlashMessage, ProgressBar, InfoBox, Severity, Cache, Notification) {
27 'use strict';
28
29 return {
30 selectorModalBody: '.t3js-modal-body',
31 selectorLoadExtLocalconfToken: '#t3js-extensionCompatTester-loadExtLocalconf-token',
32 selectorLoadExtTablesToken: '#t3js-extensionCompatTester-loadExtTables-token',
33 selectorUninstallExtensionToken: '#t3js-extensionCompatTester-uninstallExtension-token',
34 selectorCheckTrigger: '.t3js-extensionCompatTester-check',
35 selectorUninstallTrigger: '.t3js-extensionCompatTester-uninstall',
36 selectorOutputContainer: '.t3js-extensionCompatTester-output',
37
38 initialize: function(currentModal) {
39 var self = this;
40 this.currentModal = currentModal;
41 self.getLoadedExtensionList();
42
43 currentModal.on('click', this.selectorCheckTrigger, function(e) {
44 currentModal.find(self.selectorUninstallTrigger).hide();
45 currentModal.find(self.selectorOutputContainer).empty();
46 self.getLoadedExtensionList();
47 });
48 currentModal.on('click', this.selectorUninstallTrigger, function(e) {
49 self.uninstallExtension($(e.target).data('extension'));
50 });
51 },
52
53 getLoadedExtensionList: function() {
54 var self = this;
55 var modalContent = this.currentModal.find(self.selectorModalBody);
56 var $outputContainer = $(this.selectorOutputContainer);
57 var message = ProgressBar.render(Severity.loading, 'Loading...', '');
58 modalContent.append(message);
59 $outputContainer.append(message);
60 var loadResult = false;
61 $.ajax({
62 url: Router.getUrl('extensionCompatTesterLoadedExtensionList'),
63 cache: false,
64 success: function(data) {
65 modalContent.empty().append(data.html);
66 if (data.success === true && Array.isArray(data.extensions)) {
67 try {
68 data.extensions.forEach(function(extension) {
69 loadResult = self.loadExtLocalconf(extension);
70 if (loadResult === false) {
71 throw extension;
72 }
73 });
74 message = InfoBox.render(Severity.OK, 'ext_localconf.php of all loaded extensions successfully loaded', '');
75 $outputContainer.find('.alert-loading').remove();
76 $outputContainer.append(message);
77 var message = ProgressBar.render(Severity.loading, 'Loading...', '');
78 $outputContainer.append(message);
79 try {
80 data.extensions.forEach(function(extension) {
81 loadResult = self.loadExtTables(extension);
82 if (loadResult === false) {
83 throw extension;
84 }
85 });
86 message = InfoBox.render(Severity.OK, 'ext_tables.php of all loaded extensions successfully loaded', '');
87 modalContent.append(message);
88 } catch (extension) {
89 message = InfoBox.render(Severity.error, 'Loading ext_tables.php of extension "' + extension + '" failed');
90 modalContent.append(message);
91 modalContent.find(self.selectorUninstallTrigger).text('Unload extension "' + extension + '"').attr('data-extension', extension).show();
92 }
93 } catch (extension) {
94 message = InfoBox.render(Severity.error, 'Loading ext_localconf.php of extension "' + extension + '" failed');
95 // $outputContainer.find('.alert-loading').remove();
96 // $outputContainer.append(message);
97 modalContent.append(message);
98 modalContent.find(self.selectorUninstallTrigger).text('Unload extension "' + extension + '"').attr('data-extension', extension).show();
99 }
100 } else {
101 Notification.error('Something went wrong');
102 }
103 },
104 error: function(xhr) {
105 Router.handleAjaxError(xhr);
106 }
107 });
108 },
109
110 loadExtLocalconf: function(extension) {
111 var self = this;
112 var executeToken = self.currentModal.find(this.selectorLoadExtLocalconfToken).text();
113 var result = false;
114 $.ajax({
115 url: Router.getUrl(),
116 method: 'POST',
117 cache: false,
118 async: false,
119 data: {
120 'install': {
121 'action': 'extensionCompatTesterLoadExtLocalconf',
122 'token': executeToken,
123 'extension': extension
124 }
125 },
126 success: function(data) {
127 result = data.success === true;
128 },
129 error: function(data) {
130 result = false;
131 }
132 });
133 return result;
134 },
135
136 loadExtTables: function(extension) {
137 var self = this;
138 var executeToken = self.currentModal.find(this.selectorLoadExtTablesToken).text();
139 var result = false;
140 $.ajax({
141 url: Router.getUrl(),
142 method: 'POST',
143 cache: false,
144 async: false,
145 data: {
146 'install': {
147 'action': 'extensionCompatTesterLoadExtTables',
148 'token': executeToken,
149 'extension': extension
150 }
151 },
152 success: function(data) {
153 result = data.success === true;
154 },
155 error: function(data) {
156 result = false;
157 }
158 });
159 return result;
160 },
161
162 /**
163 * Send an ajax request to uninstall an extension (or multiple extensions)
164 *
165 * @param extension string of extension(s) - may be comma separated
166 */
167 uninstallExtension: function(extension) {
168 var self = this;
169 var executeToken = self.currentModal.find(self.selectorUninstallExtensionToken).text();
170 var modalContent = self.currentModal.find(self.selectorModalBody);
171 var $outputContainer = $(this.selectorOutputContainer);
172 var message = ProgressBar.render(Severity.loading, 'Loading...', '');
173 $outputContainer.append(message);
174 console.log('ExtensionCompatTester.js@174', extension, executeToken);
175 $.ajax({
176 url: Router.getUrl(),
177 cache: false,
178 method: 'POST',
179 data: {
180 'install': {
181 'action': 'extensionCompatTesterUninstallExtension',
182 'token': executeToken,
183 'extension': extension
184 }
185 },
186 success: function(data) {
187 if (data.success) {
188 if (Array.isArray(data.status)) {
189 data.status.forEach(function(element) {
190 var message = InfoBox.render(element.severity, element.title, element.message);
191 modalContent.find(self.selectorOutputContainer).empty().append(message);
192 });
193 }
194 $(self.selectorUninstallTrigger).hide();
195 //Cache.clearAll();
196 self.getLoadedExtensionList();
197 } else {
198 Notification.error('Something went wrong');
199 }
200 },
201 error: function(xhr) {
202 Router.handleAjaxError(xhr);
203 }
204 });
205 }
206 };
207 });