2011022000-1.8_svn-custom_profile_fields-390ac967b0bb5665.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Elgg 2011010401 upgrade 00
  4. * custom_profile_fields
  5. *
  6. * Migrate 1.7 style custom profile fields to 1.8
  7. */
  8. $plugin = elgg_get_plugin_from_id('profile');
  9. // plugin not installed
  10. if (!$plugin) {
  11. return true;
  12. }
  13. $settings = $plugin->getAllSettings();
  14. // no fields to migrate
  15. if (!$settings['user_defined_fields']) {
  16. return true;
  17. }
  18. $order = array();
  19. $remove_settings = array();
  20. // make sure we have a name and type
  21. foreach ($settings as $k => $v) {
  22. if (!preg_match('/admin_defined_profile_([0-9]+)/i', $k, $matches)) {
  23. continue;
  24. }
  25. $i = $matches[1];
  26. $type_name = "admin_defined_profile_type_$i";
  27. $type = elgg_extract($type_name, $settings, null);
  28. if ($type) {
  29. // field name
  30. elgg_save_config($k, $v);
  31. // field value
  32. elgg_save_config($type_name, $type);
  33. $order[] = $i;
  34. $remove_settings[] = $k;
  35. $remove_settings[] = $type_name;
  36. }
  37. }
  38. if ($order) {
  39. // these will always need to be in order, but there might be gaps
  40. ksort($order);
  41. $order_str = implode(',', $order);
  42. elgg_save_config('profile_custom_fields', $order_str);
  43. foreach ($remove_settings as $name) {
  44. $plugin->unsetSetting($name);
  45. }
  46. $plugin->unsetSetting('user_defined_fields');
  47. }