Passed
Push — master ( f7af3b...d79566 )
by Angel Fernando Quiroz
16:52 queued 14s
created

Version20200821224230::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Entity\ExtraField;
10
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
11
use Doctrine\DBAL\Exception;
12
use Doctrine\DBAL\Schema\Schema;
13
14
final class Version20200821224230 extends AbstractMigrationChamilo
15
{
16
    public const INBOX_TAGS_FILE = 'inbox_message_tags';
17
18
    public function getDescription(): string
19
    {
20
        return 'Prepare data to migrate message tags from extra fields.';
21
    }
22
23
    public function up(Schema $schema): void
24
    {
25
        $this->prepareTagsFromInboxMessages();
26
    }
27
28
    /**
29
     * @throws Exception
30
     */
31
    private function prepareTagsFromInboxMessages(): void
32
    {
33
        // Tags from inbox message
34
        $resMessageTag = $this->connection->executeQuery(
35
            "SELECT m.id AS m_id, m.user_receiver_id AS m_receiver_id, t.id AS t_id, t.tag AS t_tag
36
            FROM message m
37
            INNER JOIN extra_field_rel_tag efrt ON m.id = efrt.item_id
38
            INNER JOIN extra_field ef ON efrt.field_id = ef.id
39
            INNER JOIN tag t ON (efrt.tag_id = t.id AND ef.id = t.field_id)
40
            WHERE m.msg_status = 0
41
            AND ef.item_type = ".ExtraField::MESSAGE_TYPE." AND ef.variable = 'tags'"
42
        );
43
        $oldMessageTagInfo = $resMessageTag->fetchAllAssociative();
44
45
        $this->writeFile(self::INBOX_TAGS_FILE, serialize($oldMessageTagInfo));
46
    }
47
}