[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/phpbb/db/migration/data/v33x/ -> remove_profilefield_aol.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\v33x;
  15  
  16  class remove_profilefield_aol extends \phpbb\db\migration\migration
  17  {
  18  	public function effectively_installed()
  19      {
  20          return !$this->db_tools->sql_column_exists($this->table_prefix . 'profile_fields_data', 'pf_phpbb_aol');
  21      }
  22  
  23  	static public function depends_on()
  24      {
  25          return [
  26              '\phpbb\db\migration\data\v33x\v331',
  27          ];
  28      }
  29  
  30  	public function update_schema()
  31      {
  32          return [
  33              'drop_columns'    => [
  34                  $this->table_prefix . 'profile_fields_data'            => [
  35                      'pf_phpbb_aol',
  36                  ],
  37              ],
  38          ];
  39      }
  40  
  41  	public function revert_schema()
  42      {
  43          return [
  44              'add_columns'    => [
  45                  $this->table_prefix . 'profile_fields_data'            => [
  46                      'pf_phpbb_aol'        => ['VCHAR', ''],
  47                  ],
  48              ],
  49          ];
  50      }
  51  
  52  	public function update_data()
  53      {
  54          return [
  55              ['custom', [[$this, 'delete_custom_profile_field_data']]],
  56          ];
  57      }
  58  
  59  	public function revert_data()
  60      {
  61          return [
  62              ['custom', [[$this, 'create_custom_field']]],
  63          ];
  64      }
  65  
  66  	public function delete_custom_profile_field_data()
  67      {
  68          $sql = 'SELECT field_id
  69              FROM ' . PROFILE_FIELDS_TABLE . "
  70              WHERE field_name = 'phpbb_aol'";
  71          $result = $this->db->sql_query($sql);
  72          $field_id = (int) $this->db->sql_fetchfield('field_id');
  73          $this->db->sql_freeresult($result);
  74  
  75          $sql = 'DELETE FROM ' . PROFILE_FIELDS_TABLE . '
  76              WHERE field_id = ' . (int) $field_id;
  77          $this->db->sql_query($sql);
  78  
  79          $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . '
  80              WHERE field_id = ' . (int) $field_id;
  81          $this->db->sql_query($sql);
  82  
  83          $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . '
  84              WHERE field_id = ' . (int) $field_id;
  85          $this->db->sql_query($sql);
  86      }
  87  
  88  	public function create_custom_field()
  89      {
  90          $sql = 'SELECT MAX(field_order) as max_field_order
  91              FROM ' . PROFILE_FIELDS_TABLE;
  92          $result = $this->db->sql_query($sql);
  93          $max_field_order = (int) $this->db->sql_fetchfield('max_field_order');
  94          $this->db->sql_freeresult($result);
  95  
  96          $sql_ary = [
  97              'field_name'            => 'phpbb_aol',
  98              'field_type'            => 'profilefields.type.string',
  99              'field_ident'            => 'phpbb_aol',
 100              'field_length'            => '40',
 101              'field_minlen'            => '5',
 102              'field_maxlen'            => '255',
 103              'field_novalue'            => '',
 104              'field_default_value'    => '',
 105              'field_validation'        => '.*',
 106              'field_required'        => 0,
 107              'field_show_novalue'    => 0,
 108              'field_show_on_reg'        => 0,
 109              'field_show_on_pm'        => 1,
 110              'field_show_on_vt'        => 1,
 111              'field_show_on_ml'        => 0,
 112              'field_show_profile'    => 1,
 113              'field_hide'            => 0,
 114              'field_no_view'            => 0,
 115              'field_active'            => 1,
 116              'field_is_contact'        => 1,
 117              'field_contact_desc'    => '',
 118              'field_contact_url'        => '',
 119              'field_order'            => $max_field_order + 1,
 120          ];
 121  
 122          $sql = 'INSERT INTO ' . PROFILE_FIELDS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
 123          $this->db->sql_query($sql);
 124          $field_id = (int) $this->db->sql_nextid();
 125  
 126          $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, PROFILE_LANG_TABLE);
 127  
 128          $sql = 'SELECT lang_id
 129              FROM ' . LANG_TABLE;
 130          $result = $this->db->sql_query($sql);
 131          $lang_name = 'AOL';
 132          while ($lang_id = (int) $this->db->sql_fetchfield('lang_id'))
 133          {
 134              $insert_buffer->insert([
 135                  'field_id'                => (int) $field_id,
 136                  'lang_id'                => (int) $lang_id,
 137                  'lang_name'                => $lang_name,
 138                  'lang_explain'            => '',
 139                  'lang_default_value'    => '',
 140              ]);
 141          }
 142          $this->db->sql_freeresult($result);
 143  
 144          $insert_buffer->flush();
 145      }
 146  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1