[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/install/resources/ -> upgrade36.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  /**
  12   * Upgrade Script: 1.8.7
  13   */
  14  
  15  $upgrade_detail = array(
  16      "revert_all_templates" => 0,
  17      "revert_all_themes" => 0,
  18      "revert_all_settings" => 0
  19  );
  20  
  21  @set_time_limit(0);
  22  
  23  function upgrade36_dbchanges()
  24  {
  25      global $db, $output, $mybb;
  26  
  27      $output->print_header("Updating Database");
  28      echo "<p>Performing necessary upgrade queries...</p>";
  29      flush();
  30  
  31      if($db->field_exists('enabled', 'attachtypes'))
  32      {
  33          $db->drop_column('attachtypes', 'enabled');
  34      }
  35  
  36      if($db->field_exists('groups', 'attachtypes'))
  37      {
  38          $db->drop_column('attachtypes', 'groups');
  39      }
  40  
  41      if($db->field_exists('forums', 'attachtypes'))
  42      {
  43          $db->drop_column('attachtypes', 'forums');
  44      }
  45  
  46      if($db->field_exists('avatarfile', 'attachtypes'))
  47      {
  48          $db->drop_column('attachtypes', 'avatarfile');
  49      }
  50  
  51      switch($db->type)
  52      {
  53          case "pgsql":
  54              $db->add_column('attachtypes', 'enabled', "smallint NOT NULL default '1'");
  55              $db->add_column('attachtypes', 'groups', "text NOT NULL default '-1'");
  56              $db->add_column('attachtypes', 'forums', "text NOT NULL default '-1'");
  57              $db->add_column('attachtypes', 'avatarfile', "smallint NOT NULL default '0'");
  58              break;
  59          default:
  60              $db->add_column('attachtypes', 'enabled', "tinyint(1) NOT NULL default '1'");
  61              $db->add_column('attachtypes', 'groups', "TEXT NOT NULL");
  62              $db->add_column('attachtypes', 'forums', "TEXT NOT NULL");
  63              $db->add_column('attachtypes', 'avatarfile', "tinyint(1) NOT NULL default '0'");
  64  
  65              $db->update_query('attachtypes', array('groups' => '-1', 'forums' => '-1'));
  66              break;
  67      }
  68  
  69      $db->update_query('attachtypes', array('avatarfile' => 1), "atid IN (2, 4, 7, 11)");
  70  
  71      if($mybb->settings['username_method'] == 1 || $mybb->settings['username_method'] == 2)
  72      {
  73          $query = $db->simple_select('users', 'email, COUNT(email) AS duplicates', "email!=''", array('group_by' => 'email HAVING duplicates>1'));
  74          if($db->num_rows($query))
  75          {
  76              $db->update_query('settings', array('value' => 0), "name='username_method'");
  77          }
  78          else
  79          {
  80              $db->update_query('settings', array('value' => 0), "name='allowmultipleemails'");
  81          }
  82      }
  83  
  84      $query = $db->simple_select("templategroups", "COUNT(*) as numexists", "prefix='mycode'");
  85      if($db->fetch_field($query, "numexists") == 0)
  86      {
  87          $db->insert_query("templategroups", array('prefix' => 'mycode', 'title' => '<lang:group_mycode>', 'isdefault' => '1'));
  88      }
  89  
  90      $output->print_contents("<p>Click next to continue with the upgrade process.</p>");
  91      $output->print_footer("36_dbchanges2");
  92  }
  93  
  94  function upgrade36_dbchanges2()
  95  {
  96      global $output, $db, $cache;
  97  
  98      $output->print_header("Updating Database");
  99      echo "<p>Performing necessary upgrade queries...</p>";
 100      flush();
 101  
 102      if($db->field_exists('reasonid', 'reportedcontent'))
 103      {
 104          $db->drop_column("reportedcontent", "reasonid");
 105      }
 106  
 107      switch($db->type)
 108      {
 109          case "pgsql":
 110          case "sqlite":
 111              $db->add_column("reportedcontent", "reasonid", "smallint NOT NULL default '0' AFTER reportstatus");
 112              break;
 113          default:
 114              $db->add_column("reportedcontent", "reasonid", "smallint unsigned NOT NULL default '0' AFTER reportstatus");
 115              break;
 116      }
 117  
 118  
 119      if($db->table_exists("reportreasons"))
 120      {
 121          $db->drop_table("reportreasons");
 122      }
 123  
 124      $collation = $db->build_create_table_collation();
 125  
 126      switch($db->type)
 127      {
 128          case "pgsql":
 129              $db->write_query("CREATE TABLE ".TABLE_PREFIX."reportreasons (
 130                   rid serial,
 131                   title varchar(250) NOT NULL default '',
 132                   appliesto varchar(250) NOT NULL default '',
 133                   extra smallint NOT NULL default '0',
 134                   disporder smallint NOT NULL default '0',
 135                   PRIMARY KEY (rid)
 136              );");
 137              break;
 138          case "sqlite":
 139              $db->write_query("CREATE TABLE ".TABLE_PREFIX."reportreasons (
 140                   rid INTEGER PRIMARY KEY,
 141                   title varchar(250) NOT NULL default '',
 142                   appliesto varchar(250) NOT NULL default '',
 143                   extra tinyint(1) NOT NULL default '0',
 144                   disporder smallint NOT NULL default '0',
 145              );");
 146              break;
 147          default:
 148              $db->write_query("CREATE TABLE ".TABLE_PREFIX."reportreasons (
 149                   rid int unsigned NOT NULL auto_increment,
 150                    title varchar(250) NOT NULL default '',
 151                    appliesto varchar(250) NOT NULL default '',
 152                    extra tinyint(1) NOT NULL default '0',
 153                    disporder smallint unsigned NOT NULL default '0',
 154                    PRIMARY KEY (rid)
 155              ) ENGINE=MyISAM{$collation};");
 156              break;
 157      }
 158  
 159      $reportreasons = array(
 160          array(
 161              'rid' => 1,
 162              'title' => "<lang:report_reason_other>",
 163              'appliesto' => "all",
 164              'extra' => 1,
 165              'disporder' => 99
 166          ),
 167          array(
 168              'rid' => 2,
 169              'title' => "<lang:report_reason_rules>",
 170              'appliesto' => "all",
 171              'extra' => 0,
 172              'disporder' => 1
 173          ),
 174          array(
 175              'rid' => 3,
 176              'title' => "<lang:report_reason_bad>",
 177              'appliesto' => "all",
 178              'extra' => 0,
 179              'disporder' => 2
 180          ),
 181          array(
 182              'rid' => 4,
 183              'title' => "<lang:report_reason_spam>",
 184              'appliesto' => "all",
 185              'extra' => 0,
 186              'disporder' => 3
 187          ),
 188          array(
 189              'rid' => 5,
 190              'title' => "<lang:report_reason_wrong>",
 191              'appliesto' => "post",
 192              'extra' => 0,
 193              'disporder' => 4
 194          )
 195      );
 196  
 197      $db->insert_query_multiple('reportreasons', $reportreasons);
 198  
 199      $templang = new MyLanguage();
 200      $templang->set_path(MYBB_ROOT."inc/languages");
 201  
 202      $langs = array_keys($templang->get_languages());
 203  
 204      foreach($langs as $langname)
 205      {
 206          unset($templang);
 207          $templang = new MyLanguage();
 208          $templang->set_path(MYBB_ROOT."inc/languages");
 209          $templang->set_language($langname);
 210          $templang->load("report");
 211  
 212          if(!empty($templang->report_reason_rules) && $templang->report_reason_rules != '')
 213          {
 214              $db->update_query("reportedcontent", array("reasonid" => 2, "reason" => ''), "reason = '".$db->escape_string("\n".$templang->report_reason_rules)."'");
 215          }
 216          if(!empty($templang->report_reason_bad) && $templang->report_reason_bad != '')
 217          {
 218              $db->update_query("reportedcontent", array("reasonid" => 3, "reason" => ''), "reason = '".$db->escape_string("\n".$templang->report_reason_bad)."'");
 219          }
 220          if(!empty($templang->report_reason_spam) && $templang->report_reason_spam != '')
 221          {
 222              $db->update_query("reportedcontent", array("reasonid" => 4, "reason" => ''), "reason = '".$db->escape_string("\n".$templang->report_reason_spam)."'");
 223          }
 224          if(!empty($templang->report_reason_wrong) && $templang->report_reason_wrong != '')
 225          {
 226              $db->update_query("reportedcontent", array("reasonid" => 5, "reason" => ''), "reason = '".$db->escape_string("\n".$templang->report_reason_wrong)."'");
 227          }
 228      }
 229  
 230      // Any reason not converted is treated as "Other" with extra text specified
 231      $db->update_query("reportedcontent", array('reasonid' => 1), "reason != ''");
 232  
 233      $output->print_contents("<p>Click next to continue with the upgrade process.</p>");
 234      $output->print_footer("36_done");
 235  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref