[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/admin/ -> upgradeforumread.php (source)

   1  <?PHP  //$Id: upgradeforumread.php,v 1.13 2007/08/15 20:21:19 skodak Exp $
   2  
   3      require_once ('../config.php');
   4      require_once($CFG->dirroot.'/mod/forum/lib.php');
   5      require_once($CFG->libdir.'/adminlib.php');
   6  
   7      admin_externalpage_setup('upgradeforumread');
   8  
   9      $confirm = optional_param('confirm', 0, PARAM_BOOL);
  10  
  11      if ($CFG->version < 2005042300) {
  12          error("This script does not work with this old version of Moodle");
  13      }
  14  
  15      if (!$site = get_site()) {
  16          redirect('index.php');
  17      }
  18  
  19  
  20  /// Print header
  21  
  22      $strupgradingdata  = get_string('upgradingdata', 'admin');
  23  
  24      admin_externalpage_print_header();
  25      print_heading($strupgradingdata);
  26  
  27      if (!data_submitted() or empty($confirm) or !confirm_sesskey()) {
  28          $optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
  29          notice_yesno(get_string('upgradeforumreadinfo', 'admin'),
  30                      'upgradeforumread.php', 'index.php', $optionsyes, NULL, 'post', 'get');
  31          admin_externalpage_print_footer();
  32          exit;
  33      }
  34  
  35  
  36  /// Turn off time limits, sometimes upgrades can be slow.
  37  
  38      @set_time_limit(0);
  39      @ob_implicit_flush(true);
  40      while(@ob_end_flush());
  41  
  42      execute_sql('TRUNCATE TABLE '.$CFG->prefix.'forum_read;', false);   // Trash all old entries
  43  
  44  /// Enter initial read records for all posts older than 1 day.
  45  
  46  /// Timestamp for old posts (and therefore considered read).
  47      $dateafter = time() - ($CFG->forum_oldpostdays*24*60*60);
  48  
  49  /// Timestamp for one day ago.
  50      $onedayago = time() - (24*60*60);
  51  
  52  
  53  /// Get all discussions that have had posts since the old post date.
  54      if ($discussions = get_records_select('forum_discussions', 'timemodified > '.$dateafter,
  55                                            'course', 'id,course,forum,groupid,userid')) {
  56          $dtotal = count($discussions);
  57          print_heading('Updating forum post read/unread records for '.$dtotal.' discussions...'.
  58                        'Please keep this window open until it completes', '', 3);
  59  
  60          $groups = array();
  61  
  62          $currcourse = 0;
  63          $users = 0;
  64          $count = 0;
  65          $dcount = 0;
  66  
  67          foreach ($discussions as $discussion) {
  68              $dcount++;
  69              print_progress($dcount, $dtotal);
  70  
  71              if ($discussion->course != $currcourse) {
  72                  /// Discussions are ordered by course, so we only need to get any course's users once.
  73                  $currcourse = $discussion->course;
  74                  $users = get_course_users($currcourse, '', '', 'u.id,u.confirmed');
  75              }
  76              /// If this course has users, and posts more than a day old, mark them for each user.
  77              if ($users &&
  78                      ($posts = get_records_select('forum_posts', 'discussion = '.$discussion->id.
  79                                                   ' AND '.$dateafter.' < modified AND modified < '.$onedayago,
  80                                                   '', 'id,discussion,modified'))) {
  81                  foreach ($users as $user) {
  82                      /// If its a group discussion, make sure the user is in the group.
  83                      if ($discussion->groupid) {
  84                          if (!isset($groups[$discussion->groupid][$user->id])) {
  85                              $groups[$discussion->groupid][$user->id] = groups_is_member($discussion->groupid, $user->id);
  86                          }
  87                      }
  88                      if (!$discussion->groupid || !empty($groups[$discussion->groupid][$user->id])) {
  89                          foreach ($posts as $post) {
  90                              print_progress($dcount, $dtotal);
  91                              forum_tp_mark_post_read($user->id, $post, $discussion->forum);
  92                          }
  93                      }
  94                  }
  95              }
  96          }
  97          print_progress($dcount, $dtotal, 0);
  98      }
  99  
 100  
 101      delete_records('config', 'name', 'upgrade', 'value', 'forumread');
 102  
 103      notify('Log upgrading was successful!', 'notifysuccess');
 104  
 105      print_continue('index.php');
 106  
 107      admin_externalpage_print_footer();
 108  
 109  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7