-
Notifications
You must be signed in to change notification settings - Fork 27
/
m11_notification_type_update.php
87 lines (79 loc) · 2.18 KB
/
m11_notification_type_update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
*
* Board Rules extension for the phpBB Forum Software package.
*
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbb\boardrules\migrations\v10x;
/**
* Migration stage 11: Update the notification type to the new service name
*/
class m11_notification_type_update extends \phpbb\db\migration\migration
{
/**
* Check if an updated boardrules notification type already exists
*
* @return bool True if notification type exists, false otherwise
* @access public
*/
public function effectively_installed()
{
$sql = 'SELECT * FROM ' . $this->table_prefix . "notification_types
WHERE notification_type_name = 'phpbb.boardrules.notification.type.boardrules'";
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
return $row !== false;
}
/**
* Assign migration file dependencies for this migration
*
* @return array Array of migration files
* @static
* @access public
*/
public static function depends_on()
{
return array(
'\phpbb\boardrules\migrations\v10x\m10_notification_counter',
'\phpbb\db\migration\data\v310\notifications_use_full_name',
);
}
/**
* Add or update data in the database
*
* @return array Array of table data
* @access public
*/
public function update_data()
{
return array(
array('custom', array(array($this, 'update_notifications_name'))),
);
}
/**
* Update a boardrules notification type name and state
*
* @return void
* @access public
*/
public function update_notifications_name()
{
// New notification_type_name and re-enable
$sql_ary = array(
'notification_type_name' => 'phpbb.boardrules.notification.type.boardrules',
'notification_type_enabled' => 1,
);
$sql = 'UPDATE ' . NOTIFICATION_TYPES_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "
WHERE notification_type_name = 'boardrules'";
$this->db->sql_query($sql);
$sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . "
SET item_type = '" . $this->db->sql_escape($sql_ary['notification_type_name']) . "'
WHERE item_type = 'boardrules'";
$this->db->sql_query($sql);
}
}