Total Complexity | 3 |
Total Lines | 45 |
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 Drupal database configuration |
||
15 | :param client: String |
||
16 | :return: |
||
17 | """ |
||
18 | _path = system.config[client]['path'] |
||
19 | |||
20 | _db_config = { |
||
21 | 'name': get_database_setting(client, 'DB_NAME', system.config[client]['path']), |
||
22 | 'host': get_database_setting(client, 'DB_HOST', system.config[client]['path']), |
||
23 | 'password': get_database_setting(client, 'DB_PASSWORD', system.config[client]['path']), |
||
24 | 'port': get_database_setting(client, 'DB_PORT', system.config[client]['path']) if get_database_setting(client, 'DB_PORT', system.config[client]['path']) != '' else 3306, |
||
25 | 'user': get_database_setting(client, 'DB_USER', system.config[client]['path']), |
||
26 | } |
||
27 | |||
28 | system.config[client]['db'] = _db_config |
||
29 | |||
30 | |||
31 | def get_database_setting(client, name, file): |
||
32 | """ |
||
33 | Parsing a single database variable from the wp-config.php file |
||
34 | https://stackoverflow.com/questions/63493645/extract-database-name-from-a-wp-config-php-file |
||
35 | :param client: String |
||
36 | :param name: String |
||
37 | :param file: String |
||
38 | :return: |
||
39 | """ |
||
40 | return mode.run_command( |
||
41 | helper.get_command(client, 'sed') + f' -n "s/define( *\'{name}\', *\'\([^\']*\)\'.*/\\1/p" {file}', |
||
42 | client, |
||
43 | True |
||
44 | ).replace('\n', '') |
||
45 | |||
46 |