Lingering artifacts of deleted Sprout Forms plugin causing queue failure for updating search indexes I noticed I had a task failure notification that I couldn't clear in my Craft 3 cp for updating search indexes. Found this in queue.log:


  2020-01-15 20:02:44
  [-][41673][-][error][craft\queue\QueueLogBehavior::afterError]  [26]
  Updating search indexes (attempt: 1) - Error (time: 0.000s): Class
  'barrelstrength\sproutforms\elements\Entry' not found


I had installed Sprout Forms and also Sprout Email recently, but then disabled &amp; removed them when they weren't quite what I was after. However, I see they've left some pieces of themselves in my database: tables sprout_addresses, sproutemail_notificationemails, sproutemail_sentemail, sproutimport_seeds, sproutreports_datasources, sproutreports_reportgroups, sproutreports_reports. (I had also installed Sprout Import on this site back when it was still running Craft 2 but it's long gone now, or I thought it was.)

Can I just drop these tables? And does that solve my queue problem? I'm tempted of course to just try and see, but don't know where there may be more bits of these plugins in my database or codebase that might cause trouble if I disappeared these tables. For example, I do see a FK relationship from the one existing row in sproutemail_notificationemails to a row in craft_elements; not sure what happens if I delete that row too. 

Would be grateful for advice on the best approach here. Thanks in advance.
UPDATE: This should no longer be an issue. All of our plugins have been reviewed and updated with more consistent uninstall behavior.



If you no longer have those plugins installed, you should be able to drop all of those tables without creating any new issues.

That may not clean up all of your data though, as the queue error is pointing to an orphaned Element. To see any orphaned elements you can run a query search for all Sprout elements on your elements table. The following may need to be adjusted if you have a different database prefix:

SELECT * 
FROM craft_elements
WHERE type LIKE '%barrelstrength%';


Deleting these Elements from your elements table should cascade and clean them up anywhere else they may be used in the database. Be careful with the following operations and be sure to test on a dev database to make sure everything works as you expect. There could be scenarios I'm not considering.

Once you find the Elements you want to delete update your query to just grab the Element IDs of the specific Elements you want. You could also query these ID values from the plugin-specific element tables if they are still in your database.

SELECT id
FROM craft_elements
WHERE type LIKE '%barrelstrength%'


To delete Elements you're going to pass those IDs to a delete statement. A standalone delete query will look something like this:

DELETE FROM craft_elements
WHERE id IN (1, 2, 3);


If you want to combine both queries since you're selecting the IDs from the same table that you are deleting from you can create a temp table to get around that. This can result in a slow query if you have a large number of elements. In that case, you could delete multiple batches of a smaller number of elements.

DELETE FROM craft_elements
WHERE id IN (
    SELECT tempElements.id
    FROM (
        SELECT id
        FROM craft_elements
        WHERE type LIKE '%barrelstrength%'
    ) tempElements
);


Again, please be careful when operating on the Craft database directly. Be sure to create backups, test on a development database, and review things closely. Craft has a highly relational data structure and plugins may behave in different ways in how they store their own data.

A less risky way of approaching this may be to write a short script and delete the Elements using the Element API:

foreach ($elementIdsToDelete as $elementId) {
  Craft::$app-&gt;elements-&gt;deleteElementById($elementId);
}