fix_duplicate_settings.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * Remove the current_settings duplicates from migration 1.9.x to 1.10.x
  5. */
  6. //exit;
  7. require_once dirname(__FILE__) . '/../../main/inc/global.inc.php';
  8. //api_protect_admin_script();
  9. $entityManager = Database::getManager();
  10. $settingsCurrentRepo = $entityManager->getRepository('ChamiloCoreBundle:SettingsCurrent');
  11. $settingsOptionsRepo = $entityManager->getRepository('ChamiloCoreBundle:SettingsOptions');
  12. $settingsCurrent = $settingsCurrentRepo->findBy([], ['id' => 'ASC']);
  13. $cleanList = [];
  14. $duplicatedCurrent = [];
  15. foreach ($settingsCurrent as $settingCurrent) {
  16. $key = vsprintf(
  17. "%s-%s-%s",
  18. [
  19. $settingCurrent->getVariable(),
  20. $settingCurrent->getSubkey(),
  21. $settingCurrent->getAccessUrl()
  22. ]
  23. );
  24. if (!array_key_exists($key, $cleanList)) {
  25. $cleanList[$key] = $settingCurrent;
  26. continue;
  27. }
  28. $duplicatedCurrent[] = $settingCurrent;
  29. }
  30. $settingsOptions = $settingsOptionsRepo->findBy([], ['id' => 'ASC']);
  31. $cleanList = [];
  32. $duplicatedOptions = [];
  33. foreach ($settingsOptions as $settingOption) {
  34. $key = vsprintf(
  35. "%s-%s",
  36. [
  37. $settingOption->getVariable(),
  38. $settingOption->getValue()
  39. ]
  40. );
  41. if (!array_key_exists($key, $cleanList)) {
  42. $cleanList[$key] = $settingOption;
  43. continue;
  44. }
  45. $duplicatedOptions[] = $settingOption;
  46. }
  47. // View
  48. echo "<br>Removing the settings_current:<br>" . PHP_EOL;
  49. if (empty($duplicatedCurrent)) {
  50. echo "No results";
  51. } else {
  52. foreach ($duplicatedCurrent as $settingCurrent) {
  53. echo vsprintf(
  54. "variable = '%s' subkey = '%s' access_url = '%s'<br>" . PHP_EOL,
  55. [$settingCurrent->getVariable(), $settingCurrent->getSubkey(), $settingCurrent->getAccessUrl()]
  56. );
  57. $entityManager->remove($settingCurrent);
  58. }
  59. }
  60. echo "<br>Removing the settings_options:<br>" . PHP_EOL;
  61. if (empty($duplicatedOptions)) {
  62. echo "No results";
  63. } else {
  64. foreach ($duplicatedOptions as $settingOption) {
  65. echo vsprintf(
  66. "variable = '%s' value = '%s'<br>" . PHP_EOL,
  67. [$settingOption->getVariable(), $settingOption->getValue()]
  68. );
  69. $entityManager->remove($settingOption);
  70. }
  71. }
  72. $entityManager->flush();