fix_schedules.php 1.1 KB

123456789101112131415161718192021222324
  1. <?php
  2. /**
  3. * Finds the sessions without access date and defines (for all sessions without access date older than 30
  4. * days in the past from now) a new access date based on the period (which can be found in the session
  5. * name).
  6. * @package chamilo.migrate
  7. */
  8. require_once '../../main/inc/global.inc.php';
  9. $log = 'sessions_dates_changes.txt';
  10. $ts = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_OPTIONS);
  11. //$sql = "SELECT * FROM $ts WHERE access_start_date = '0000-00-00 00:00:00' AND access_end_date = '0000-00-00 00:00:00' ORDER BY name";
  12. //$sql = "SELECT * FROM $ts WHERE access_start_date = '0000-00-00 00:00:00' OR access_end_date = '0000-00-00 00:00:00' ORDER BY name";
  13. $sql = "SELECT id, option_display_text FROM $ts WHERE field_id = 4";
  14. echo $sql."\n";
  15. $res = Database::query($sql);
  16. if ($res !== false) {
  17. while ($row = Database::fetch_assoc($res)) {
  18. //echo "Session ".$row['name']." has no start/end date\n";
  19. $name = $row['option_display_text'];
  20. $name = substr($name,5).' '.substr($name,0,4);
  21. $sql2 = "UPDATE $ts SET option_display_text = '$name' WHERE id = ".$row['id'];
  22. $res2 = Database::query($sql2);
  23. }
  24. }