Total Complexity | 4 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
|
|||
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | import json |
||
5 | import os |
||
6 | import sys |
||
7 | from subprocess import check_output |
||
8 | |||
9 | from db_sync_tool.utility import mode, system, helper, output |
||
10 | |||
11 | |||
12 | def check_configuration(client): |
||
13 | """ |
||
14 | Checking remote TYPO3 database configuration |
||
15 | :param client: String |
||
16 | :return: |
||
17 | """ |
||
18 | _path = system.config[client]['path'] |
||
19 | |||
20 | stdout = mode.run_command( |
||
21 | helper.get_command(client, 'php') + ' -r "echo json_encode(include \'' + system.config[client][ |
||
22 | 'path'] + '\');"', |
||
23 | client, |
||
24 | True |
||
25 | ) |
||
26 | |||
27 | _db_config = parse_database_credentials(json.loads(stdout)['DB']) |
||
28 | |||
29 | system.config[client]['db'] = _db_config |
||
30 | |||
31 | |||
32 | def parse_database_credentials(db_credentials): |
||
33 | """ |
||
34 | Parsing database credentials to needed format |
||
35 | :param db_credentials: Dictionary |
||
36 | :return: Dictionary |
||
37 | """ |
||
38 | # |
||
39 | # Distinguish between database config scheme of TYPO3 v8+ and TYPO3 v7- |
||
40 | # |
||
41 | if 'Connections' in db_credentials: |
||
42 | _db_config = db_credentials['Connections']['Default'] |
||
43 | _db_config['name'] = _db_config['dbname'] |
||
44 | else: |
||
45 | _db_config = db_credentials |
||
46 | _db_config['user'] = _db_config['username'] |
||
47 | _db_config['name'] = _db_config['database'] |
||
48 | |||
49 | if 'port' not in _db_config: |
||
50 | _db_config['port'] = 3306 |
||
51 | |||
52 | return _db_config |
||
53 |