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

merge_duplicate_bbcodes.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 2.16 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\v32x;
15   
16  class merge_duplicate_bbcodes extends \phpbb\db\migration\container_aware_migration
17  {
18      public function update_data()
19      {
20          return [
21              ['custom', [[$this, 'update_bbcodes_table']]],
22          ];
23      }
24   
25      public function update_bbcodes_table()
26      {
27          $sql     = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline, bbcode_match, bbcode_tpl FROM ' . BBCODES_TABLE;
28          $result  = $this->sql_query($sql);
29          $bbcodes = [];
30          while ($row = $this->db->sql_fetchrow($result))
31          {
32              $variant = (substr($row['bbcode_tag'], -1) === '=') ? 'with': 'without';
33              $bbcode_name = strtolower(rtrim($row['bbcode_tag'], '='));
34              $bbcodes[$bbcode_name][$variant] = $row;
35          }
36          $this->db->sql_freeresult($result);
37   
38          foreach ($bbcodes as $bbcode_name => $variants)
39          {
40              if (count($variants) === 2)
41              {
42                  $this->merge_bbcodes($variants['without'], $variants['with']);
43              }
44          }
45      }
46   
47      protected function merge_bbcodes(array $without, array $with)
48      {
49          try
50          {
51              $merged = $this->container->get('text_formatter.s9e.bbcode_merger')->merge_bbcodes(
52                  [
53                      'usage'    => $without['bbcode_match'],
54                      'template' => $without['bbcode_tpl']
55                  ],
56                  [
57                      'usage'    => $with['bbcode_match'],
58                      'template' => $with['bbcode_tpl']
59                  ]
60              );
61          }
62          catch (\Exception $e)
63          {
64              // Ignore the pair and move on. The BBCodes would have to be fixed manually
65              return;
66          }
67   
68          $bbcode_data = [
69              'bbcode_tag'      => $without['bbcode_tag'],
70              'bbcode_helpline' => $without['bbcode_helpline'] . ' | ' . $with['bbcode_helpline'],
71              'bbcode_match'    => $merged['usage'],
72              'bbcode_tpl'      => $merged['template']
73          ];
74   
75          $sql = 'UPDATE ' . BBCODES_TABLE . '
76              SET ' . $this->db->sql_build_array('UPDATE', $bbcode_data) . '
77              WHERE bbcode_id = ' . (int) $without['bbcode_id'];
78          $this->sql_query($sql);
79   
80          $sql = 'DELETE FROM ' . BBCODES_TABLE . '
81              WHERE bbcode_id = ' . (int) $with['bbcode_id'];
82          $this->sql_query($sql);
83      }
84  }
85