Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ultimateboy’s picture

And, here is the patch.

ultimateboy’s picture

Issue description should be...

"Actions should be removed during module un-installation."

Dave Reid’s picture

Status: Needs review » Needs work

We now have an API just for this purpose! :) Please use hook_modules_uninstalled() and add it to system.module.

Dave Reid’s picture

Title: Remove actions during module uninstall » DX: Remove module actions on uninstall
ultimateboy’s picture

Status: Needs work » Needs review
FileSize
781 bytes

That is handy. Moved the delete to hook_modules_uninstalled() in system.module.

Xano’s picture

Shouldn't this be in module.inc?

Dave Reid’s picture

@Xano Nope. .inc files are API *only.* Hooks are only called from module files. Plus, the actipns code lives in system.module so it makes perfect sense to have the related hook_modules_uninstalled there as well.

Xano’s picture

Hooks are not only called from modules. How did you think hook_modules_installed() and friends were called? Exactly, in module_disable(). Personally I believe every installation/unstallatio-related work that is not part of any module (There is no Actions.module) should be put in there.

Dave Reid’s picture

API files are free to call modules_invoke_all(), which triggers hooks, but API (.inc) files do *not* contain hooks themselves. The whole reason I pushed to get hook_modules_uninstalled, etc() into D7 core was to be able to do things like this and *not* have a crap ton of crud in drupal_uninstall_modules(). Since the system module is reponsible for the actions administration, it can now react when other modules are uninstalled and remove their actions automatically.

Xano’s picture

I'm not talking about putting hook implementations in .inc files (which wouldn't even work with the current hook system). I'm talking about module_enable() and module_disable() to do this kind of cleanup directly. If there would be a separate Action module, that module should cleanup the actions, but since actions don't belong to any module I believe it is nonsense to us system_modules_disabled() for this.

cburschka’s picture

If system.module already aministrates actions, then doesn't it make sense to put the clean-up there too?

Is there a real performance cost associated with implementing the hook?

Status: Needs review » Needs work

The last submitted patch failed testing.

webchick’s picture

Status: Needs work » Needs review
agentrickard’s picture

There is a DX component to hook_modules_disabled() as well.

If we handle the removal of actions, menus, node types, and so forth in core, then your module never has to implement hook_disable(), which saves us one more thing we have to worry about when writing a module.

So putting cleanup functions in system_modules_disabled() is a good things, because it provides consistency: If you use the API properly, your actions are installed/uninstalled automatically. Good DX!

andypost’s picture

Before calling actions_delete ensure drupal_function_exists and this new hook should be called somewhere

catch’s picture

Status: Needs review » Needs work

+ foreach($modules as $module){
missing spaces.

Putting this in system_modules_uninstalled() makes sense. andypost is there any situation where actions_delete() wouldn't be available here?

andypost’s picture

@catch actions_delete() available everytime cos they live in actions.inc

Im scared about:
1) trigger assignments which possible stay in DB
2) another modules which uninstalled same time but not loaded this moment

For example trigger_actions_delete() - sits in trigger.module and cleans trigger assingments

Case:
if trigger module is disabled when another module been uninstalled so no trigger assignments will be deleted - suppose it's wrong because actions from module can have assignments before trigger.module was disabled. Maybe it's a another issue so we need wise trigger_enable.

example:
unstalation of modules somemodule and trigger
1) in loop drupal_load(somemodule), retrive its actions_info, process delete
2) drupal_load(trigger), but its trigger_actions_delete() is never called for actions from module somemodule

so I think we should load all modules and only then call actions_delete

catch’s picture

Oh I see what you mean, hook_actions_delete() for disabled modules might not be available. I think that's probably outside the scope of this patch - if modules remove their own actions manually they can't account for that either.

andypost’s picture

andypost’s picture

Status: Needs work » Needs review
FileSize
2.9 KB

Let's separate actions which lives in system.module and triggers ({trigger_assignments} table)

When a module is about to be installed |enabled|disabled system.module should reflect and sync module's actions whick already done in system_modules_submit() but nothing is happen in system_modules_uninstall_submit()

Also actions_synchronize() call action_delete() so if trigger.module enabled it will hook trigger_actions_delete()

If trigger.module enabled same things should happen with {trigger_assignments} table! So I changed trigger_install() to trigger_enable() to sync {trigger_assignments} because hook_enable() is called when trigger.module installed and enabled too.

Also this patch extends a bit test from commited #306540: Orphaned assigned actions still triggered and cannot be removed

Not all modules have hook_schema() or hook_uninstall() their actions and triggers are live in DB but now not called because #306540: Orphaned assigned actions still triggered and cannot be removed

This patch just make things little clear.

andypost’s picture

andypost’s picture

#20: 420124-sync-actions.patch queued for re-testing.

andypost’s picture

Component: other » system.module
FileSize
2.89 KB

Re roll to trace latest changes

rfay’s picture

subscribing

agentrickard’s picture

Why does trigger_enable() not use db_delete()?

andypost’s picture

@agentrickard because I don't know how to add this condition to db_delete()

agentrickard’s picture

With some help from Crell, we have:

$select = db_select('actions')
  ->fields('actions', array('aid'));
db_delete('trigger_assignments')
  ->condition('aid', $select, 'NOT IN')
  ->execute();
rfay’s picture

Status: Needs review » Needs work

I think we probably need a test that does with this, that verifies that actions get removed.

+++ modules/system/system.admin.inc	29 Mar 2010 00:29:06 -0000
@@ -1384,6 +1384,9 @@ function system_modules_uninstall_submit
+    // Synchronize to catch any actions that were removed.
+    actions_synchronize();

What about just calling actions_synchronize(TRUE) and get rid of the orphans? Or maybe we need to make a distinction between "uninstalled orphans" and "disabled orphans".

      $link = l(t('Remove orphaned actions'), 'admin/config/system/actions/orphan');

I have clicked the link for admin/config/system/actions/orphan a number of times... Does it do anything? Or does it just take you to the actions page? Maybe this is another bug that I just don't want to admit.

131 critical left. Go review some!

andypost’s picture

Status: Needs work » Needs review

@rfay this already have tests for orphants #306540: Orphaned assigned actions still triggered and cannot be removed

Patch re-rolled with proposed changes for db_delete()

EDIT: testActionsContent() class already have tests for unassign, and testActionsOrphaned()

andypost’s picture

FileSize
2.96 KB

Hm, patch was lost

andypost’s picture

#30: 420124-sync-actions.patch queued for re-testing.

andypost’s picture

maybe we need to make a distinction between "uninstalled orphans" and "disabled orphans".

This is a good idea but I cant imagine implementation... this approach require details about actions from "disabled" modules (table "system" with "status" == 0 and "schema_version" != -1 )

But we could delete module actions in system_modules_uninstall_submit() and implement hook_modules_uninstalled() for trigger module

andypost’s picture

FileSize
3.04 KB

Re-roll, suppose no need to separate "disabled" and "uninstalled" because removing orphans is manual task

@rfay see system_actions_remove_orphans()

Addition to #20
- Added comment to trigger_enanble()
- Removed system_action_delete_orphans_post() because unused

Status: Needs review » Needs work
Issue tags: -actions, -triggers, -trigger

The last submitted patch, 420124-sync-actions.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review

#33: 420124-sync-actions.patch queued for re-testing.

andypost’s picture

Issue tags: +actions, +triggers, +trigger

#33: 420124-sync-actions.patch queued for re-testing.

agentrickard’s picture

Version: 7.x-dev » 8.x-dev

Moving.

andypost’s picture

Issue tags: -actions, -triggers, -trigger

#33: 420124-sync-actions.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +actions, +triggers, +trigger

The last submitted patch, 420124-sync-actions.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
2.6 KB

Strange, patch been applied with offset, anyway reroll

>patch -p0 < 420124-sync-actions_2.patch
patching file modules/system/system.admin.inc
Hunk #1 succeeded at 1322 (offset -66 lines).
patching file modules/trigger/trigger.install
Hunk #1 succeeded at 45 with fuzz 2 (offset 2 lines).
patching file modules/trigger/trigger.test
Hunk #1 succeeded at 729 (offset 301 lines).
Hunk #2 succeeded at 737 (offset 301 lines).
tstoeckler’s picture

+++ b/modules/system/system.admin.inc
@@ -1322,6 +1322,9 @@ function system_modules_uninstall_submit($form, &$form_state) {
+    // Synchronize actions to remove all related to uninstalled modules.
+    actions_synchronize();

I was about to say, this should go in actions_modules_uninstalled() ...

(#1008166: Actions should be a module)

Code looks great, but I didn't try it out.

Powered by Dreditor.

fgm’s picture

Issue tags: -actions, -triggers, -trigger

#40: 420124-sync-actions-triggers.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +actions, +triggers, +trigger

The last submitted patch, 420124-sync-actions-triggers.patch, failed testing.

andypost’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Needs review
FileSize
2.61 KB

Since trigger module now lives in contrinb D7 still should be fixed