[ Index ]

PHP Cross Reference of phpBB-3.3.2-deutsch

title

Body

[close]

/phpbb/db/migration/data/v310/ -> style_update_p1.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\db\migration\data\v310;
  15  
  16  class style_update_p1 extends \phpbb\db\migration\migration
  17  {
  18  	public function effectively_installed()
  19      {
  20          return !$this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset');
  21      }
  22  
  23  	static public function depends_on()
  24      {
  25          return array('\phpbb\db\migration\data\v30x\release_3_0_11');
  26      }
  27  
  28  	public function update_schema()
  29      {
  30          return array(
  31              'add_columns'    => array(
  32                  $this->table_prefix . 'styles'        => array(
  33                      'style_path'            => array('VCHAR:100', ''),
  34                      'bbcode_bitfield'        => array('VCHAR:255', 'kNg='),
  35                      'style_parent_id'        => array('UINT', 0),
  36                      'style_parent_tree'        => array('TEXT', ''),
  37                  ),
  38              ),
  39          );
  40      }
  41  
  42  	public function revert_schema()
  43      {
  44          return array(
  45              'drop_columns'    => array(
  46                  $this->table_prefix . 'styles'        => array(
  47                      'style_path',
  48                      'bbcode_bitfield',
  49                      'style_parent_id',
  50                      'style_parent_tree',
  51                  ),
  52              ),
  53          );
  54      }
  55  
  56  	public function update_data()
  57      {
  58          return array(
  59              array('custom', array(array($this, 'styles_update'))),
  60          );
  61      }
  62  
  63  	public function styles_update()
  64      {
  65          // Get list of valid 3.1 styles
  66          $available_styles = array('prosilver');
  67  
  68          $iterator = new \DirectoryIterator($this->phpbb_root_path . 'styles');
  69          $skip_dirs = array('.', '..', 'prosilver');
  70          foreach ($iterator as $fileinfo)
  71          {
  72              if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg'))
  73              {
  74                  $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg');
  75                  if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>='))
  76                  {
  77                      // 3.1 style
  78                      $available_styles[] = $fileinfo->getFilename();
  79                  }
  80              }
  81          }
  82  
  83          // Get all installed styles
  84          if ($this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'))
  85          {
  86              $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path
  87                  FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . 'styles_theme c, ' . $this->table_prefix . "styles_imageset i
  88                  WHERE t.template_id = s.template_id
  89                      AND c.theme_id = s.theme_id
  90                      AND i.imageset_id = s.imageset_id";
  91          }
  92          else
  93          {
  94              $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id
  95                  FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . "styles_theme c
  96                  WHERE t.template_id = s.template_id
  97                      AND c.theme_id = s.theme_id";
  98          }
  99          $result = $this->db->sql_query($sql);
 100  
 101          $styles = array();
 102          while ($row = $this->db->sql_fetchrow($result))
 103          {
 104              $styles[] = $row;
 105          }
 106          $this->db->sql_freeresult($result);
 107  
 108          // Decide which styles to keep, all others will be deleted
 109          $valid_styles = array();
 110          foreach ($styles as $style_row)
 111          {
 112              if (
 113                  // Delete styles with parent style (not supported yet)
 114                  $style_row['template_inherits_id'] == 0 &&
 115                  // Check if components match
 116                  $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) &&
 117                  // Check if components are valid
 118                  in_array($style_row['template_path'], $available_styles)
 119                  )
 120              {
 121                  // Valid style. Keep it
 122                  $sql_ary = array(
 123                      'style_path'    => $style_row['template_path'],
 124                      'bbcode_bitfield'    => $style_row['bbcode_bitfield'],
 125                      'style_parent_id'    => 0,
 126                      'style_parent_tree'    => '',
 127                  );
 128                  $this->sql_query('UPDATE ' . STYLES_TABLE . '
 129                      SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
 130                      WHERE style_id = ' . $style_row['style_id']);
 131                  $valid_styles[] = (int) $style_row['style_id'];
 132              }
 133          }
 134  
 135          // Remove old entries from styles table
 136          if (!count($valid_styles))
 137          {
 138              // No valid styles: remove everything and add prosilver
 139              $this->sql_query('DELETE FROM ' . STYLES_TABLE);
 140  
 141              $sql_ary = array(
 142                  'style_name'        => 'prosilver',
 143                  'style_copyright'    => '&copy; phpBB Limited',
 144                  'style_active'        => 1,
 145                  'style_path'        => 'prosilver',
 146                  'bbcode_bitfield'    => 'lNg=',
 147                  'style_parent_id'    => 0,
 148                  'style_parent_tree'    => '',
 149  
 150                  // Will be removed in the next step
 151                  'imageset_id'        => 0,
 152                  'template_id'        => 0,
 153                  'theme_id'            => 0,
 154              );
 155  
 156              $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
 157              $this->sql_query($sql);
 158  
 159              $sql = 'SELECT style_id
 160                  FROM ' . STYLES_TABLE . "
 161                  WHERE style_name = 'prosilver'";
 162              $result = $this->sql_query($sql);
 163              $default_style = (int) $this->db->sql_fetchfield('style_id');
 164              $this->db->sql_freeresult($result);
 165  
 166              $this->config->set('default_style', $default_style);
 167  
 168              $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = ' .  (int) $default_style;
 169              $this->sql_query($sql);
 170          }
 171          else
 172          {
 173              // There are valid styles in styles table. Remove styles that are outdated
 174              $this->sql_query('DELETE FROM ' . STYLES_TABLE . '
 175                  WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true));
 176  
 177              // Change default style
 178              if (!in_array($this->config['default_style'], $valid_styles))
 179              {
 180                  $this->sql_query('UPDATE ' . CONFIG_TABLE . "
 181                      SET config_value = '" . $valid_styles[0] . "'
 182                      WHERE config_name = 'default_style'");
 183              }
 184  
 185              // Reset styles for users
 186              $this->sql_query('UPDATE ' . USERS_TABLE . "
 187                  SET user_style = '" . (int) $valid_styles[0] . "'
 188                  WHERE " . $this->db->sql_in_set('user_style', $valid_styles, true));
 189          }
 190      }
 191  }


Generated: Wed Nov 11 20:28:18 2020 Cross-referenced by PHPXref 0.7.1