Will "the Mighty" Strohl

How to Manually Delete A DotNetNuke Module

I was recently asked how someone could manually delete a module once it is installed. The number of use cases where this would be useful is limited, but it is still a valid scenario that needs to be considered – especially during development.  Here is a walk through of the general steps required to delete a module manually.

  1. Run the Uninstall script (if necessary)
  2. Delete the module files from the DesktopModules and App_Code folder
  3. Grab the DesktopModuleId
  4. Delete the permissions associated with the module
  5. Delete the module from the database
  6. Refresh the site cache to update the UI with your changes

While I have not fully verified these steps to be the same in DNN version 5.x, they should generally be the same.  Here is some guidance to follow each of the defined steps above…

WARNING!  Performing these steps incorrectly could result in your DNN site being broken and/or no longer accessible.  In some cases, this might be permanent.  It is HIGHLY recommended that you perform a complete backup of your database and file system before performing these steps.  Doing so will give you a restore point, should something go wrong.

Run the Uninstall Script

Not all modules require a Data Access Layer (DAL), as some modules only perform utility functions and do not need to save and retrieve information from the database.  The majority of the module out there do have a DAL though, and in turn will have an uninstall script in their folder.  Look for a file named Uninstall.SqlDataProvider in the DesktopModules folder for the module you’re deleting.  Here is a reference path for you to use:

~/DesktopModules/<module name>/Uninstall.SqlDataProvider

Assuming your module is named “WNSUtility”, the above path would look like this:

~/DesktopModules/WNSUtility/Uninstall.SqlDataProvider

Using the SQL Module in the Host Menu, execute this script.  Be sure to load the script, and then check the checkbox for Run as Script before you execute it.

Please Note:  If you are using a different Data Provider, the file extension for your uninstall script will be different.

Delete the Module Files

Deleting the files from a module is easy.  Find the module directory for your module.  Using the example from above, it would be:

~/DesktopModules/WNSUtility/

Delete all files from that directory, and the directory itself.  You might run into one or more errors do to files being loaded into memory.  Should this happen, you can release the file(s) from memory by recycling the Application Pool, or restarting IIS.

Grab the DesktopModuleId

This is a very important step, as the final two steps would be incredibly difficult without the DesktopModuleId.  There is not always an exact science to finding the DesktopModuleId, but we will need it for the following steps.  In most cases, I simply perform the following query on the database:

SELECT * FROM [dbo].[DesktopModules] 
WHERE [IsAdmin] = 0 
ORDER BY [FriendlyName] 
-- or 
SELECT * FROM {databaseOwner}{objectQualifier}DesktopModules 
WHERE [IsAdmin] = 0 
ORDER BY [FriendlyName] 
 

From the above script, locating the module in question is usually easy.  Simply find the module using its Friendly Name, and then record the DesktopModuleID associated with it.

Delete the Module Permissions

This step gets executed in three parts.  As long as there aren’t a lot of instances of the module in your site, these queries should execute quickly, and error free.

Using the DesktopModuleId from the previous step, execute the GetModuleDefinitions stored procedure, taking note of each ModuleDefID.  For each module definition returned, you will next need to execute the GetPermissionsByModuleDefID stored procedure, this time taking note of each PermissionID.  Finally, execute the DeletePermission stored procedure for each PermissionID that was returned.

Delete the Module from the Database

Now, we actually delete the module.  Doing so is very easy.  Like the previous step, we just need to execute a stored procedure using the DesktopModuleID we grabbed a little while ago.  Execute the DeleteDesktopModule stored procedure to delete the module.

Refresh the Site Cache

The final thing to do is to clear the cache on the site to remove the module from all of the user interface, such as the drop down lists.  You just need to clear the cache on the site.  I have blogged about clearing the DNN site cache before.



blog comments powered by Disqus