2015041400-1.11.0_dev-trim_metastrings-d9a9fdfa28a981a3.php 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. * Elgg 1.11.0-dev upgrade 2015041400
  4. * trim_metastrings
  5. *
  6. * Trim all whitespace padding in metastrings
  7. */
  8. $prefix = elgg_get_config('dbprefix');
  9. $q = "SELECT * FROM {$prefix}metastrings WHERE string REXEXP '^[ ]+|[ ]+$'";
  10. $r = mysql_query($q);
  11. while ($ms = mysql_fetch_assoc($r)) {
  12. // find if trimmed version collides with existing MS
  13. $string = sanitize_string(trim($ms['string']));
  14. $existing = get_data_row("SELECT * FROM {$prefix}metastrings WHERE string = BINARY '$string' LIMIT 1");
  15. if ($existing) {
  16. // delete the padded string and update MD / annotations to use the existing trimmed one
  17. $q = "DELETE FROM {$prefix}metastrings WHERE id = {$ms['id']} LIMIT 1";
  18. if (delete_data($q)) {
  19. update_data("UPDATE {$prefix}metadata SET name_id = '{$existing->id}' where name_id = '{$ms['id']}'");
  20. update_data("UPDATE {$prefix}metadata SET value_id = '{$existing->id}' where value_id = '{$ms['id']}'");
  21. update_data("UPDATE {$prefix}annotations SET name_id = '{$existing->id}' where name_id = '{$ms['id']}'");
  22. update_data("UPDATE {$prefix}annotations SET value_id = '{$existing->id}' where value_id = '{$ms['id']}'");
  23. }
  24. } else {
  25. update_data("UPDATE {$prefix}metastrings SET string = '$string' where id = '{$ms['id']}'");
  26. }
  27. }