Created
March 21, 2022 20:03
-
-
Save kbcarte/86d2f27f9aa5f547e1aaec709c2411f4 to your computer and use it in GitHub Desktop.
Python Removes the old "[vc_]" shortcodes found in the db during migrations. If other shortcodes not specific to vc_* are preset, the regex pattern will need to be updated.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python script to find-replace an exported DB | |
# For use when the php version timeout's or exceeding memory limits | |
# export db you want to update, rename it to backup.sql | |
# place backup in same dir as this script | |
# run script | |
# import the out.sql file | |
import re | |
from pprint import pprint | |
pattern = r'\[/?(vc_.*?)\]' | |
db = None | |
# Assumes there is a sql file called "backup" in this dir | |
with open('backup.sql', 'r') as sql: | |
db = sql.read() | |
match = re.findall(pattern, db) | |
print(f"Found: {len(match)} matching shortcodes") | |
print("Running Replace") | |
res = re.sub(pattern, '', db) | |
with open('out.sql', 'w') as sql: | |
print("Writing new db") | |
sql.write(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment