From a91879cc0857b5b3d9339108c556cd0378d3a007 Mon Sep 17 00:00:00 2001 From: naomi Date: Wed, 23 Mar 2022 17:53:50 +0000 Subject: [PATCH 1/3] fixed error in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 566af8a..3cdf66c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - Install requirements `pip install -r requirements.txt` - `cp example.env .env` - Edit `.env` and add creds for the production, test or development server you'll retrieve the data from. -- Execute dump to retrieve base data: `env $(cat example.env) python ./confdump.py dump -o mydata INSTANCEPATH` where INSTANCEPATH is something like https://crm.dev.caat.org.uk/. +- Execute dump to retrieve base data: `env $(cat .env) python ./confdump.py dump -o mydata INSTANCEPATH` where INSTANCEPATH is something like https://crm.dev.caat.org.uk/. - **IMPORTANT!!** - If you sourced the data from live, you must delete the `.env` file or delete the creds from inside it. If you leave them in it will negate the whole purpose of having this conf dump utility, which is to provide a way of creating a local site without any sensitive data. - If your civicrm is in a docker container, load data into running local instance with: `confdump.py mysql -i mydata/ -p 63306` - Otherwise use `confdump.py mysql -i mydata/ --host= --db= --user= --password=` From a3416543348d69ed0b456c2f5ff3274e83f1e0bc Mon Sep 17 00:00:00 2001 From: naomi Date: Wed, 23 Mar 2022 17:55:17 +0000 Subject: [PATCH 2/3] and another --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3cdf66c..b78ac93 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ - Edit `.env` and add creds for the production, test or development server you'll retrieve the data from. - Execute dump to retrieve base data: `env $(cat .env) python ./confdump.py dump -o mydata INSTANCEPATH` where INSTANCEPATH is something like https://crm.dev.caat.org.uk/. - **IMPORTANT!!** - If you sourced the data from live, you must delete the `.env` file or delete the creds from inside it. If you leave them in it will negate the whole purpose of having this conf dump utility, which is to provide a way of creating a local site without any sensitive data. -- If your civicrm is in a docker container, load data into running local instance with: `confdump.py mysql -i mydata/ -p 63306` +- If your civicrm is in a docker container, load data into running local instance with: `python confdump.py mysql -i mydata/ -p 63306` - Otherwise use `confdump.py mysql -i mydata/ --host= --db= --user= --password=` - Clear the cache in CiviCRM: * DOCKER: `make shell`, and then inside the shell `cd /app; ./vendor/bin/drush cc all` From 107f10f704f4358387376a8abeb1e60f969cec6c Mon Sep 17 00:00:00 2001 From: naomi Date: Wed, 23 Mar 2022 18:36:51 +0000 Subject: [PATCH 3/3] Now importing saved searches so that smart group works --- confdump.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/confdump.py b/confdump.py index 3bddcb8..e97872d 100644 --- a/confdump.py +++ b/confdump.py @@ -39,7 +39,8 @@ DUMP_TRIVIAL = ["FinancialType", "CustomGroup", "OptionGroup", "OptionValue", - "Domain"] + "Domain", + "SavedSearch"] # "ContributionPage", needs payment processors & payment_processor column formatted correctly. @@ -64,7 +65,8 @@ LOAD_TRIVIAL = ["FinancialType", "OptionGroup", "OptionValue", "Domain", - "Contact"] + "Contact", + "SavedSearch"] # 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. @@ -111,6 +113,8 @@ def object_to_table(instr: str) -> str: def array_to_weird_array(val: List) -> str: return '"\x01' + ('\x01'.join([str(x) for x in val])) + '\x01"' +def value_to_php_serialized(val: Any) -> str: + return "'{}'".format(mysql.escape_string(phpserialize.dumps(val).decode()).decode()) def python_value_to_sql(val: Any) -> str: """ @@ -127,7 +131,7 @@ def python_value_to_sql(val: Any) -> str: # weird list serialization return "'" + ','.join([str(x) for x in val]) + "'" if (type(val) == dict): - return "'{}'".format(mysql.escape_string(phpserialize.dumps(val).decode()).decode()) + return value_to_php_serialized(val) return "'{}'".format(mysql.escape_string(val).decode()) @@ -141,6 +145,8 @@ def dict_to_insert(table: str, objdict: Dict) -> str: # 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])) + elif table == "civicrm_saved_search" and col == "form_values": + values.append(value_to_php_serialized(objdict[col])) else: values.append(python_value_to_sql(objdict[col])) return "REPLACE INTO {} ({}) VALUES ({});".format(table, ",".join(columns), ",".join(values))