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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
notification_options_reconvert.php
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\v310;
015
016 class notification_options_reconvert extends \phpbb\db\migration\migration
017 {
018 static public function depends_on()
019 {
020 return array('\phpbb\db\migration\data\v310\notifications_schema_fix');
021 }
022
023 public function update_data()
024 {
025 return array(
026 array('custom', array(array($this, 'purge_notifications'))),
027 array('custom', array(array($this, 'convert_notifications'))),
028 );
029 }
030
031 public function purge_notifications()
032 {
033 $sql = 'DELETE FROM ' . $this->table_prefix . 'user_notifications';
034 $this->sql_query($sql);
035 }
036
037 public function convert_notifications($start)
038 {
039 $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->table_prefix . 'user_notifications');
040
041 return $this->perform_conversion($insert_buffer, $start);
042 }
043
044 /**
045 * Perform the conversion (separate for testability)
046 *
047 * @param \phpbb\db\sql_insert_buffer $insert_buffer
048 * @param int $start Start of staggering step
049 * @return mixed int start of the next step, null if the end was reached
050 */
051 public function perform_conversion(\phpbb\db\sql_insert_buffer $insert_buffer, $start)
052 {
053 $limit = 250;
054 $converted_users = 0;
055
056 $sql = 'SELECT user_id, user_notify_type, user_notify_pm
057 FROM ' . $this->table_prefix . 'users
058 ORDER BY user_id';
059 $result = $this->db->sql_query_limit($sql, $limit, $start);
060
061 while ($row = $this->db->sql_fetchrow($result))
062 {
063 $converted_users++;
064 $notification_methods = array();
065
066 // In-board notification
067 $notification_methods[] = '';
068
069 if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH)
070 {
071 $notification_methods[] = 'email';
072 }
073
074 if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH)
075 {
076 $notification_methods[] = 'jabber';
077 }
078
079 // Notifications for posts
080 foreach (array('post', 'topic') as $item_type)
081 {
082 $this->add_method_rows(
083 $insert_buffer,
084 $item_type,
085 0,
086 $row['user_id'],
087 $notification_methods
088 );
089 }
090
091 if ($row['user_notify_pm'])
092 {
093 // Notifications for private messages
094 // User either gets all methods or no method
095 $this->add_method_rows(
096 $insert_buffer,
097 'pm',
098 0,
099 $row['user_id'],
100 $notification_methods
101 );
102 }
103 }
104 $this->db->sql_freeresult($result);
105
106 $insert_buffer->flush();
107
108 if ($converted_users < $limit)
109 {
110 // No more users left, we are done...
111 return;
112 }
113
114 return $start + $limit;
115 }
116
117 /**
118 * Insert method rows to DB
119 *
120 * @param \phpbb\db\sql_insert_buffer $insert_buffer
121 * @param string $item_type
122 * @param int $item_id
123 * @param int $user_id
124 * @param string $methods
125 */
126 protected function add_method_rows(\phpbb\db\sql_insert_buffer $insert_buffer, $item_type, $item_id, $user_id, array $methods)
127 {
128 $row_base = array(
129 'item_type' => $item_type,
130 'item_id' => (int) $item_id,
131 'user_id' => (int) $user_id,
132 'notify' => 1
133 );
134
135 foreach ($methods as $method)
136 {
137 $row_base['method'] = $method;
138 $insert_buffer->insert($row_base);
139 }
140 }
141 }
142