Getting batch processing into the core for 1.6 and 1.7 hasn't been an easy task. At the first beta release of 1.6, only the Menu Manager had it in the items view. After one tracker item, the methods were carried over to the Category Manager. The place that it was most asked for, the Article Manager, just couldn't get the same treatment in a timely manner and it was decided that this feature wasn't important enough to block the release of 1.6. Fast forward a few months, and Dennis Hermatski submitted a patch to batch process articles. It was tested and implemented into the development head, which was moving away from the 1.6 series and beginning to take shape for the forthcoming 1.7 release. Upon seeing this commit, I remembered the lack of batch processing being available for the core and began testing Dennis' code on other core components. I realized that Dennis had not only coded a solution for the Article Manager, but the code was easily reusable throughout the CMS.
Into the Framework
I quickly requested an SVN branch to begin incorporating this feature into the framework to make it available for the core components and all third party developers. The first task was to move the code out of ContentControllerArticle and ContentModelArticle into the methods that they had overridden, JControllerForm and JModelAdmin (respectively). The model functions were a simple move which required only changing hard coded com_content references into an $extension variable that would act based on which component was using the code at the time. The controller method took a little bit of outside thinking because each controller sets a redirect for after the process is complete. Instead of each controller duplicating all the batch function code, I decided instead to move the common code into JControllerForm with each controller presetting the actionable model and the redirect before feeding into the parent function.
Once all the code was moved, I began reviewing the existing code for com_categories and com_menus to determine how much of this extended code could be deleted. I found several lines that were deletable, including making the controller methods follow my boilerplate code. As a further demonstration of the implementation, batch processing was added to com_weblinks as well.
Two additional patches after this feature was originally implemented cleans up the code a bit more. Both resolve small bugs and make the interface more consistent. The first patch fixed a bug where "Save as Copy" when editing Articles would fail because the title and alias weren't made unique. The second fixes a bug in the batch processing for the Category Manager wouldn't do the same uniqueness checking. This is processed through a function added to JModelAdmin called generateNewTitle, which is too reusable by developers.
So How Do I Add Batch Processing?
If your extension follows a category -> item structure, and you're dying to add batch processing to your extensions and release the new versions tomorrow, you can simply grab the methods from JControllerForm and JModelAdmin in the current trunk and push them into your own extension's code, or you can wait for 1.7 to release and add a simple boilerplate function to your single item's controller (which should be extending JControllerForm). Here's the snippet from ContentControllerArticle:
* Method to run batch operations.
* @return void
* @since 1.7
public function batch($model)
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Set the model
$model = $this->getModel('Article', '', array());
// Preset the redirect
Very easy, isn't it?
The difficult part is if your extension doesn't follow this structure, in which case you'll need to extend those functions from JControllerForm and JModelAdmin. CategoriesModelCategory has a good example of extended functions where items are stored in a nested tree.
Joomla! 1.7 is just around the corner. Are you ready for it?