[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/inc/tasks/ -> checktables.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  function task_checktables($task)
  13  {
  14      global $db, $mybb, $lang;
  15      
  16      // Sorry SQLite, you don't have a decent way of checking if the table is corrupted or not.
  17      if($db->type == "sqlite")
  18      {
  19          return;
  20      }
  21      
  22      @set_time_limit(0);
  23      
  24      $ok = array(
  25          "The storage engine for the table doesn't support check",
  26          "Table is already up to date",
  27          "OK"
  28      );
  29      
  30      $comma = "";
  31      $tables_list = "";
  32      $repaired = "";
  33  
  34      $tables = $db->list_tables($mybb->config['database']['database'], $mybb->config['database']['table_prefix']);
  35      foreach($tables as $key => $table)
  36      {
  37          $tables_list .= "{$comma}{$table} ";        
  38          $comma = ",";
  39      }
  40      
  41      if($tables_list)
  42      {
  43          $query = $db->query("CHECK TABLE {$tables_list}CHANGED;");
  44          while($table = $db->fetch_array($query))
  45          {
  46              if(!in_array($table['Msg_text'], $ok))
  47              {
  48                  if($table['Table'] != $mybb->config['database']['database'].".".TABLE_PREFIX."settings" && $setting_done != true)
  49                  {
  50                      $boardclosed = $mybb->settings['boardclosed'];
  51                      $boardclosed_reason = $mybb->settings['boardclosed_reason'];
  52                      
  53                      $db->update_query("settings", array('value' => 1), "name='boardclosed'", 1);
  54                      $db->update_query("settings", array('value' => $db->escape_string($lang->error_database_repair)), "name='boardclosed_reason'", 1);
  55                      rebuild_settings();
  56                      
  57                      $setting_done = true;
  58                  }
  59                  
  60                  $db->query("REPAIR TABLE {$table['Table']}");
  61                  $repaired[] = $table['Table'];
  62              }
  63          }
  64          
  65          if($table['Table'] != $mybb->config['database']['table_prefix'].".".TABLE_PREFIX."settings" && $setting_done == true)
  66          {
  67              $db->update_query("settings", array('value' => intval($boardclosed)), "name='boardclosed'", 1);
  68              $db->update_query("settings", array('value' => $db->escape_string($boardclosed_reason)), "name='boardclosed_reason'", 1);
  69                      
  70              rebuild_settings();
  71          }
  72          
  73      }
  74      
  75      if(!empty($repaired))
  76      {
  77          add_task_log($task, $lang->sprintf($lang->task_checktables_ran_found, implode(', ', $repaired)));
  78      }
  79      else
  80      {
  81          add_task_log($task, $lang->task_checktables_ran);
  82      }
  83  }
  84  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1