[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 /** 2 * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> 3 * @license GNU General Public License version 2 or later; see LICENSE.txt 4 */ 5 if (!Joomla) { 6 throw new Error('Joomla API was not initialised properly'); 7 } 8 9 Joomla.Update = window.Joomla.Update || { 10 stat_total: 0, 11 stat_files: 0, 12 stat_inbytes: 0, 13 stat_outbytes: 0, 14 password: null, 15 totalsize: 0, 16 ajax_url: null, 17 return_url: null, 18 cached_instance: null, 19 genericErrorMessage: message => { 20 const headerDiv = document.getElementById('errorDialogLabel'); 21 const messageDiv = document.getElementById('errorDialogMessage'); 22 const progressDiv = document.getElementById('joomlaupdate-progress'); 23 const errorDiv = document.getElementById('joomlaupdate-error'); 24 headerDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_HEAD_GENERIC'); 25 messageDiv.innerHTML = message; 26 27 if (message.toLowerCase() === 'invalid login') { 28 messageDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_BODY_INVALIDLOGIN'); 29 } 30 31 progressDiv.classList.add('d-none'); 32 errorDiv.classList.remove('d-none'); 33 }, 34 handleErrorResponse: xhr => { 35 const isForbidden = xhr.status === 403; 36 const headerDiv = document.getElementById('errorDialogLabel'); 37 const messageDiv = document.getElementById('errorDialogMessage'); 38 const progressDiv = document.getElementById('joomlaupdate-progress'); 39 const errorDiv = document.getElementById('joomlaupdate-error'); 40 41 if (isForbidden) { 42 headerDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_HEAD_FORBIDDEN'); 43 messageDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_BODY_FORBIDDEN'); 44 } else { 45 headerDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_HEAD_SERVERERROR'); 46 messageDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_BODY_SERVERERROR'); 47 } 48 49 progressDiv.classList.add('d-none'); 50 errorDiv.classList.remove('d-none'); 51 }, 52 startExtract: () => { 53 // Reset variables 54 Joomla.Update.stat_files = 0; 55 Joomla.Update.stat_inbytes = 0; 56 Joomla.Update.stat_outbytes = 0; 57 Joomla.Update.cached_instance = null; 58 document.getElementById('extbytesin').innerText = Joomla.Update.formatBytes(Joomla.Update.stat_inbytes); 59 document.getElementById('extbytesout').innerText = Joomla.Update.formatBytes(Joomla.Update.stat_outbytes); 60 document.getElementById('extfiles').innerText = Joomla.Update.stat_files; 61 const postData = new FormData(); 62 postData.append('task', 'startExtract'); 63 postData.append('password', Joomla.Update.password); // Make the initial request to the extraction script 64 65 Joomla.request({ 66 url: Joomla.Update.ajax_url, 67 data: postData, 68 method: 'POST', 69 perform: true, 70 onSuccess: rawJson => { 71 try { 72 // If we can decode the response as JSON step through the update 73 const data = JSON.parse(rawJson); 74 Joomla.Update.stepExtract(data); 75 } catch (e) { 76 // Decoding failed; display an error 77 Joomla.Update.genericErrorMessage(e.message); 78 } 79 }, 80 onError: Joomla.Update.handleErrorResponse 81 }); 82 }, 83 stepExtract: data => { 84 // Did we get an error from the ZIP extraction engine? 85 if (data.status === false) { 86 Joomla.Update.genericErrorMessage(data.message); 87 return; 88 } 89 90 const progressDiv = document.getElementById('progress-bar'); 91 const titleDiv = document.getElementById('update-title'); // Add data to variables 92 93 Joomla.Update.stat_inbytes = data.bytesIn; 94 Joomla.Update.stat_percent = data.percent; 95 Joomla.Update.stat_percent = Joomla.Update.stat_percent || 100 * (Joomla.Update.stat_inbytes / Joomla.Update.totalsize); // Update GUI 96 97 Joomla.Update.stat_outbytes = data.bytesOut; 98 Joomla.Update.stat_files = data.files; 99 100 if (Joomla.Update.stat_percent < 100) { 101 progressDiv.classList.remove('bg-success'); 102 progressDiv.style.width = `$Joomla.Update.stat_percent}%`; 103 progressDiv.setAttribute('aria-valuenow', Joomla.Update.stat_percent); 104 } else if (Joomla.Update.stat_percent >= 100) { 105 progressDiv.classList.add('bg-success'); 106 progressDiv.style.width = '100%'; 107 progressDiv.setAttribute('aria-valuenow', 100); 108 } 109 110 progressDiv.innerText = `$Joomla.Update.stat_percent.toFixed(1)}%`; 111 document.getElementById('extbytesin').innerText = Joomla.Update.formatBytes(Joomla.Update.stat_inbytes); 112 document.getElementById('extbytesout').innerText = Joomla.Update.formatBytes(Joomla.Update.stat_outbytes); 113 document.getElementById('extfiles').innerText = Joomla.Update.stat_files; // Are we done extracting? 114 115 if (data.done) { 116 progressDiv.classList.add('bg-success'); 117 progressDiv.style.width = '100%'; 118 progressDiv.setAttribute('aria-valuenow', 100); 119 titleDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_UPDATING_COMPLETE'); 120 Joomla.Update.finalizeUpdate(); 121 return; 122 } // This is required so we can get outside the scope of the previous XHR's success handler. 123 124 125 window.setTimeout(() => { 126 Joomla.Update.delayedStepExtract(data.instance); 127 }, 50); 128 }, 129 delayedStepExtract: instance => { 130 Joomla.Update.cached_instance = instance; 131 const postData = new FormData(); 132 postData.append('task', 'stepExtract'); 133 postData.append('password', Joomla.Update.password); 134 135 if (instance) { 136 postData.append('instance', instance); 137 } 138 139 Joomla.request({ 140 url: Joomla.Update.ajax_url, 141 data: postData, 142 method: 'POST', 143 perform: true, 144 onSuccess: rawJson => { 145 try { 146 const newData = JSON.parse(rawJson); 147 Joomla.Update.stepExtract(newData); 148 } catch (e) { 149 Joomla.Update.genericErrorMessage(e.message); 150 } 151 }, 152 onError: Joomla.Update.handleErrorResponse 153 }); 154 }, 155 finalizeUpdate: () => { 156 const postData = new FormData(); 157 postData.append('task', 'finalizeUpdate'); 158 postData.append('password', Joomla.Update.password); 159 Joomla.request({ 160 url: Joomla.Update.ajax_url, 161 data: postData, 162 method: 'POST', 163 perform: true, 164 onSuccess: () => { 165 window.location = Joomla.Update.return_url; 166 }, 167 onError: Joomla.Update.handleErrorResponse 168 }); 169 }, 170 formatBytes: (bytes, decimals = 2) => { 171 if (bytes === 0) return `0 $Joomla.Text._('JLIB_SIZE_BYTES')}`; 172 const k = 1024; 173 const dm = decimals < 0 ? 0 : decimals; 174 const sizes = [Joomla.Text._('JLIB_SIZE_BYTES'), Joomla.Text._('JLIB_SIZE_KB'), Joomla.Text._('JLIB_SIZE_MB'), Joomla.Text._('JLIB_SIZE_GB'), Joomla.Text._('JLIB_SIZE_TB'), Joomla.Text._('JLIB_SIZE_PB'), Joomla.Text._('JLIB_SIZE_EB'), Joomla.Text._('JLIB_SIZE_ZB'), Joomla.Text._('JLIB_SIZE_YB')]; 175 const i = Math.floor(Math.log(bytes) / Math.log(k)); 176 return `$parseFloat((bytes / k ** i).toFixed(dm))} $sizes[i]}`; 177 }, 178 resumeButtonHandler: e => { 179 e.preventDefault(); 180 document.getElementById('joomlaupdate-progress').classList.remove('d-none'); 181 document.getElementById('joomlaupdate-error').classList.add('d-none'); 182 183 if (Joomla.Update.cached_instance === false) { 184 Joomla.Update.startExtract(); 185 } else { 186 Joomla.Update.delayedStepExtract(Joomla.Update.cached_instance); 187 } 188 }, 189 restartButtonHandler: e => { 190 e.preventDefault(); 191 document.getElementById('joomlaupdate-progress').classList.remove('d-none'); 192 document.getElementById('joomlaupdate-error').classList.add('d-none'); 193 Joomla.Update.startExtract(); 194 } 195 }; // Add click handlers for the Resume and Restart Update buttons in the error pane. 196 197 const elResume = document.getElementById('joomlaupdate-resume'); 198 const elRestart = document.getElementById('joomlaupdate-restart'); 199 200 if (elResume) { 201 elResume.addEventListener('click', Joomla.Update.resumeButtonHandler); 202 } 203 204 if (elRestart) { 205 elRestart.addEventListener('click', Joomla.Update.restartButtonHandler); 206 } // Start the update 207 208 209 const JoomlaUpdateOptions = Joomla.getOptions('joomlaupdate'); 210 211 if (JoomlaUpdateOptions && Object.keys(JoomlaUpdateOptions).length) { 212 Joomla.Update.password = JoomlaUpdateOptions.password; 213 Joomla.Update.totalsize = JoomlaUpdateOptions.totalsize; 214 Joomla.Update.ajax_url = JoomlaUpdateOptions.ajax_url; 215 Joomla.Update.return_url = JoomlaUpdateOptions.return_url; 216 Joomla.Update.startExtract(); 217 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |