|
Planet MySQL
|
Planet MySQL - http://www.planetmysql.org/
|
-
Adding dynamic fields to Signups on Drupal
In my day job at SkySQL I work with Drupal as our content management system. One thing we often need to do is provide a way for people to sign up for events and the like. One such event is the upcoming SkySQL and MariaDB: Solutions Day for the MySQL® Database and unlike other events we needed to take into account the dietary requirements of those wishing to attend.
For events registration we use the Signup module and use a theme template function to provide a set of standard fields. The code looks something like this:
function ourtheme_signup_user_form($node) { $form = array(); // If this function is providing any extra fields at all, the following // line is required for form form to work -- DO NOT EDIT OR REMOVE. $form['signup_form_data']['#tree'] = TRUE; $form['signup_form_data']['FirstName'] = array( '#type' => 'textfield', '#title' => t('First Name'), '#size' => 40, '#maxlength' => 64, '#required' => TRUE, ); $form['signup_form_data']['LastName'] = array( '#type' => 'textfield', '#title' => t('Last Name'), '#size' => 40, '#maxlength' => 64, '#required' => TRUE, );
And so on, building up the elements and then returning the form. This is great because it allows us to have a standard set of fields for all signup pages, making life a lot simpler when creating content that requires registration. But the Solutions Day event required an extra field. I could have done this a number of ways, including putting logic in the template file to check for that particular node and only display the field then, or perhaps some other hack specific to this node. I, however, don't like specifics and tend to look for a generic solution, as the exception invariably becomes the rule.
For this exercise I wanted to be able to have a way of specifying for a particular node any extra fields that are available for this form. So I now have in the template.php file the following code:
// If there is a special field required for this, check and display if (!empty($node->field_signup_extra) && !empty($node->field_signup_extra[0]['value'])) { $extras = explode("\n", $node->field_signup_extra[0]['value']); foreach ($extras as $field_def) { $field_def = trim($field_def); if (empty($field_def)) { continue; } $elems = explode('|', $field_def); $field_name = array_unshift($elems); $form['signup_form_data'][$field_name] = array(); foreach ($elems as $field_element) { list($key, $val) = explode('=',$field_element); if ($key == 'options') { $val = explode(',', $val); } $form['signup_form_data'][$field_name]['#' . $key] = $val; } } }
Now all I need to do is create a field that is non-displayable but contains information to build extra fields. For example the content that describes the Dietary Requirements field is:
dietary_requirements|title=Dietary Requirements|size=40|type=textfield
The production version does a little more analysis of the input to ensure there are no possible attack vectors, but I've left that out for clarity sake.
Now, if I have an event (or other content type) that needs extra signup fields, I ensure that the content type has the new Signup Extras field and fill it on the new content with a simple field definition that Signup can use.Original post blogged on Saki Envirotech Blogs.
-
Drizzle Day 2012
Henrik has already posted it over on the Drizzle Blog, but I thought I’d give a shout out here too.
We’re holding a Drizzle Day right after the Percona Live MySQL Conference and Expo in April. So, since you’re all like me and don’t book your travel this far in advance, it’ll be easy to stay for the extra day and come and learn awesome things about Drizzle.
I’m also pretty glad that my employer, Percona is sponsoring the event.
-
Three free MySQL webinars
I’m scheduled to deliver several free MySQL webinars via Percona and ODTUG in the upcoming weeks. I hope you can join me:
February 16 – Verifying Replication Integrity with Percona Toolkit via ODTUG.
February 22 – EXPLAIN Demystified via Percona.
March 14 – Optimizing MySQL Configuration via Percona.
Further Reading:Free webinar Wednesday: verifying replication integrity
Free webinar on MySQL performance this Thursday
Free webinar on preventing MySQL downtime
MySQL: Free Software but not Open Source
Get a free sample chapter of High Performance MySQL Second Edition
-
The community helping customers restore faster with mysqldump
A big thanks to Xiaobin Lin for taking the time to submit and the related patch for bug #64248. It could be available in MySQL 5.5.20. I was mistaken. The patch is based on 5.5.20 This should help users to restore their database faster thanks to fast index creation. More information is available via the bugs page. I have heard that this is just one of several patches he has contributed. Contributions such as this, help MySQL to continue to deliver an always improving product. So a big “Thank You” from the MySQL team.
-
XtraBackup Manager - Job Control, Better Debugging and some little fixes...
Hi Everyone,Just a quick note to let you know that I've just finished up adding some new features to XtraBackup Manager.You can now get better visibility into what is going on inside XtraBackup Manager with the "xbm status" command.It will allow you to see which backup jobs are running and also those which may be waiting to start, due to the maximum number of concurrent backup tasks already running.It looks/works as follows:[xbm@localhost ~]$ xbm statusXtraBackup Manager v0.8 - Copyright 2011-2012 Marin SoftwareCurrently Running Backups:+--------+-----------+-------------+---------------------+-------------------+------+| Job ID | Host | Backup Name | Start Time | Status | PID |+--------+-----------+-------------+---------------------+-------------------+------+| 14 | localhost | test-backup | 2012-02-07 14:19:19 | Performing Backup | 2525 |+--------+-----------+-------------+---------------------+-------------------+------+Note: I have to thank a tiny little BSD-licensed project I found on Google Code called PHP text table for saving me the need to reinvent the wheel in providing this very mysql command-line client-styled table output.In addition to seeing which jobs are running/queued, if there is a backup job you would like to abort for some reason, then you can now simply use the "xbm kill" command with a Job ID taken from the "xbm status" output:[xbm@localhost ~]$ xbm kill 14XtraBackup Manager v0.8 - Copyright 2011-2012 Marin SoftwareAction: Backup Job ID 14 was killed.The backup job itself will log an event at the ERROR level, like:2012-02-07 14:19:30 -0800 [ERROR] : [ The backup job was killed by an administrator. Aborting... ]2012-02-07 14:19:30 -0800 [INFO] : [ Cleaning up files... ]2012-02-07 14:19:30 -0800 [INFO] : [ Released lock on port 10000. ]2012-02-07 14:19:31 -0800 [ERROR] : [ Exiting after the backup job was killed... ]I'm still not 100% on whether an aborted backup message should be considered an "Error" level event or an "Info" level event. My thinking is that I'd prefer to know if a job was aborted, so I figure putting it at the ERROR level will ensure it is always logged.Now speaking quickly of the log levels -- it is now useful to increase your logging level in config.php from INFO to DEBUG.You will see the exact commands used for running backups by XtraBackup Manager, which can be useful when troubleshooting XBM-related issues.It will enable logging like the below -- Note: The password is _actually_ masked when writing the command to the log. You're welcome ;-)2012-02-07 14:19:19 -0800 [INFO] : [ Staging an INCREMENTAL xtrabackup snapshot of /var/lib/mysql via ssh: mysql@localhost to /tmp/xbm-3592510/deltas... ]2012-02-07 14:19:19 -0800 [DEBUG] : [ Attempting to run the incremental backup with command:ssh -o StrictHostKeyChecking=no -p 22 mysql@localhost 'cd /tmp/xbm-3592510 ; innobackupex --ibbackup=xtrabackup --slave-info --incremental-lsn=2325647 /tmp/xbm-3592510/deltas --user=root --safe-slave-backup --password=XXXXXXX --no-timestamp --incremental --throttle=0 1>&2 ' ]Aside from the above, some other small fixes were made, including ensuring that all temporary files created on the database host that you're backing up are created in the defined "staging_tmpdir" -- This is a parameter that is set at the host level in XtraBackup Manager.eg. shell> xbm host edit hostname staging_tmpdir /path/to/useI encourage you to check out the XtraBackup Manager Project and open issues with any problems you encounter or other feedback.Cheers,Lachlan
|