You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201405302318_add_relations_to_zone_templates.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. include_once('../inc/config-me.inc.php');
  3. if (!@include_once('../inc/config.inc.php')) {
  4. error(_('You have to create a config.inc.php!'));
  5. }
  6. require '../inc/error.inc.php';
  7. require '../inc/database.inc.php';
  8. require '../inc/file.inc.php';
  9. require '../inc/record.inc.php';
  10. require '../inc/migrations.inc.php';
  11. $db = dbConnect();
  12. $file_name = file_get_name_without_extension(__FILE__);
  13. if (migration_exists($db, $file_name)) {
  14. migration_message('The migration had already been applied!');
  15. exit;
  16. }
  17. $zones = get_zones_with_templates($db);
  18. foreach ($zones as $zone) {
  19. $domain = get_zone_name_from_id($zone['id']);
  20. $templ_records = get_zone_templ_records($zone['zone_templ_id']);
  21. $generated_templ_records = array();
  22. foreach ($templ_records as $templ_record) {
  23. $name = parse_template_value($templ_record['name'], $domain);
  24. $type = $templ_record['type'];
  25. $content = parse_template_value($templ_record['content'], $domain);
  26. $generated_templ_records[] = array(
  27. 'name' => $name,
  28. 'type' => $type,
  29. 'content' => $content,
  30. );
  31. }
  32. $records = get_records_by_domain_id($db, $zone['domain_id']);
  33. foreach ($records as $record) {
  34. foreach ($generated_templ_records as $generated_templ_record) {
  35. if ($record['name'] == $generated_templ_record['name'] &&
  36. $record['type'] == $generated_templ_record['type'] &&
  37. $record['content'] == $generated_templ_record['content']) {
  38. if (!record_relation_to_templ_exists($db, $zone['domain_id'], $record['id'], $zone['zone_templ_id'])) {
  39. add_record_relation_to_templ($db, $zone['domain_id'], $record['id'], $zone['zone_templ_id']);
  40. }
  41. break;
  42. }
  43. }
  44. }
  45. }
  46. migration_message('Relations between records and zone templates added successfully');
  47. migration_save($db, $file_name);