| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: flag.export.inc,v 1.1.2.1 2009/10/28 00:31:47 quicksketch Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 136 |
/** |
/** |
| 137 |
* Export a flag and display it in a form. |
* Export a flag and display it in a form. |
| 138 |
*/ |
*/ |
| 139 |
function flag_export_form(&$form_state, $flag_name = NULL) { |
function flag_export_form(&$form_state, $flag = NULL) { |
| 140 |
$form = array(); |
$form = array(); |
| 141 |
|
|
| 142 |
// Convert a flag name (if any) to the list of export flags. |
// Convert a flag name (if any) to the list of export flags. |
| 143 |
if ($flag = flag_get_flag($flag_name)) { |
if (is_object($flag) || ($flag = flag_get_flag($flag))) { |
| 144 |
$flags = array($flag); |
$flags = array($flag); |
| 145 |
} |
} |
| 146 |
|
|
| 193 |
function flag_export_form_submit($form, &$form_state) { |
function flag_export_form_submit($form, &$form_state) { |
| 194 |
$form_state['rebuild'] = TRUE; |
$form_state['rebuild'] = TRUE; |
| 195 |
} |
} |
| 196 |
|
|
| 197 |
|
/** |
| 198 |
|
* Page for displaying an upgrade message and export form for Flag 1.x flags. |
| 199 |
|
*/ |
| 200 |
|
function flag_update_page($flag_name) { |
| 201 |
|
$flags = flag_get_default_flags(TRUE); |
| 202 |
|
if (!isset($flags[$flag_name])) { |
| 203 |
|
drupal_not_found(); |
| 204 |
|
return; |
| 205 |
|
} |
| 206 |
|
|
| 207 |
|
if ($flags[$flag_name]->api_version == FLAG_API_VERSION) { |
| 208 |
|
drupal_set_message(t('The flag %name is already up-to-date with the latest Flag API and does not need upgrading.')); |
| 209 |
|
drupal_goto('admin/build/flags'); |
| 210 |
|
} |
| 211 |
|
|
| 212 |
|
$flag = $flags[$flag_name]; |
| 213 |
|
drupal_set_message(t('The flag %name is currently using the Flag API version @version, which is not compatible with the current version of Flag. You can upgrade this flag by pasting the below code into <em>@module_flag_default_flags()</em> function in the @module.module file.', array('%name' => $flag->name, '@version' => $flag->api_version, '@module' => $flag->module)), 'warning'); |
| 214 |
|
|
| 215 |
|
flag_update_export($flag); |
| 216 |
|
|
| 217 |
|
return drupal_get_form('flag_export_form', $flag); |
| 218 |
|
} |
| 219 |
|
|
| 220 |
|
/** |
| 221 |
|
* Update a flag before export. |
| 222 |
|
* |
| 223 |
|
* @param $flag |
| 224 |
|
* The flag object passed by reference. |
| 225 |
|
*/ |
| 226 |
|
function flag_update_export(&$flag) { |
| 227 |
|
// Update differences. |
| 228 |
|
if (empty($flag->api_version) || $flag->api_version == 1) { |
| 229 |
|
if (isset($flag->roles) && !isset($flag->roles['flag'])) { |
| 230 |
|
$flag->roles = array( |
| 231 |
|
'flag' => $flag->roles, |
| 232 |
|
'unflag' => $flag->roles, |
| 233 |
|
); |
| 234 |
|
} |
| 235 |
|
$flag->api_version = FLAG_API_VERSION; |
| 236 |
|
} |
| 237 |
|
} |