@copyright Copyright (C) 2015. All Rights Reserved @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html ____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____ (_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _) .-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )( \____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__) /------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\Filesystem\File; use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Installer\Adapter\ComponentAdapter; JHTML::_('bootstrap.renderModal'); /** * Script File of Hello_world Component */ class com_hello_worldInstallerScript { /** * Constructor * * @param JAdapterInstance $parent The object responsible for running this script */ public function __construct(ComponentAdapter $parent) {} /** * Called on installation * * @param ComponentAdapter $parent The object responsible for running this script * * @return boolean True on success */ public function install(ComponentAdapter $parent) {} /** * Called on uninstallation * * @param ComponentAdapter $parent The object responsible for running this script */ public function uninstall(ComponentAdapter $parent) { // Get Application object $app = JFactory::getApplication(); // Get The Database object $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); // Select ids from fields $query->select($db->quoteName('id')); $query->from($db->quoteName('#__fields')); // Where greeting context is found $query->where( $db->quoteName('context') . ' = '. $db->quote('com_hello_world.greeting') ); $db->setQuery($query); // Execute query to see if context is found $db->execute(); $greeting_found = $db->getNumRows(); // Now check if there were any rows if ($greeting_found) { // Since there are load the needed greeting field ids $greeting_field_ids = $db->loadColumn(); // Remove greeting from the field table $greeting_condition = array( $db->quoteName('context') . ' = '. $db->quote('com_hello_world.greeting') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__fields')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove greeting items $greeting_done = $db->execute(); if ($greeting_done) { // If successfully remove greeting add queued success message. $app->enqueueMessage(JText::_('The fields with type (com_hello_world.greeting) context was removed from the #__fields table')); } // Also Remove greeting field values $greeting_condition = array( $db->quoteName('field_id') . ' IN ('. implode(',', $greeting_field_ids) .')'); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__fields_values')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove greeting field values $greeting_done = $db->execute(); if ($greeting_done) { // If successfully remove greeting add queued success message. $app->enqueueMessage(JText::_('The fields values for greeting was removed from the #__fields_values table')); } } // Create a new query object. $query = $db->getQuery(true); // Select ids from field groups $query->select($db->quoteName('id')); $query->from($db->quoteName('#__fields_groups')); // Where greeting context is found $query->where( $db->quoteName('context') . ' = '. $db->quote('com_hello_world.greeting') ); $db->setQuery($query); // Execute query to see if context is found $db->execute(); $greeting_found = $db->getNumRows(); // Now check if there were any rows if ($greeting_found) { // Remove greeting from the field groups table $greeting_condition = array( $db->quoteName('context') . ' = '. $db->quote('com_hello_world.greeting') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__fields_groups')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove greeting items $greeting_done = $db->execute(); if ($greeting_done) { // If successfully remove greeting add queued success message. $app->enqueueMessage(JText::_('The field groups with type (com_hello_world.greeting) context was removed from the #__fields_groups table')); } } // Create a new query object. $query = $db->getQuery(true); // Select id from content type table $query->select($db->quoteName('type_id')); $query->from($db->quoteName('#__content_types')); // Where greeting alias is found $query->where( $db->quoteName('type_alias') . ' = '. $db->quote('com_hello_world.greeting') ); $db->setQuery($query); // Execute query to see if alias is found $db->execute(); $greeting_found = $db->getNumRows(); // Now check if there were any rows if ($greeting_found) { // Since there are load the needed greeting type ids $greeting_ids = $db->loadColumn(); // Remove greeting from the content type table $greeting_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_hello_world.greeting') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__content_types')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove greeting items $greeting_done = $db->execute(); if ($greeting_done) { // If successfully remove greeting add queued success message. $app->enqueueMessage(JText::_('The (com_hello_world.greeting) type alias was removed from the #__content_type table')); } // Remove greeting items from the contentitem tag map table $greeting_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_hello_world.greeting') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__contentitem_tag_map')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove greeting items $greeting_done = $db->execute(); if ($greeting_done) { // If successfully remove greeting add queued success message. $app->enqueueMessage(JText::_('The (com_hello_world.greeting) type alias was removed from the #__contentitem_tag_map table')); } // Remove greeting items from the ucm content table $greeting_condition = array( $db->quoteName('core_type_alias') . ' = ' . $db->quote('com_hello_world.greeting') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__ucm_content')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove greeting items $greeting_done = $db->execute(); if ($greeting_done) { // If successfully removed greeting add queued success message. $app->enqueueMessage(JText::_('The (com_hello_world.greeting) type alias was removed from the #__ucm_content table')); } // Make sure that all the greeting items are cleared from DB foreach ($greeting_ids as $greeting_id) { // Remove greeting items from the ucm base table $greeting_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $greeting_id); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__ucm_base')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove greeting items $db->execute(); // Remove greeting items from the ucm history table $greeting_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $greeting_id); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__ucm_history')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove greeting items $db->execute(); } } // Create a new query object. $query = $db->getQuery(true); // Select id from content type table $query->select($db->quoteName('type_id')); $query->from($db->quoteName('#__content_types')); // Where Greeting alias is found $query->where( $db->quoteName('type_alias') . ' = '. $db->quote('com_hello_world.greeting') ); $db->setQuery($query); // Execute query to see if alias is found $db->execute(); $greeting_found = $db->getNumRows(); // Now check if there were any rows if ($greeting_found) { // Since there are load the needed greeting type ids $greeting_ids = $db->loadColumn(); // Remove Greeting from the content type table $greeting_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_hello_world.greeting') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__content_types')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove Greeting items $greeting_done = $db->execute(); if ($greeting_done) { // If successfully remove Greeting add queued success message. $app->enqueueMessage(JText::_('The (com_hello_world.greeting) type alias was removed from the #__content_type table')); } // Remove Greeting items from the contentitem tag map table $greeting_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_hello_world.greeting') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__contentitem_tag_map')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove Greeting items $greeting_done = $db->execute(); if ($greeting_done) { // If successfully remove Greeting add queued success message. $app->enqueueMessage(JText::_('The (com_hello_world.greeting) type alias was removed from the #__contentitem_tag_map table')); } // Remove Greeting items from the ucm content table $greeting_condition = array( $db->quoteName('core_type_alias') . ' = ' . $db->quote('com_hello_world.greeting') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__ucm_content')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove Greeting items $greeting_done = $db->execute(); if ($greeting_done) { // If successfully removed Greeting add queued success message. $app->enqueueMessage(JText::_('The (com_hello_world.greeting) type alias was removed from the #__ucm_content table')); } // Make sure that all the Greeting items are cleared from DB foreach ($greeting_ids as $greeting_id) { // Remove Greeting items from the ucm base table $greeting_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $greeting_id); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__ucm_base')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove Greeting items $db->execute(); // Remove Greeting items from the ucm history table $greeting_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $greeting_id); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__ucm_history')); $query->where($greeting_condition); $db->setQuery($query); // Execute the query to remove Greeting items $db->execute(); } } // If All related items was removed queued success message. $app->enqueueMessage(JText::_('All related items was removed from the #__ucm_base table')); $app->enqueueMessage(JText::_('All related items was removed from the #__ucm_history table')); // Remove hello_world assets from the assets table $hello_world_condition = array( $db->quoteName('name') . ' LIKE ' . $db->quote('com_hello_world%') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__assets')); $query->where($hello_world_condition); $db->setQuery($query); $greeting_done = $db->execute(); if ($greeting_done) { // If successfully removed hello_world add queued success message. $app->enqueueMessage(JText::_('All related items was removed from the #__assets table')); } // Set db if not set already. if (!isset($db)) { $db = JFactory::getDbo(); } // Set app if not set already. if (!isset($app)) { $app = JFactory::getApplication(); } // Remove Hello_world from the action_logs_extensions table $hello_world_action_logs_extensions = array( $db->quoteName('extension') . ' = ' . $db->quote('com_hello_world') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__action_logs_extensions')); $query->where($hello_world_action_logs_extensions); $db->setQuery($query); // Execute the query to remove Hello_world $hello_world_removed_done = $db->execute(); if ($hello_world_removed_done) { // If successfully remove Hello_world add queued success message. $app->enqueueMessage(JText::_('The com_hello_world extension was removed from the #__action_logs_extensions table')); } // Set db if not set already. if (!isset($db)) { $db = JFactory::getDbo(); } // Set app if not set already. if (!isset($app)) { $app = JFactory::getApplication(); } // Remove Hello_world Greeting from the action_log_config table $greeting_action_log_config = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_hello_world.greeting') ); // Create a new query object. $query = $db->getQuery(true); $query->delete($db->quoteName('#__action_log_config')); $query->where($greeting_action_log_config); $db->setQuery($query); // Execute the query to remove com_hello_world.greeting $greeting_action_log_config_done = $db->execute(); if ($greeting_action_log_config_done) { // If successfully removed Hello_world Greeting add queued success message. $app->enqueueMessage(JText::_('The com_hello_world.greeting type alias was removed from the #__action_log_config table')); } // little notice as after service, in case of bad experience with component. echo '
Please let me know at joomla@vdm.io.
We at VDM are committed to building extensions that performs proficiently! You can help us, really!
Send me your thoughts on improvements that is needed, trust me, I will be very grateful!
Visit us at https://www.vdm.io today!