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

profilefield_youtube_update.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 2.28 KiB


01  <?php
02  /**
03  *
04  * This file is part of the phpBB Forum Software package.
05  *
06  * @copyright (c) phpBB Limited <https://www.phpbb.com>
07  * @license GNU General Public License, version 2 (GPL-2.0)
08  *
09  * 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 profilefield_youtube_update extends \phpbb\db\migration\migration
17  {
18      public static $youtube_url_matcher = 'https:\\/\\/(www\\.)?youtube\\.com\\/.+';
19   
20      public function effectively_installed()
21      {
22          $profile_fields = $this->table_prefix . 'profile_fields';
23   
24          $result = $this->db->sql_query(
25              "SELECT field_validation
26                  FROM $profile_fields
27                  WHERE field_name = 'phpbb_youtube'"
28          );
29   
30          $row = $this->db->sql_fetchrow($result);
31          $this->db->sql_freeresult($result);
32   
33          return !$row || $row['field_validation'] === self::$youtube_url_matcher;
34      }
35   
36      public static function depends_on()
37      {
38          return ['\phpbb\db\migration\data\v33x\v337'];
39      }
40   
41      public function update_data()
42      {
43          return [['custom', [[$this, 'update_youtube_profile_field']]]];
44      }
45   
46      public function update_youtube_profile_field()
47      {
48          $profile_fields = $this->table_prefix . 'profile_fields';
49          $profile_fields_data = $this->table_prefix . 'profile_fields_data';
50   
51          $field_data = [
52              'field_length'        => 40,
53              'field_minlen'        => strlen('https://youtube.com/c/') + 1,
54              'field_maxlen'        => 255,
55              'field_validation'    => self::$youtube_url_matcher,
56              'field_contact_url'    => '%s'
57          ];
58   
59          $sql = 'UPDATE ' . $profile_fields . '
60              SET ' . $this->db->sql_build_array('UPDATE', $field_data) . "
61              WHERE field_name = 'phpbb_youtube'";
62          $this->db->sql_query($sql);
63   
64          $yt_profile_field = 'pf_phpbb_youtube';
65          $prepend_legacy_youtube_url = $this->db->sql_concatenate(
66              "'https://youtube.com/user/'", $yt_profile_field
67          );
68          $is_not_already_youtube_url = $this->db->sql_not_like_expression(
69              $this->db->get_any_char()
70                  . 'youtube.com/'
71                  . $this->db->get_any_char()
72          );
73   
74          // We're done if the profile field doesn't exist
75          if (!$this->db_tools->sql_column_exists($profile_fields_data, $yt_profile_field))
76          {
77              return;
78          }
79   
80          $this->db->sql_query(
81              "UPDATE $profile_fields_data SET
82                  $yt_profile_field = $prepend_legacy_youtube_url
83                  WHERE $yt_profile_field <> ''
84                  AND $yt_profile_field $is_not_already_youtube_url"
85          );
86      }
87  }
88