<p>I can't think of an existing way to do this (other than something ugly like have a separate plugin whose sole job is to clean up the data from the first).</p>

<p>I think this would make the case for things like <code>onBeforePluginUninstall</code>, <code>onPluginUninstall</code>, <code>onBeforePluginInstall</code>, <code>onPluginInstall</code>, <code>onBeforePluginDeactivate</code>, etc. events to be added so that you could listen for these events and have time to do all of the cleanup necessary before uninstallation continues.</p>

<p>Probably worth adding as a <a href="http://feedback.buildwithcraft.com" rel="nofollow">feature request</a> and linking to this thread!</p>

CC BY-SA 3.0
2015-10-21T16:18:54.160Z
Solid answer. Even with this though, **tasks** would still be the wrong approach. The plugin would need to run all of its cleanup _before_ the plugin has finished uninstalling... otherwise you'd bump into the same issue.
Lindsey D
CC BY-SA 3.0
2015-10-21T16:19:57.293Z
Yeah - agreed...
Brad Bell
CC BY-SA 3.0
2015-10-21T16:16:47.160Z
2015-10-21T16:16:47.160Z
Brad Bell
<p>When I try to initiate tasks on uninstall the tasks fail because the plugin completes uninstalling before the tasks. The task is referencing an uninstalled plugin at that point. Once the plugin is uninstalled I get this error:</p>

<p>Encountered an error running task 23 (xxxx): Could not find the task component type.</p>

<p>Which makes sense. However, uninstall takes a long time because there are many things needing clean up so is there any way I can have tasks continue to work after the plugin is uninstalled?</p>

<plugin-development><plugins><tasks>
Tasks on Uninstall Plugin
# Tasks on Uninstall Plugin

(Asked by: username_0 on 2015-10-21)

When I try to initiate tasks on uninstall the tasks fail because the plugin completes uninstalling before the tasks. The task is referencing an uninstalled plugin at that point. Once the plugin is uninstalled I get this error:

Encountered an error running task 23 (xxxx): Could not find the task component type.

Which makes sense. However, uninstall takes a long time because there are many things needing clean up so is there any way I can have tasks continue to work after the plugin is uninstalled?

**Tags:** plugin-development, plugins, tasks


---

## 1 answers

### Answer by username_1 on 2015-10-21. Score: 4

I can't think of an existing way to do this (other than something ugly like have a separate plugin whose sole job is to clean up the data from the first).

I think this would make the case for things like `onBeforePluginUninstall`, `onPluginUninstall`, `onBeforePluginInstall`, `onPluginInstall`, `onBeforePluginDeactivate`, etc. events to be added so that you could listen for these events and have time to do all of the cleanup necessary before uninstallation continues.

Probably worth adding as a [feature request](http://feedback.buildwithcraft.com) and linking to this thread!

> **Comments:**
> **username_2**: Solid answer. Even with this though, **tasks** would still be the wrong approach. The plugin would need to run all of its cleanup _before_ the plugin has finished uninstalling... otherwise you'd bump into the same issue.  
> **username_1**: Yeah - agreed...  

---

