Completed
Push — next ( 19838d...3cfa04 )
by Thomas
12:22 queued 06:06
created

CrowdinExport::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Oc\Translation;
4
5
use Doctrine\DBAL\Connection;
6
7
class CrowdinExport
8
{
9
    /**
10
     * @var Connection
11
     */
12
    private $connection;
13
14
    /**
15
     * @param Connection $connection
16
     */
17
    public function __construct(Connection $connection)
18
    {
19
        $this->connection = $connection;
20
    }
21
22
    public function exportTranslations()
23
    {
24
        $savePath = __DIR__ . '/../../../var/crowdin/';
25
        // Identifier;SourceString;Comment;langKey
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
        // key, source string, translation, context
27
        $select = '';
28
        $joins = '';
29
        foreach (['de', 'fr', 'nl', 'es', 'pl', 'it', 'ru'] as $languageKey) {
30
            $joins .= "\n".' LEFT JOIN sys_trans_text ' . $languageKey . ' ON ' . $languageKey . '.trans_id = source.trans_id AND ' . $languageKey . '.lang = "' . $languageKey . '" ';
31
            $select .= ', ' . $languageKey . '.text as ' . $languageKey . ' ';
32
        }
33
34
        $languageData = $this->connection->fetchAll(
35
            'SELECT source.trans_id AS identifer,
36
                    source.text AS source,
37
                    CONCAT(ref.line,\':\',ref.resource_name) AS comment
38
                    ' . $select . '
39
                 FROM sys_trans_text source
40
                 LEFT JOIN sys_trans_ref ref ON ref.trans_id = source.trans_id
41
                 ' . $joins . '
42
                 WHERE source.lang = "EN"
43
                 AND source.trans_id NOT IN (167, 171, 450, 453, 461, 465,466,470, 471, 472, 473, 604, 608, 681, 684, 699, 818, 830, 1298, 2265)
44
                 GROUP BY source.trans_id'
45
        );
46
        $csvFile = fopen($savePath . '/oc_legacy.csv', 'wb');
47
        fputcsv($csvFile, ['Identifier', 'SourceString', 'Comment', 'DE', 'FR', 'NL', 'ES', 'PL', 'IT', 'RU']);
48
        foreach ($languageData as $row) {
49
            fputcsv($csvFile, $row);
50
        }
51
        fclose($csvFile);
52
    }
53
}
54