Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

profilefields_update.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 5.48 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\v33x;
015   
016  class profilefields_update extends \phpbb\db\migration\migration
017  {
018      /** @var string YouTube URLs matcher: handle or custom URL or channel URL */
019      protected $youtube_url_matcher = '(@[a-zA-Z0-9_.-]{3,30}|c/[a-zA-Z][\w\.,\-_]+|(channel|user)/[a-zA-Z][\w\.,\-_]+)';
020   
021      public static function depends_on(): array
022      {
023          return [
024              '\phpbb\db\migration\data\v33x\v3310',
025              '\phpbb\db\migration\data\v33x\profilefield_youtube_update',
026          ];
027      }
028   
029      public function update_schema(): array
030      {
031          return [
032              'change_columns'    => [
033                  $this->table_prefix . 'profile_fields'            => [
034                      'field_validation'        => ['VCHAR_UNI:128', ''],
035                  ],
036              ]
037          ];
038      }
039   
040      public function revert_schema(): array
041      {
042          return [
043              'change_columns'    => [
044                  $this->table_prefix . 'profile_fields'            => [
045                      'field_validation'        => ['VCHAR_UNI:64', ''],
046                  ],
047              ]
048          ];
049      }
050   
051      public function update_data(): array
052      {
053          return [
054              ['custom', [[$this, 'update_youtube_profile_field']]],
055              ['custom', [[$this, 'update_other_profile_fields']]],
056          ];
057      }
058   
059      public function revert_data(): array
060      {
061          return [
062              ['custom', [[$this, 'revert_youtube_profile_field']]],
063              ['custom', [[$this, 'revert_other_profile_fields']]],
064          ];
065      }
066   
067      public function update_youtube_profile_field(): bool
068      {
069          $profile_fields = $this->table_prefix . 'profile_fields';
070          $profile_fields_data = $this->table_prefix . 'profile_fields_data';
071          $end_time = time() + 5; // allow up to 5 seconds for migration to run
072   
073          $field_data = [
074              'field_length'            => 20,
075              'field_minlen'            => 3,
076              'field_maxlen'            => 60,
077              'field_validation'        => $this->youtube_url_matcher,
078              'field_contact_url'        => 'https://youtube.com/%s',
079              'field_contact_desc'    => 'VIEW_YOUTUBE_PROFILE',
080          ];
081   
082          $sql = 'UPDATE ' . $profile_fields . '
083              SET ' . $this->db->sql_build_array('UPDATE', $field_data) . "
084              WHERE field_name = 'phpbb_youtube'";
085          $this->db->sql_query($sql);
086   
087          $yt_profile_field = 'pf_phpbb_youtube';
088          $has_youtube_url = $this->db->sql_like_expression($this->db->get_any_char() . 'youtube.com/' . $this->db->get_any_char());
089   
090          // We're done if the profile field doesn't exist
091          if (!$this->db_tools->sql_column_exists($profile_fields_data, $yt_profile_field))
092          {
093              return true;
094          }
095   
096          $update_aborted = false;
097   
098          $sql = 'SELECT user_id, pf_phpbb_youtube
099              FROM ' . $profile_fields_data . "
100              WHERE $yt_profile_field <> ''
101                  AND $yt_profile_field $has_youtube_url";
102          $result = $this->db->sql_query($sql);
103          while ($row = $this->db->sql_fetchrow($result))
104          {
105              $updated_youtube_url_part = $this->get_youtube_url_part($row['pf_phpbb_youtube']);
106              if ($updated_youtube_url_part != $row['pf_phpbb_youtube'])
107              {
108                  $this->db->sql_query(
109                      "UPDATE $profile_fields_data
110                      SET $yt_profile_field = '$updated_youtube_url_part'
111                      WHERE user_id = {$row['user_id']}"
112                  );
113              }
114   
115              if (time() > $end_time)
116              {
117                  $update_aborted = true;
118                  break;
119              }
120          }
121          $this->db->sql_freeresult($result);
122   
123          return $update_aborted != true;
124      }
125   
126      public function update_other_profile_fields(): void
127      {
128          $profile_fields = $this->table_prefix . 'profile_fields';
129   
130          $this->db->sql_query(
131              "UPDATE $profile_fields
132                  SET field_contact_url = 'https://facebook.com/%s/'
133                  WHERE field_name = 'phpbb_facebook'"
134          );
135   
136          $this->db->sql_query(
137              "UPDATE $profile_fields
138                  SET field_contact_url = 'https://twitter.com/%s'
139                  WHERE field_name = 'phpbb_twitter'"
140          );
141      }
142   
143      public function revert_youtube_profile_field(): void
144      {
145          $profile_fields = $this->table_prefix . 'profile_fields';
146          $profile_fields_data = $this->table_prefix . 'profile_fields_data';
147   
148          $field_data = [
149              'field_length'        => 40,
150              'field_minlen'        => strlen('https://youtube.com/c/') + 1,
151              'field_maxlen'        => 255,
152              'field_validation'    => profilefield_youtube_update::$youtube_url_matcher,
153              'field_contact_url'    => '%s'
154          ];
155   
156          $sql = 'UPDATE ' . $profile_fields . '
157              SET ' . $this->db->sql_build_array('UPDATE', $field_data) . "
158              WHERE field_name = 'phpbb_youtube'";
159          $this->db->sql_query($sql);
160   
161          $yt_profile_field = 'pf_phpbb_youtube';
162   
163          // We're done if the profile field doesn't exist
164          if (!$this->db_tools->sql_column_exists($profile_fields_data, $yt_profile_field))
165          {
166              return;
167          }
168   
169          $prepend_legacy_youtube_url = $this->db->sql_concatenate(
170              "'https://youtube.com/'", $yt_profile_field
171          );
172          $is_not_already_youtube_url = $this->db->sql_not_like_expression(
173              $this->db->get_any_char()
174              . 'youtube.com/'
175              . $this->db->get_any_char()
176          );
177   
178          $this->db->sql_query(
179              "UPDATE $profile_fields_data SET
180                  $yt_profile_field = $prepend_legacy_youtube_url
181                  WHERE $yt_profile_field <> ''
182                  AND $yt_profile_field $is_not_already_youtube_url"
183          );
184      }
185   
186      public function revert_other_profile_fields(): void
187      {
188          $profile_fields = $this->table_prefix . 'profile_fields';
189   
190          $this->db->sql_query(
191              "UPDATE $profile_fields
192                  SET field_contact_url = 'http://facebook.com/%s/'
193                  WHERE field_name = 'phpbb_facebook'"
194          );
195   
196          $this->db->sql_query(
197              "UPDATE $profile_fields
198                  SET field_contact_url = 'http://twitter.com/%s'
199                  WHERE field_name = 'phpbb_twitter'"
200          );
201      }
202   
203      protected function get_youtube_url_part(string $profile_field_string): string
204      {
205          return preg_replace('#^https://(?:www\.)?youtube\.com/(.+)$#iu', '$1', $profile_field_string);
206      }
207  }
208