Lock table in form_validate and unlock on form_submit on Drupal 6
I'm writing a form for a Drupal 6 module for people to subscribe to some activities, and would like to limit the available subscriptions.
I'm quite new to Drupal API, but was thinking in locking a table (with db_lock_table
on validation, check if we still have a s开发者_开发问答eat available, then, on form submit, insert everything on the database and unlock, to prevent race conditions.
Will this work? Is there any better way of doing this?
Instead of writing your own event management system in drupal, why not leverage existing modules, taken from http://beeznest.wordpress.com/2010/05/28/adding-events-management-to-drupal-6/
Installing events and events subscription management to Drupal 6 is as easy as installing a few modules and doing a quick setup.
- download and install the event module
- download and install the signup module
- enable the event module and all its sub-modules (don’t check datepicker if you want to go fast, as it will require additional CSS and JS to work)
- enable the signup module (required by event-signup)
- go to permissions and enable the events and signup features (nodes and signup sections) for user roles as needed (maybe you want to allow anonymous people to signup for events…)
- go to content administration -> content type -> event -> edit
- in the Signup configuration section, select any of the 2 last options (allowed or enabled) then save
- create an event and “enable” the signup option (edit the corresponding elements to suit your needs)
The event signup module has the feature of "There are settings for restricting signups to selected roles and content types, and to place limits on the number of users that can signup for any given node." - see http://drupal.org/project/signup
db_lock_table's point is to avoid race conditions. I don't see any other way of doing this.
精彩评论