function flag_update_export in Flag 7.3
Same name and namespace in other branches
- 6.2 includes/flag.export.inc \flag_update_export()
- 7.2 includes/flag.export.inc \flag_update_export()
Update a flag before export.
Parameters
flag_flag $flag: The flag object passed by reference.
1 call to flag_update_export()
- flag_update_page in includes/
flag.export.inc - Page for displaying an upgrade message and export form for Flag 1.x flags.
File
- includes/
flag.export.inc, line 253 - Import/Export functionality provided by Flag module.
Code
function flag_update_export(&$flag) {
// Set the API version to 1 by default: version 1 did not explicitly define
// the API version.
if (empty($flag->api_version)) {
$flag->api_version = 1;
}
// Get all our update classes.
// This is not terribly graceful, but the alternative is declaring our classes
// explicitly, or registering them with the Drupal autoloader and then running
// a database query, which seems a waste of space given we only ever need
// these here.
$classes = get_declared_classes();
$update_handlers = array();
foreach ($classes as $class) {
// Any class whose name is of the form 'FlagUpdate_foo' is one of ours, we
// assume. Should this prove problematic, we can add use of reflection here.
if (substr($class, 0, 11) == 'FlagUpdate_') {
// @todo: change this to work with the static class when we drop support
// for PHP 5.2: see commit d5b517.
$update_handler = new $class();
// Cast to string, as decimals as array keys seem to be rounded down to
// ints, WTF PHP?
$version = (string) $update_handler->old_api_version;
$update_handlers[$version] = $update_handler;
}
}
// Sort the classes by old version number.
uksort($update_handlers, 'version_compare');
// Work through each update handler.
foreach ($update_handlers as $old_api_version => $update_handler) {
// Skip update classes that are older than our current flag.
if (version_compare($old_api_version, $flag->api_version, '<')) {
continue;
}
// Run the update and change the API version on the flag.
$update_handler
->update($flag);
$flag->api_version = $update_handler->new_api_version;
}
}