Help needed: changing ReassignOwnership plugin to include batch edit

Hello everyone.

I’m changing (forking?) the ReassignOwnership plugin (https://github.com/patrickmj/ReassignOwnership, by @patrickmj), to make the function available also during Items batch editing.

So far, I’ve managed to include the list of owners in the batch-edit form, but as the plugin is originally built to work on a single Item at a time, I would need to cycle through the Items selected in the form. Point is: I cannot find where the other changes from that form are processed, I can see it should happen in batch-edit-save but cannot find such a file or function… anybody could help me on this?

Thanks.

I have a similar plugin here that I would accept pull requests for:

The action for batch-edit-save is defined here:

It looks like the actual work is done in this job, though:

In particular, it appears the items_batch_edit_custom hook would be the best way to add additional code to the batch edit process in a plugin.

Thanks, @kloor.

I’ll surely take a look at your plugin and, if needed, submit a pull request.

After following your hint, @kloor, I’ve used the admin_items_batch_edit_form hook to add to the items/batch-edit page a combobox listing all site users:

public function hookAdminItemsBatchEditForm($args)
{
    $view = $args['view'];
    echo "<div class='field'>";
    echo "<label class='two columns alpha' for='custom[owner_id]'>" . __('Owner') .  "</label>";
    echo "<div class='inputs five columns omega'>";
    $ownershipOptions = get_table_options('User', null, array('sort_field' => 'name'));
    $ownershipOptions = array('' => __('Select Below')) + $ownershipOptions;
    echo $view->formSelect('custom[owner_id]', null, array(), $ownershipOptions);
    echo "</div>";
    echo "</div>";
}

But, when I try to use items_batch_edit_custom hook to save the new values, it fails, with no change applied. Here’s the code:

public function hookItemsBatchEditCustom($args)
{
    if (isset($args['custom']['owner_id']) && $args['custom']['owner_id'] != '') {
		$item = $args['item'];
		$newOwnerId = $args['custom']['owner_id'];
		$newOwner = $this->_db->getTable('User')->find($newOwnerId);
		$item->setOwner($newOwner);
	}
}   

Any idea what’s wrong?

The only thing I notice at a glance is that you are only checking if owner_id exists in $args['custom'] but not that it necessarily has a value, or that that value can be found in the user table before attempting to set it as the owner. Perhaps the select box isn’t working correctly, and only sending an empty value?

Are you logging errors, and have you checked the error log?

Hi.
Thanks for the suggestion.

I have checked every single step of the algorithm, and the ItemsBatchEditCustom hook is receiving the correct values and applying the correct one.
Also the function perform in ItemBatchEdit is applying the change (if I check just before release_object($item), the item’s owner is the new one.
But, for some reason, when I get back to ItemsController, if I check after $dispatcher->send('Job_ItemBatchEdit', $options), no change is visible and the old owner is still there. I wonder whether that’s where the issue resides…

In the custom batch edit hook, you need to ->save() the item when you make changes.

That did the trick. Thanks a lot, @jflatnes!
I’ve now posted the whole new code as pull requests to @patrickmj’s original plugin (GitHub - patrickmj/ReassignOwnership: Omeka plugin to reassign ownership of records.).

John, as I could find no indication of that special need in the Omeka literature, may I suggest it could be added to items_batch_edit_custom — Omeka Classic 3.1 documentation?

I went ahead and added a note about saving to that documentation page (but it may take a bit to actually show up).

Thanks again for your help.

This topic was automatically closed after 250 days. New replies are no longer allowed.