1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
8
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\Message; |
10
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
11
|
|
|
use Doctrine\DBAL\Schema\Schema; |
12
|
|
|
|
13
|
|
|
final class Version20200821224244 extends AbstractMigrationChamilo |
14
|
|
|
{ |
15
|
|
|
private const OLD_MESSAGE_STATUS_NEW = 0; |
16
|
|
|
private const OLD_MESSAGE_STATUS_UNREAD = 1; |
17
|
|
|
private const OLD_MESSAGE_STATUS_DELETED = 3; |
18
|
|
|
private const OLD_MESSAGE_STATUS_OUTBOX = 4; |
19
|
|
|
private const OLD_MESSAGE_STATUS_INVITATION_PENDING = 5; |
20
|
|
|
private const OLD_MESSAGE_STATUS_INVITATION_ACCEPTED = 6; |
21
|
|
|
private const OLD_MESSAGE_STATUS_INVITATION_DENIED = 7; |
22
|
|
|
private const OLD_MESSAGE_STATUS_WALL = 8; |
23
|
|
|
private const OLD_MESSAGE_STATUS_WALL_DELETE = 9; |
24
|
|
|
private const OLD_MESSAGE_STATUS_WALL_POST = 10; |
25
|
|
|
private const OLD_MESSAGE_STATUS_CONVERSATION = 11; |
26
|
|
|
private const OLD_MESSAGE_STATUS_FORUM = 12; |
27
|
|
|
private const OLD_MESSAGE_STATUS_PROMOTED = 13; |
28
|
|
|
|
29
|
|
|
public function getDescription(): string |
30
|
|
|
{ |
31
|
|
|
return 'Post Message update'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function up(Schema $schema): void |
35
|
|
|
{ |
36
|
|
|
$result = $this->connection->executeQuery('SELECT * FROM message WHERE user_receiver_id IS NOT NULL'); |
37
|
|
|
$messages = $result->fetchAllAssociative(); |
38
|
|
|
|
39
|
|
|
if ($messages) { |
40
|
|
|
foreach ($messages as $message) { |
41
|
|
|
$messageId = (int) $message['id']; |
42
|
|
|
$receiverId = (int) $message['user_receiver_id']; |
43
|
|
|
|
44
|
|
|
$result = $this->connection->executeQuery(" SELECT * FROM message_rel_user WHERE message_id = $messageId AND user_id = $receiverId"); |
45
|
|
|
$exists = $result->fetchAllAssociative(); |
46
|
|
|
|
47
|
|
|
if (empty($exists)) { |
48
|
|
|
$sql = "INSERT INTO message_rel_user (message_id, user_id, msg_read, starred, receiver_type) VALUES('$messageId', '$receiverId', 1, 0, 1) "; |
49
|
|
|
$this->addSql($sql); |
50
|
|
|
} |
51
|
|
|
// $this->addSql("UPDATE message SET user_receiver_id = NULL WHERE id = $messageId"); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$tblMessage = $schema->getTable('message'); |
56
|
|
|
|
57
|
|
|
if ($tblMessage->hasIndex('idx_message_user_receiver')) { |
58
|
|
|
$this->addSql('DROP INDEX idx_message_user_receiver ON message'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($tblMessage->hasColumn('user_receiver_id')) { |
62
|
|
|
$this->addSql('ALTER TABLE message DROP user_receiver_id'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$newTypeQueries = []; |
66
|
|
|
|
67
|
|
|
$newTypeQueries[] = sprintf( |
68
|
|
|
'UPDATE message SET status = %d WHERE msg_type = %d', |
69
|
|
|
Message::MESSAGE_STATUS_DELETED, |
70
|
|
|
self::OLD_MESSAGE_STATUS_DELETED |
71
|
|
|
); |
72
|
|
|
$newTypeQueries[] = sprintf( |
73
|
|
|
'UPDATE message SET msg_type = %d WHERE msg_type = %d', |
74
|
|
|
Message::MESSAGE_TYPE_INBOX, |
75
|
|
|
self::OLD_MESSAGE_STATUS_OUTBOX |
76
|
|
|
); |
77
|
|
|
$newTypeQueries[] = sprintf( |
78
|
|
|
'UPDATE message SET msg_type = %d WHERE msg_type = %d', |
79
|
|
|
Message::MESSAGE_TYPE_CONVERSATION, |
80
|
|
|
self::OLD_MESSAGE_STATUS_CONVERSATION |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$newTypeQueries[] = sprintf( |
84
|
|
|
'UPDATE message SET status = %d WHERE msg_type = %d', |
85
|
|
|
Message::MESSAGE_STATUS_INVITATION_PENDING, |
86
|
|
|
self::OLD_MESSAGE_STATUS_INVITATION_PENDING |
87
|
|
|
); |
88
|
|
|
$newTypeQueries[] = sprintf( |
89
|
|
|
'UPDATE message SET status = %d WHERE msg_type = %d', |
90
|
|
|
Message::MESSAGE_STATUS_INVITATION_ACCEPTED, |
91
|
|
|
self::OLD_MESSAGE_STATUS_INVITATION_ACCEPTED |
92
|
|
|
); |
93
|
|
|
$newTypeQueries[] = sprintf( |
94
|
|
|
'UPDATE message SET status = %d WHERE msg_type = %d', |
95
|
|
|
Message::MESSAGE_STATUS_INVITATION_DENIED, |
96
|
|
|
self::OLD_MESSAGE_STATUS_INVITATION_DENIED |
97
|
|
|
); |
98
|
|
|
$newTypeQueries[] = sprintf( |
99
|
|
|
'UPDATE message SET msg_type = %d WHERE status IN (%d, %d, %d)', |
100
|
|
|
Message::MESSAGE_TYPE_INVITATION, |
101
|
|
|
Message::MESSAGE_STATUS_INVITATION_PENDING, |
102
|
|
|
Message::MESSAGE_STATUS_INVITATION_ACCEPTED, |
103
|
|
|
Message::MESSAGE_STATUS_INVITATION_DENIED |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$newTypeQueries[] = sprintf( |
107
|
|
|
'UPDATE message SET msg_type = %d WHERE msg_type = %d', |
108
|
|
|
Message::MESSAGE_TYPE_INBOX, |
109
|
|
|
self::OLD_MESSAGE_STATUS_NEW |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$newTypeQueries[] = sprintf( |
113
|
|
|
'UPDATE message SET msg_type = %d WHERE group_id IS NOT NULL', |
114
|
|
|
Message::MESSAGE_TYPE_GROUP |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
foreach ($newTypeQueries as $sql) { |
118
|
|
|
$this->addSql($sql); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function down(Schema $schema): void {} |
123
|
|
|
} |
124
|
|
|
|