1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
# -*- coding: future_fstrings -*- |
3
|
|
|
|
4
|
|
|
""" |
5
|
|
|
Wordpress script |
6
|
|
|
""" |
7
|
|
|
|
8
|
|
|
from db_sync_tool.utility import mode, system, helper |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def check_configuration(client): |
12
|
|
|
""" |
13
|
|
|
Checking Drupal database configuration |
14
|
|
|
:param client: String |
15
|
|
|
:return: |
16
|
|
|
""" |
17
|
|
|
_path = system.config[client]['path'] |
18
|
|
|
|
19
|
|
|
_db_config = { |
20
|
|
|
'name': get_database_setting(client, 'DB_NAME', system.config[client]['path']), |
21
|
|
|
'host': get_database_setting(client, 'DB_HOST', system.config[client]['path']), |
22
|
|
|
'password': get_database_setting(client, 'DB_PASSWORD', system.config[client]['path']), |
23
|
|
|
'port': get_database_setting(client, 'DB_PORT', system.config[client]['path']) |
24
|
|
|
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'] = helper.clean_db_config(_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') + |
42
|
|
|
f' -n "s/define( *\'{name}\', *\'\([^\']*\)\'.*/\\1/p" {file}', |
|
|
|
|
43
|
|
|
client, |
44
|
|
|
True |
45
|
|
|
).replace('\n', '') |
46
|
|
|
|