I wrote this quick hack to be inserted in pathauto.module.


/**
 * Implementation of hook_node_operations().
 */
function pathauto_node_operations() {
  $operations = array(
    'publish' => array(
      'label' => t('Update path alias'),
      'callback' => 'pathauto_node_operations_update',
    ),
  );
  return $operations;
}

/**
 * Callback function for updating node aliases.
 */
function pathauto_node_operations_update($nodes) {
  foreach ($nodes as $nid) {
    $node = node_load($nid);
    $placeholders = pathauto_get_placeholders('node', $node);
    pathauto_create_alias('node', 'bulkupdate', $placeholders, "node/$node->nid", $node->nid, $node->type);
  }
}

It adds an option to the Node Operations the select box in admin/content/node, which updates the path aliases of the selected nodes. I suspect this can't be so easy, or it would have been done before.

Comments

greggles’s picture

Can you provide it as a patch?
Can you get someone else who uses node_operations module to test it (I don't use it and don't entirely plan on it).

waddles’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new899 bytes

Yes, it really is that simple. :)

greggles’s picture

Status: Reviewed & tested by the community » Fixed

Great - thanks, wad!

Committed to both DRUPAL-5--2 and HEAD (for 6.x).

psynaptic’s picture

I think this removes the Publish option from the Update options. Can anyone else confirm this?

psynaptic’s picture

StatusFileSize
new469 bytes

Changing the name of the element seems to fix it.

Before:

function pathauto_node_operations() {
  $operations = array(
    'publish' => array(
      'label' => t('Update path alias'),
      'callback' => 'pathauto_node_operations_update',
    ),
  );
  return $operations;
}

After:

function pathauto_node_operations() {
  $operations = array(
    'update_alias' => array(
      'label' => t('Update path alias'),
      'callback' => 'pathauto_node_operations_update',
    ),
  );
  return $operations;
}

I can now see the Publish option in the Update options again. I have tested Updates path alias and Publish and they both work as expected.

Unified diff attached.

psynaptic’s picture

StatusFileSize
new443 bytes

Here's another patch where I ran the patch program from the Drupal root. Hope this helps.

greggles’s picture

Category: feature » bug
Priority: Normal » Critical
Status: Fixed » Needs review

yeah, see http://drupal.org/node/226914 for the bug report on this...

Seems critical bug now and since you have the patch here I'll repurpose this issue...

greggles’s picture

Status: Needs review » Fixed

Applied to both 5.x-2 and 6.x.

Thanks psynaptic!

psynaptic’s picture

Glad to be of service.

poehnix’s picture

Patch works

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

eaposztrof’s picture

i have Pathauto 5.x-2.1, this patch is applied, and now the 'Update path alias' is missing :)

greggles’s picture

@eaposztrof - the way you describe that sounds like a bug, but you used a smiley and left the status as closed so I'm not sure.

I can't repeat that bug (it works fine for me) so I'm not sure what this means.

wmclark’s picture

Status: Closed (fixed) » Active

This still seems like a bug in 2.1. Although the new functionality is added, it introduces a new bug in which you can not bulk publish nodes.

The correct patch does not to seem to have been applied to pathauto.module in the 2.1 version. I just download a fresh copy and checked the code.

After changing the code described here, I can now bulk publish nodes again.

The correct patch needs to be applied to 2.1.

greggles’s picture

Status: Active » Closed (fixed)

@wmclark - it was applied to 5.x-2.x-dev. Please test that release, it is quite stable now and will soon become 5.x-2.2. There is no way to apply a patch to an existing release and still have it be called 5.x-2.1...

wmclark’s picture

Ok, I just manually did the patch myself. Since it is on production I prefer to leave it the "stable" version.

Thanks greggles