Fix array values in Contact for contact_sub_type
This commit is contained in:
parent
3344394fbc
commit
12d094c392
26
confdump.py
26
confdump.py
@ -63,7 +63,8 @@ LOAD_TRIVIAL = ["FinancialType",
|
|||||||
"CustomGroup",
|
"CustomGroup",
|
||||||
"OptionGroup",
|
"OptionGroup",
|
||||||
"OptionValue",
|
"OptionValue",
|
||||||
"Domain",]
|
"Domain",
|
||||||
|
"Contact"]
|
||||||
|
|
||||||
# This is a payment processor we can assign contribution pages to in order for them to work.
|
# This is a payment processor we can assign contribution pages to in order for them to work.
|
||||||
# FIXME this seems to produce a non-working setup.
|
# FIXME this seems to produce a non-working setup.
|
||||||
@ -107,6 +108,10 @@ def object_to_table(instr: str) -> str:
|
|||||||
return 'civicrm_' + '_'.join([x.lower() for x in words])
|
return 'civicrm_' + '_'.join([x.lower() for x in words])
|
||||||
|
|
||||||
|
|
||||||
|
def array_to_weird_array(val: List) -> str:
|
||||||
|
return '"\x01' + ('\x01'.join([str(x) for x in val])) + '\x01"'
|
||||||
|
|
||||||
|
|
||||||
def python_value_to_sql(val: Any) -> str:
|
def python_value_to_sql(val: Any) -> str:
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
@ -119,7 +124,8 @@ def python_value_to_sql(val: Any) -> str:
|
|||||||
if (isinstance(val, (int, float, complex))):
|
if (isinstance(val, (int, float, complex))):
|
||||||
return str(val)
|
return str(val)
|
||||||
if (type(val) == list):
|
if (type(val) == list):
|
||||||
return "'{}'".format(",".join([str(v) for v in val]))
|
# weird list serialization
|
||||||
|
return "'" + ','.join([str(x) for x in val]) + "'"
|
||||||
if (type(val) == dict):
|
if (type(val) == dict):
|
||||||
return "'{}'".format(mysql.escape_string(phpserialize.dumps(val).decode()).decode())
|
return "'{}'".format(mysql.escape_string(phpserialize.dumps(val).decode()).decode())
|
||||||
return "'{}'".format(mysql.escape_string(val).decode())
|
return "'{}'".format(mysql.escape_string(val).decode())
|
||||||
@ -130,7 +136,13 @@ def dict_to_insert(table: str, objdict: Dict) -> str:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
columns = tuple(x for x in objdict.keys())
|
columns = tuple(x for x in objdict.keys())
|
||||||
values = tuple(python_value_to_sql(objdict[x]) for x in columns)
|
values = list()
|
||||||
|
for col in columns:
|
||||||
|
# any weird array we have to process here if there are others
|
||||||
|
if table == "civicrm_contact" and col == "contact_sub_type":
|
||||||
|
values.append(array_to_weird_array(objdict[col]))
|
||||||
|
else:
|
||||||
|
values.append(python_value_to_sql(objdict[col]))
|
||||||
return "REPLACE INTO {} ({}) VALUES ({});".format(table, ",".join(columns), ",".join(values))
|
return "REPLACE INTO {} ({}) VALUES ({});".format(table, ",".join(columns), ",".join(values))
|
||||||
|
|
||||||
|
|
||||||
@ -238,7 +250,6 @@ def main() -> int:
|
|||||||
print("dumping", table)
|
print("dumping", table)
|
||||||
with output.open("w") as of:
|
with output.open("w") as of:
|
||||||
of.write(json.dumps(data))
|
of.write(json.dumps(data))
|
||||||
|
|
||||||
# dump org contacts
|
# dump org contacts
|
||||||
output = args.output / ("Contact.json")
|
output = args.output / ("Contact.json")
|
||||||
data = api.get("Contact", where=[["contact_sub_type", "=", "Political_Party"]])
|
data = api.get("Contact", where=[["contact_sub_type", "=", "Political_Party"]])
|
||||||
@ -258,10 +269,9 @@ def main() -> int:
|
|||||||
cursor.execute("SET FOREIGN_KEY_CHECKS=0;")
|
cursor.execute("SET FOREIGN_KEY_CHECKS=0;")
|
||||||
|
|
||||||
query = dict_to_insert("civicrm_payment_processor", STANDIN_PAYMENT_PROCESSOR)
|
query = dict_to_insert("civicrm_payment_processor", STANDIN_PAYMENT_PROCESSOR)
|
||||||
print(query)
|
|
||||||
print(cursor.execute(query))
|
|
||||||
for table in LOAD_TRIVIAL:
|
for table in LOAD_TRIVIAL:
|
||||||
# exceptions that require extra processing
|
# exceptions that require extra processing
|
||||||
|
print(table)
|
||||||
with open((args.input / (table + ".json"))) as inf:
|
with open((args.input / (table + ".json"))) as inf:
|
||||||
indata = json.load(inf)
|
indata = json.load(inf)
|
||||||
table_name = object_to_table(table)
|
table_name = object_to_table(table)
|
||||||
@ -269,9 +279,11 @@ def main() -> int:
|
|||||||
if table == "ContributionPage":
|
if table == "ContributionPage":
|
||||||
for row in indata:
|
for row in indata:
|
||||||
row['payment_processor'] = STANDIN_PAYMENT_PROCESSOR_ID
|
row['payment_processor'] = STANDIN_PAYMENT_PROCESSOR_ID
|
||||||
|
tot = 0;
|
||||||
for row in indata:
|
for row in indata:
|
||||||
query = dict_to_insert(table_name, row)
|
query = dict_to_insert(table_name, row)
|
||||||
cursor.execute(query)
|
tot += cursor.execute(query)
|
||||||
|
print(tot)
|
||||||
|
|
||||||
# create custom field data tables
|
# create custom field data tables
|
||||||
custom_fields = defaultdict(list)
|
custom_fields = defaultdict(list)
|
||||||
|
Loading…
Reference in New Issue
Block a user