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

functions_database_helper.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 5.24 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  /**
015  * @ignore
016  */
017  if (!defined('IN_PHPBB'))
018  {
019      exit;
020  }
021   
022  /**
023  * Updates rows in given table from a set of values to a new value.
024  * If this results in rows violating uniqueness constraints, the duplicate
025  * rows are eliminated.
026  *
027  * The only supported table is bookmarks.
028  *
029  * @param \phpbb\db\driver\driver_interface $db Database object
030  * @param string $table Table on which to perform the update
031  * @param string $column Column whose values to change
032  * @param array $from_values An array of values that should be changed
033  * @param int $to_value The new value
034  * @return null
035  */
036  function phpbb_update_rows_avoiding_duplicates(\phpbb\db\driver\driver_interface $db, $table, $column, $from_values, $to_value)
037  {
038      $sql = "SELECT $column, user_id
039          FROM $table
040          WHERE " . $db->sql_in_set($column, $from_values);
041      $result = $db->sql_query($sql);
042   
043      $old_user_ids = array();
044      while ($row = $db->sql_fetchrow($result))
045      {
046          $old_user_ids[$row[$column]][] = (int) $row['user_id'];
047      }
048      $db->sql_freeresult($result);
049   
050      $sql = "SELECT $column, user_id
051          FROM $table
052          WHERE $column = " . (int) $to_value;
053      $result = $db->sql_query($sql);
054   
055      $new_user_ids = array();
056      while ($row = $db->sql_fetchrow($result))
057      {
058          $new_user_ids[$row[$column]][] = (int) $row['user_id'];
059      }
060      $db->sql_freeresult($result);
061   
062      $queries = array();
063      foreach ($from_values as $from_value)
064      {
065          if (!isset($old_user_ids[$from_value]))
066          {
067              continue;
068          }
069          if (empty($new_user_ids))
070          {
071              $sql = "UPDATE $table
072                  SET $column = " . (int) $to_value . "
073                  WHERE $column = '" . $db->sql_escape($from_value) . "'";
074              $queries[] = $sql;
075          }
076          else
077          {
078              $different_user_ids = array_diff($old_user_ids[$from_value], $new_user_ids[$to_value]);
079              if (!empty($different_user_ids))
080              {
081                  $sql = "UPDATE $table
082                      SET $column = " . (int) $to_value . "
083                      WHERE $column = '" . $db->sql_escape($from_value) . "'
084                      AND " . $db->sql_in_set('user_id', $different_user_ids);
085                  $queries[] = $sql;
086              }
087          }
088      }
089   
090      if (!empty($queries))
091      {
092          $db->sql_transaction('begin');
093   
094          foreach ($queries as $sql)
095          {
096              $db->sql_query($sql);
097          }
098   
099          $sql = "DELETE FROM $table
100              WHERE " . $db->sql_in_set($column, $from_values);
101          $db->sql_query($sql);
102   
103          $db->sql_transaction('commit');
104      }
105  }
106   
107  /**
108  * Updates rows in given table from a set of values to a new value.
109  * If this results in rows violating uniqueness constraints, the duplicate
110  * rows are merged respecting notify_status (0 takes precedence over 1).
111  *
112  * The only supported table is topics_watch.
113  *
114  * @param \phpbb\db\driver\driver_interface $db Database object
115  * @param string $table Table on which to perform the update
116  * @param string $column Column whose values to change
117  * @param array $from_values An array of values that should be changed
118  * @param int $to_value The new value
119  * @return null
120  */
121  function phpbb_update_rows_avoiding_duplicates_notify_status(\phpbb\db\driver\driver_interface $db, $table, $column, $from_values, $to_value)
122  {
123      $sql = "SELECT $column, user_id, notify_status
124          FROM $table
125          WHERE " . $db->sql_in_set($column, $from_values);
126      $result = $db->sql_query($sql);
127   
128      $old_user_ids = array();
129      while ($row = $db->sql_fetchrow($result))
130      {
131          $old_user_ids[(int) $row['notify_status']][$row[$column]][] = (int) $row['user_id'];
132      }
133      $db->sql_freeresult($result);
134   
135      $sql = "SELECT $column, user_id
136          FROM $table
137          WHERE $column = " . (int) $to_value;
138      $result = $db->sql_query($sql);
139   
140      $new_user_ids = array();
141      while ($row = $db->sql_fetchrow($result))
142      {
143          $new_user_ids[$row[$column]][] = (int) $row['user_id'];
144      }
145      $db->sql_freeresult($result);
146   
147      $queries = array();
148      $extra_updates = array(
149          0 => 'notify_status = 0',
150          1 => '',
151      );
152      foreach ($from_values as $from_value)
153      {
154          foreach ($extra_updates as $notify_status => $extra_update)
155          {
156              if (!isset($old_user_ids[$notify_status][$from_value]))
157              {
158                  continue;
159              }
160              if (empty($new_user_ids))
161              {
162                  $sql = "UPDATE $table
163                      SET $column = " . (int) $to_value . "
164                      WHERE $column = '" . $db->sql_escape($from_value) . "'";
165                  $queries[] = $sql;
166              }
167              else
168              {
169                  $different_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $new_user_ids[$to_value]);
170                  if (!empty($different_user_ids))
171                  {
172                      $sql = "UPDATE $table
173                          SET $column = " . (int) $to_value . "
174                          WHERE $column = '" . $db->sql_escape($from_value) . "'
175                          AND " . $db->sql_in_set('user_id', $different_user_ids);
176                      $queries[] = $sql;
177                  }
178   
179                  if ($extra_update)
180                  {
181                      $same_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $different_user_ids);
182                      if (!empty($same_user_ids))
183                      {
184                          $sql = "UPDATE $table
185                              SET $extra_update
186                              WHERE $column = '" . (int) $to_value . "'
187                              AND " . $db->sql_in_set('user_id', $same_user_ids);
188                          $queries[] = $sql;
189                      }
190                  }
191              }
192          }
193      }
194   
195      if (!empty($queries))
196      {
197          $db->sql_transaction('begin');
198   
199          foreach ($queries as $sql)
200          {
201              $db->sql_query($sql);
202          }
203   
204          $sql = "DELETE FROM $table
205              WHERE " . $db->sql_in_set($column, $from_values);
206          $db->sql_query($sql);
207   
208          $db->sql_transaction('commit');
209      }
210  }
211