Forked from hn-support/change_magento1_base_urls_to_https.py
Created
August 23, 2018 20:20
-
-
Save jbelke/5ed976abc8b723cb555ee0cf01dbe2b8 to your computer and use it in GitHub Desktop.
Change all base_urls of your Magento 1 live shop to https on hypernode
This file contains hidden or 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
| #!/usr/bin/env python | |
| """ | |
| Set the base-urls for your Magento 1 installation to support only https. | |
| To use, download the file and make it executable. Then run: | |
| ./change_magento1_base_urls_to_https.py | |
| After use, check your base-urls by issuing: | |
| n98-magerun sys:store:config:base-url:list | |
| This script requires n98-magerun. | |
| """ | |
| import json | |
| import subprocess | |
| import os | |
| import sys | |
| from urlparse import urlsplit | |
| def securify(url): | |
| url = urlsplit(url) | |
| return "https://{}/".format(url.netloc) | |
| def set_base_url(data, store_type): | |
| scope_id = data['Scope-ID'] | |
| scope = data['Scope'] | |
| path = data['Path'] | |
| value = securify(data['Value']) | |
| command = '/usr/local/bin/n98-magerun --root-dir=/data/web/public config:set --scope="{}" --scope-id="{}" "{}" "{}"'.format(scope, scope_id, path, value) | |
| subprocess.check_output(command, shell=True) | |
| def main(): | |
| if not os.path.isfile('/data/web/public/app/Mage.php'): | |
| print >>sys.stderr, "No magento 1 installation found in /data/web/public" | |
| sys.exit(1) | |
| for store_type, store_front in ('unsecure', 'web/unsecure/base_url'), ('secure', 'web/secure/base_url'): | |
| command = '/usr/local/bin/n98-magerun --root-dir=/data/web/public config:get "{}" --format=json'.format(store_front) | |
| magerun_json = subprocess.check_output(command, shell=True) | |
| magerun_dict = json.loads(magerun_json) | |
| for value in magerun_dict.values(): | |
| set_base_url(data=value, store_type=store_type) | |
| subprocess.check_output('/usr/local/bin/n98-magerun --root-dir=/data/web/public cache:flush', shell=True) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment