Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

style_update_p1.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 5.71 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\db\migration\data\v310;
 015   
 016  class style_update_p1 extends \phpbb\db\migration\migration
 017  {
 018      public function effectively_installed()
 019      {
 020          return !$this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset');
 021      }
 022   
 023      static public function depends_on()
 024      {
 025          return array('\phpbb\db\migration\data\v30x\release_3_0_11');
 026      }
 027   
 028      public function update_schema()
 029      {
 030          return array(
 031              'add_columns'    => array(
 032                  $this->table_prefix . 'styles'        => array(
 033                      'style_path'            => array('VCHAR:100', ''),
 034                      'bbcode_bitfield'        => array('VCHAR:255', 'kNg='),
 035                      'style_parent_id'        => array('UINT', 0),
 036                      'style_parent_tree'        => array('TEXT', ''),
 037                  ),
 038              ),
 039          );
 040      }
 041   
 042      public function revert_schema()
 043      {
 044          return array(
 045              'drop_columns'    => array(
 046                  $this->table_prefix . 'styles'        => array(
 047                      'style_path',
 048                      'bbcode_bitfield',
 049                      'style_parent_id',
 050                      'style_parent_tree',
 051                  ),
 052              ),
 053          );
 054      }
 055   
 056      public function update_data()
 057      {
 058          return array(
 059              array('custom', array(array($this, 'styles_update'))),
 060          );
 061      }
 062   
 063      public function styles_update()
 064      {
 065          // Get list of valid 3.1 styles
 066          $available_styles = array('prosilver');
 067   
 068          $iterator = new \DirectoryIterator($this->phpbb_root_path . 'styles');
 069          $skip_dirs = array('.', '..', 'prosilver');
 070          foreach ($iterator as $fileinfo)
 071          {
 072              if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg'))
 073              {
 074                  $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg');
 075                  if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>='))
 076                  {
 077                      // 3.1 style
 078                      $available_styles[] = $fileinfo->getFilename();
 079                  }
 080              }
 081          }
 082   
 083          // Get all installed styles
 084          if ($this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'))
 085          {
 086              $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
 087                  FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . 'styles_theme c, ' . $this->table_prefix . "styles_imageset i
 088                  WHERE t.template_id = s.template_id
 089                      AND c.theme_id = s.theme_id
 090                      AND i.imageset_id = s.imageset_id";
 091          }
 092          else
 093          {
 094              $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
 095                  FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . "stles_theme c
 096                  WHERE t.template_id = s.template_id
 097                      AND c.theme_id = s.theme_id";
 098          }
 099          $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 (!sizeof($valid_styles))
 137          {
 138              // No valid styles: remove everything and add prosilver
 139              $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary);
 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 ' . $table . "
 161                  WHERE style_name = 'prosilver'";
 162              $result = $this->sql_query($sql);
 163              $default_style = $this->db->sql_fetchfield($result);
 164              $this->db->sql_freeresult($result);
 165   
 166              set_config('default_style', $default_style);
 167   
 168              $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0';
 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 = 0
 188                  WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true));
 189          }
 190      }
 191  }
 192