/**
* Method to do any prechecks and setup the uninstall job
*
* @return void
*
* @since 4.0.0
*/
protected function setupUninstall()
{
$this->parent->extension = $this->extension;
$db = $this->parent->getDbo();
$name = $this->extension->element;
$clientId = $this->extension->client_id;
// For a template the id will be the template name which represents the subfolder of the templates folder that the template resides in.
if (!$name) {
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_ID_EMPTY'));
}
// Deny removing a parent template if there are children
$query = $db->getQuery(true)->select('COUNT(*)')->from($db->quoteName('#__template_styles'))->where([$db->quoteName('parent') . ' = :template', $db->quoteName('client_id') . ' = :client_id'])->bind(':template', $name)->bind(':client_id', $clientId);
$db->setQuery($query);
if ($db->loadResult() != 0) {
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_PARENT_TEMPLATE'));
}
// Deny remove default template
$query = $db->getQuery(true)->select('COUNT(*)')->from($db->quoteName('#__template_styles'))->where([$db->quoteName('home') . ' = ' . $db->quote('1'), $db->quoteName('template') . ' = :template', $db->quoteName('client_id') . ' = :client_id'])->bind(':template', $name)->bind(':client_id', $clientId);
$db->setQuery($query);
if ($db->loadResult() != 0) {
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DEFAULT'));
}
// Get the template root path
$client = ApplicationHelper::getClientInfo($clientId);
if (!$client) {
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_CLIENT'));
}
$this->parent->setPath('extension_root', $client->path . '/templates/' . strtolower($name));
$this->parent->setPath('source', $this->parent->getPath('extension_root'));
// We do findManifest to avoid problem when uninstalling a list of extensions: getManifest cache its manifest file
$this->parent->findManifest();
$manifest = $this->parent->getManifest();
if (!$manifest instanceof \SimpleXMLElement) {
// Kill the extension entry
$this->extension->delete($this->extension->extension_id);
// Make sure we delete the folders
Folder::delete($this->parent->getPath('extension_root'));
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_NOTFOUND_MANIFEST'));
}
// Attempt to load the language file; might have uninstall strings
$this->loadLanguage();
}