Skip to content

Commit

Permalink
[4] Cleanup response from deleting /installation folder (#34173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil E. Taylor authored May 28, 2021
1 parent d1b2b6b commit f61b9ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
34 changes: 21 additions & 13 deletions installation/src/Controller/InstallationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Session\Session;
use Joomla\Utilities\ArrayHelper;

/**
Expand Down Expand Up @@ -256,24 +257,31 @@ public function delete()

/** @var \Joomla\CMS\Installation\Model\CleanupModel $model */
$model = $this->getModel('Cleanup');
$success = $model->deleteInstallationFolder();

// If an error was encountered return an error.
if (!$success)
if (!$model->deleteInstallationFolder())
{
$this->app->enqueueMessage(Text::sprintf('INSTL_COMPLETE_ERROR_FOLDER_DELETE', 'installation'), 'warning');
// We can't send a response with sendJsonResponse because our installation classes might not now exist
$error = [
'token' => Session::getFormToken(true),
'error' => true,
'data' => [
'view' => 'remove'
],
'messages' => [
'warning' => [
Text::sprintf('INSTL_COMPLETE_ERROR_FOLDER_DELETE', 'installation')
]
]
];

echo json_encode($error);

return;
}

$this->app->getSession()->destroy();

$r = new \stdClass;
$r->view = 'remove';

/**
* TODO: We can't send a response this way because our installation classes no longer
* exist. We probably need to hardcode a json response here
*
* $this->sendJsonResponse($r);
*/
// We can't send a response with sendJsonResponse because our installation classes now do not exist
echo json_encode(['error' => false]);
}
}
21 changes: 16 additions & 5 deletions installation/template/js/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,22 @@ if (document.getElementById('removeInstallationFolder')) {
perform: true,
token: true,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
onSuccess: function () {
const customInstallation = document.getElementById('customInstallation');
customInstallation.parentNode.removeChild(customInstallation);
const removeInstallationTab = document.getElementById('removeInstallationTab');
removeInstallationTab.parentNode.removeChild(removeInstallationTab);
onSuccess: function (response) {
const successresponse = JSON.parse(response);
if (successresponse.error === true) {
if (successresponse.messages) {
Joomla.renderMessages(successresponse.messages, '#system-message-container');
Joomla.loadOptions({'csrf.token': successresponse.token});
} else {
// Stuff went wrong. No error messages. Just panic bail!
Joomla.renderMessages('Unknown error deleting the installation folder.', '#system-message-container');
}
} else {
const customInstallation = document.getElementById('customInstallation');
customInstallation.parentNode.removeChild(customInstallation);
const removeInstallationTab = document.getElementById('removeInstallationTab');
removeInstallationTab.parentNode.removeChild(removeInstallationTab);
}
},
onError: function (xhr) {
Joomla.renderMessages({ error: [xhr] }, '#system-message-container');
Expand Down

0 comments on commit f61b9ae

Please sign in to comment.