check_extra_fields.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script checks if the default extra fields are present in the platform.
  5. * If a default extra field doesn't exists then it will created.
  6. * Extra field list as in 1.11.8
  7. */
  8. exit;
  9. require_once __DIR__.'/../../main/inc/global.inc.php';
  10. $em = Database::getManager();
  11. $repo = $em->getRepository('ChamiloCoreBundle:ExtraField');
  12. $extraFields = $repo->findAll();
  13. $list = [
  14. 'legal_accept' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 1, 'legal_accept','Legal',0,0, NOW());",
  15. 'already_logged_in' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 1, 'already_logged_in','Already logged in',0,0, NOW());",
  16. 'update_type' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 1, 'update_type','Update script type',0,0, NOW())",
  17. 'rssfeeds' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 1, 'rssfeeds','RSS',0,0, NOW())",
  18. 'dashboard' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 1, 'dashboard', 'Dashboard', 0, 0, NOW())",
  19. 'timezone' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 11, 'timezone', 'Timezone', 0, 0, NOW())",
  20. 'user_chat_status' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 1, 'user_chat_status','User chat status',0,0, NOW())",
  21. 'google_calendar_url' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 1, 'google_calendar_url','Google Calendar URL',0,0, NOW())",
  22. 'special_course' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, default_value, created_at) VALUES (2, 13, 'special_course', 'Special course', 1 , 1, '', NOW())",
  23. 'video_url' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (2, 19, 'video_url', 'VideoUrl', 1, 1, NOW())",
  24. 'image' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (3, 16, 'image', 'Image', 1, 1, NOW())",
  25. 'captcha_blocked_until_date' => "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 1, 'captcha_blocked_until_date', 'Account locked until', 0, 0, NOW())",
  26. ];
  27. $extraFieldList = [];
  28. /** @var \Chamilo\CoreBundle\Entity\ExtraField $extraField */
  29. foreach ($extraFields as $extraField) {
  30. $extraFieldList[$extraField->getVariable()] = $extraField;
  31. }
  32. $extraFieldVariableList = array_keys($extraFieldList);
  33. $queriesExecuted = [];
  34. foreach ($list as $variable => $sql) {
  35. if (!in_array($variable, $extraFieldVariableList)) {
  36. Database::query($sql);
  37. $queriesExecuted[] = $sql;
  38. }
  39. }
  40. if (!isset($extraFieldList['mail_notify_invitation'])) {
  41. $sql = "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, default_value, created_at) values (1, 4, 'mail_notify_invitation', 'MailNotifyInvitation',0,1,'1', NOW())";
  42. Database::query($sql);
  43. $queriesExecuted[] = $sql;
  44. $id = Database::insert_id();
  45. $sql = "INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES ($id, '1', 'AtOnce',1)";
  46. Database::query($sql);
  47. $queriesExecuted[] = $sql;
  48. $sql = "INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES ($id, '8', 'Daily',2)";
  49. Database::query($sql);
  50. $queriesExecuted[] = $sql;
  51. $sql = "INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES ($id, '0', 'No',3)";
  52. Database::query($sql);
  53. $queriesExecuted[] = $sql;
  54. }
  55. if (!isset($extraFieldList['mail_notify_message'])) {
  56. $sql = "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, default_value, created_at) values (1, 4, 'mail_notify_message', 'MailNotifyMessage',0,1,'1', NOW())";
  57. Database::query($sql);
  58. $queriesExecuted[] = $sql;
  59. $id = Database::insert_id();
  60. if ($id) {
  61. $sql = "INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES ($id, '1', 'AtOnce',1)";
  62. Database::query($sql);
  63. $queriesExecuted[] = $sql;
  64. $sql = "INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES ($id, '8', 'Daily',2)";
  65. Database::query($sql);
  66. $queriesExecuted[] = $sql;
  67. $sql = "INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES ($id, '0', 'No',3)";
  68. Database::query($sql);
  69. $queriesExecuted[] = $sql;
  70. }
  71. }
  72. if (!isset($extraFieldList['mail_notify_group_message'])) {
  73. $sql = "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, default_value, created_at) values (1, 4, 'mail_notify_group_message','MailNotifyGroupMessage',0,1,'1', NOW())";
  74. Database::query($sql);
  75. $queriesExecuted[] = $sql;
  76. $id = Database::insert_id();
  77. if ($id) {
  78. $sql = "INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES ($id, '1', 'AtOnce',1)";
  79. Database::query($sql);
  80. $queriesExecuted[] = $sql;
  81. $sql = "INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES ($id, '8', 'Daily',2)";
  82. Database::query($sql);
  83. $queriesExecuted[] = $sql;
  84. $sql = "INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES ($id, '0', 'No',3)";
  85. Database::query($sql);
  86. $queriesExecuted[] = $sql;
  87. }
  88. }
  89. $tag1Exists = false;
  90. $tag2Exists = false;
  91. foreach ($extraFields as $extraField) {
  92. if ($extraField->getVariable() === 'tags' && $extraField->getExtraFieldType() == 1) {
  93. $tag1Exists = true;
  94. }
  95. if ($extraField->getVariable() === 'tags' && $extraField->getExtraFieldType() == 2) {
  96. $tag2Exists = true;
  97. }
  98. }
  99. if ($tag1Exists === false) {
  100. $sql = "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (1, 10, 'tags','tags',0,0, NOW())";
  101. Database::query($sql);
  102. $queriesExecuted[] = $sql;
  103. }
  104. if ($tag2Exists === false) {
  105. $sql = "INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at) VALUES (2, 10, 'tags', 'Tags', 1, 1, NOW())";
  106. Database::query($sql);
  107. $queriesExecuted[] = $sql;
  108. }
  109. if (empty($queriesExecuted)) {
  110. echo 'No database changes';
  111. exit;
  112. }
  113. foreach ($queriesExecuted as $query) {
  114. echo $query.PHP_EOL;
  115. }