diff --git a/.gitignore b/.gitignore index 8092570faac..3cc4a24cd53 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.vagrant /.idea -/log/debug.log +/log/*.log /scripts/.current_nesting_level -.DS_Store \ No newline at end of file +/scripts/.current_log_path +.DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md index a8b0010f34a..cfe2994e99b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,10 +25,13 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added + - Added ability to configure number of CPUs for virtual machine via [etc/config.yaml](etc/config.yaml.dist) + - Added generation of basic sample data for testing purposes + - Ability to upgrade Magento using `m-switch-to-ce` and `m-switch-to-ee` (when `-u` flag is specified) - Redis support for Magento caching - - Access to Magento developer mode and storefront/admin UI debugging features via [etc/config.yaml.dist](etc/config.yaml.dist) + - Access to Magento developer mode and storefront/admin UI debugging features via [etc/config.yaml](etc/config.yaml.dist) - Composer-based installation support - - Magento cache warming up after re-install and clearing cache + - Magento cache warming up after re-install and clearing cache (when `-w` flag is specified) - Tests configuration files are generated during project initialization - Sample data support - ElasticSearch support @@ -40,7 +43,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Removed requirement for public github token due to Composer limitations (issue is fixed on Composer side) - Changed requirement for minimum box version from 1.0 to 1.1 - Upgraded PHP 5.5.9 to PHP 5.6 - - When [init_project.sh](init_project.sh) is executed, EE will be installed by default, if EE repository is specified in [etc/config.yaml.dist](etc/config.yaml.dist). Not supported on Windows hosts + - When [init_project.sh](init_project.sh) is executed, EE will be installed by default, if EE repository is specified in [etc/config.yaml](etc/config.yaml.dist). Not supported on Windows hosts ### Fixed @@ -65,7 +68,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Moved provisioning scripts - Magento project directory moved to vagrant project root. Current structure is as follows: `vagrant-magento/magento2ce/magento2ee` - - PHP 7.0 is installed by default instead of PHP 5.5.9 (can be configured in [etc/config.yaml.dist](etc/config.yaml.dist)) + - PHP 7.0 is installed by default instead of PHP 5.5.9 (can be configured in [etc/config.yaml](etc/config.yaml.dist)) - Renamed configuration folder from `local.config` to `etc` - Set minimum Vagrant version as 1.8 - Improved deployment speed in case of disabled NFS for folders sync @@ -78,7 +81,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added [project initialization script](init_project.sh) and host scripts for routine flows (compatible with OSX, *nix and Windows) - Implemented static value of forwarded SSH port to prevent necessity to reconfigure software accessing guest via SSH - Implemented collision prevention for IP address and host name (in case when several machines are created at once) - - Configuration file [etc/config.yaml.dist](etc/config.yaml.dist) + - Configuration file [etc/config.yaml](etc/config.yaml.dist) - PHP 7.0 support - PHP Storm configuration during project initialization (particularly automatic deployment settings) - Automatic vagrant plugins installation diff --git a/README.md b/README.md index c00ac322941..ae19e9e7ac7 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ * [Connecting to MySQL DB](#connecting-to-mysql-db) * [View emails sent by Magento](#view-emails-sent-by-magento) * [Accessing PHP and other config files](#accessing-php-and-other-config-files) + * [Upgrading Magento](#upgrading-magento) * [Multiple Magento instances](#multiple-magento-instances) * [Update Composer dependencies](#update-composer-dependencies) * [Environment configuration](#environment-configuration) @@ -139,10 +140,12 @@ Note, that semantic versioning is only used for `x.0` branches (not for `develop ## Day-to-day development scenarios ### Reinstall Magento -To save some time and get clear Magento installation, you can skip installation of software like web server or php. -The following command will clear Magento DB, Magento caches and reinstall Magento instance. -Go to 'vagrant-magento' created earlier and run in command line: +Use commands described in [Switch between CE and EE](#switch-between-ce-and-ee) section with `-f` flag. Before doing actual re-installation, these commands update linking of EE codebase, clear cache, update composer dependencies. + +If no composer update and relinking of EE codebase is necessary, use the following command. It will clear Magento DB, Magento caches and reinstall Magento instance. + +Go to the root of vagrant project in command line and execute: ``` bash m-reinstall @@ -150,7 +153,7 @@ bash m-reinstall ### Clear Magento cache -Go to 'vagrant-magento' created earlier and run in command line: +Go to the root of vagrant project in command line and execute: ``` bash m-clear-cache @@ -170,6 +173,8 @@ bash m-switch-to-ee Force switch can be done using `-f` flag even if already switched to the target edition. May be helpful to relink EE modules after switching between branches. +Upgrade can be performed instead of re-installation using `-u` flag. + :information_source: On Windows hosts (or when NFS mode is disabled in [config.yaml](etc/config.yaml.dist) explicitly) you will be asked to wait until code is uploaded to guest machine by PhpStorm (PhpStorm must be launched). To continue the process press any key. ### Sample data installation @@ -226,6 +231,13 @@ Do not edit any symlinks using PhpStorm because it may break your installation. After editing configs in IDE it is still required to restart related services manually. +### Upgrading Magento + +Sometimes it is necessary to test upgrade flow. This can be easily done as follows (assuming that you have installed instance): + + - For git-based installation - check out codebase corresponding to the target Magento version. Or modify your `composer.json` in case of composer-based installation + - Use commands described in [Switch between CE and EE](#switch-between-ce-and-ee) section with `-u` flag + ### Multiple Magento instances To install several Magento instances based on different code bases, just follow [Installation steps](#installation-steps) to initialize project in another directory on the host. diff --git a/Vagrantfile b/Vagrantfile index 5e809b04cd4..b3487333f18 100755 --- a/Vagrantfile +++ b/Vagrantfile @@ -20,7 +20,7 @@ module Config config_data_dist = YAML.load_file(config_dist_file) config_data = File.exists?(config_file) ? YAML.load_file(config_file) : {} - return config_data_dist.merge!(config_data) + return config_data_dist.deep_merge!(config_data) end end @@ -30,6 +30,7 @@ magento_host_name = config_data['magento']['host_name'] magento_ip_address = config_data['guest']['ip_address'] forwarded_ssh_port = config_data['guest']['forwarded_ssh_port'] guest_memory = config_data['guest']['memory'] +guest_cpus = config_data['guest']['cpus'] # NFS will be used for *nix and OSX hosts, if not disabled explicitly in config use_nfs_for_synced_folders = !OS.is_windows && (config_data['guest']['use_nfs'] == 1) @@ -44,6 +45,7 @@ Vagrant.configure(VAGRANT_API_VERSION) do |config| config.vm.provider "virtualbox" do |vb| vb.memory = guest_memory + vb.cpus = guest_cpus # Uncomment option below to avoid issues with VirtualBox on Windows 10 # vb.gui=true end diff --git a/etc/config.yaml.dist b/etc/config.yaml.dist index 506f17eb9ce..1291f18efa9 100644 --- a/etc/config.yaml.dist +++ b/etc/config.yaml.dist @@ -27,6 +27,8 @@ guest: use_nfs: 1 # [To apply changes: vagrant reload] Default is 2Gb, around 3Gb is necessary to run functional tests. memory: 2048 + # Recommended number of CPUs is 2 + cpus: 1 ip_address: "192.168.10.2" forwarded_ssh_port: 3000 diff --git a/init_project.sh b/init_project.sh index 01c8de4b03f..de9b3ce2ff3 100755 --- a/init_project.sh +++ b/init_project.sh @@ -6,6 +6,8 @@ vagrant_dir=$PWD source "${vagrant_dir}/scripts/output_functions.sh" resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" if [[ ${debug_vagrant_project} -eq 1 ]]; then @@ -240,4 +242,4 @@ if [[ ${host_os} == "Windows" ]] || [[ ${use_nfs} == 0 ]]; then If not using PhpStorm, you can set up synchronization using rsync" fi -info "See detailed log in '${vagrant_dir}/log/debug.log'. For even more details you can set debug:vagrant_project to 1 in config.yaml" +info "See detailed log in '${vagrant_dir}/log/${current_script_name}.log'. For even more details you can set debug:vagrant_project to 1 in config.yaml" diff --git a/m-bin-magento b/m-bin-magento index 2c06528e1b4..e5fc3d29cd4 100755 --- a/m-bin-magento +++ b/m-bin-magento @@ -6,6 +6,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD source "${vagrant_dir}/scripts/output_functions.sh" resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" if [[ ${debug_vagrant_project} -eq 1 ]]; then @@ -18,4 +20,4 @@ vagrant ssh -c "\$MAGENTO_ROOT/bin/magento $arguments" 2> >(logError) # To debug, comment out line above and uncomment line below # vagrant ssh -c "php -d xdebug.remote_autostart=1 \$MAGENTO_ROOT/bin/magento $arguments" 2> >(logError) -info "See detailed log in '${vagrant_dir}/log/debug.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" +info "See detailed log in '${vagrant_dir}/log/${current_script_name}.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" diff --git a/m-clear-cache b/m-clear-cache index df682106591..8a6ecf78abe 100755 --- a/m-clear-cache +++ b/m-clear-cache @@ -6,6 +6,16 @@ cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD source "${vagrant_dir}/scripts/output_functions.sh" resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} + +warm_up_cache=0 +while getopts 'w' flag; do + case "${flag}" in + w) warm_up_cache=1 ;; + *) error "Unexpected option" && exit 1;; + esac +done debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" if [[ ${debug_vagrant_project} -eq 1 ]]; then @@ -14,10 +24,12 @@ fi bash "${vagrant_dir}/scripts/host/m_clear_cache.sh" "$@" 2> >(logError) -incrementNestingLevel - -bash "${vagrant_dir}/scripts/host/warm_up_cache.sh" 2> >(logError) - -decrementNestingLevel +if [[ ${warm_up_cache} -eq 1 ]]; then + incrementNestingLevel + bash "${vagrant_dir}/scripts/host/warm_up_cache.sh" 2> >(logError) + decrementNestingLevel +else + info "Use 'bash ./m-clear-cache -w' to get automatic cache warm up" +fi -info "See detailed log in '${vagrant_dir}/log/debug.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" +info "See detailed log in '${vagrant_dir}/log/${current_script_name}.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" diff --git a/m-composer b/m-composer index 515b78cd0ac..470d42b65e0 100755 --- a/m-composer +++ b/m-composer @@ -6,6 +6,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD source "${vagrant_dir}/scripts/output_functions.sh" resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" if [[ ${debug_vagrant_project} -eq 1 ]]; then @@ -14,4 +16,4 @@ fi bash "${vagrant_dir}/scripts/host/m_composer.sh" "$@" 2> >(logError) -info "See detailed log in '${vagrant_dir}/log/debug.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" +info "See detailed log in '${vagrant_dir}/log/${current_script_name}.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" diff --git a/m-reinstall b/m-reinstall index c3dba8612cd..36574e73007 100755 --- a/m-reinstall +++ b/m-reinstall @@ -6,6 +6,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD source "${vagrant_dir}/scripts/output_functions.sh" resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" if [[ ${debug_vagrant_project} -eq 1 ]]; then @@ -14,4 +16,4 @@ fi bash "${vagrant_dir}/scripts/host/m_reinstall.sh" "$@" 2> >(logError) -info "See detailed log in '${vagrant_dir}/log/debug.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" +info "See detailed log in '${vagrant_dir}/log/${current_script_name}.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" diff --git a/m-search-engine b/m-search-engine index 03e16cc9a27..209a4089a57 100755 --- a/m-search-engine +++ b/m-search-engine @@ -6,6 +6,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD source "${vagrant_dir}/scripts/output_functions.sh" resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" if [[ ${debug_vagrant_project} -eq 1 ]]; then @@ -15,4 +17,4 @@ fi cd "${vagrant_dir}" vagrant ssh -c "bash /vagrant/scripts/guest/m-search-engine ${@}" 2> >(logError) -info "See detailed log in '${vagrant_dir}/log/debug.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" +info "See detailed log in '${vagrant_dir}/log/${current_script_name}.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" diff --git a/m-switch-to-ce b/m-switch-to-ce index 1edb6c9001c..bc0afbcda3b 100755 --- a/m-switch-to-ce +++ b/m-switch-to-ce @@ -6,6 +6,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD source "${vagrant_dir}/scripts/output_functions.sh" resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" if [[ ${debug_vagrant_project} -eq 1 ]]; then @@ -14,4 +16,4 @@ fi bash "${vagrant_dir}/scripts/host/m_switch_to_ce.sh" "$@" 2> >(logError) -info "See detailed log in '${vagrant_dir}/log/debug.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" +info "See detailed log in '${vagrant_dir}/log/${current_script_name}.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" diff --git a/m-switch-to-ee b/m-switch-to-ee index 7a66d371b35..d4e0da7a54f 100755 --- a/m-switch-to-ee +++ b/m-switch-to-ee @@ -6,6 +6,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD source "${vagrant_dir}/scripts/output_functions.sh" resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" if [[ ${debug_vagrant_project} -eq 1 ]]; then @@ -14,4 +16,4 @@ fi bash "${vagrant_dir}/scripts/host/m_switch_to_ee.sh" "$@" 2> >(logError) -info "See detailed log in '${vagrant_dir}/log/debug.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" +info "See detailed log in '${vagrant_dir}/log/${current_script_name}.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" diff --git a/m-varnish b/m-varnish index 5b4c54c4f7b..30fb4ad1fee 100755 --- a/m-varnish +++ b/m-varnish @@ -6,6 +6,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD source "${vagrant_dir}/scripts/output_functions.sh" resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" if [[ ${debug_vagrant_project} -eq 1 ]]; then @@ -15,4 +17,4 @@ fi cd "${vagrant_dir}" vagrant ssh -c "bash /vagrant/scripts/guest/m-varnish ${@}" 2> >(logError) -info "See detailed log in '${vagrant_dir}/log/debug.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" +info "See detailed log in '${vagrant_dir}/log/${current_script_name}.log'. For even more details you can set 'debug:vagrant_project' to 1 in etc/config.yaml" diff --git a/scripts/colors.sh b/scripts/colors.sh index 9b6664f55b2..e0819b0f11c 100644 --- a/scripts/colors.sh +++ b/scripts/colors.sh @@ -3,55 +3,35 @@ # CLI color functions function red() { - tput setaf 1 + printf "\e[31m" } function bold() { - tput bold + printf "\e[1m" } function green() { - tput setaf 2 + printf "\e[32m" } function yellow() { - tput setaf 3 -} - -function yellow_background() -{ - tput setab 3 + printf "\e[33m" } function blue() { - tput setaf 4 -} - -function magenta() -{ - tput setaf 5 -} - -function cyan() -{ - tput setaf 6 + printf "\e[34m" } function grey() { - tput setaf 7 -} - -function grey_background() -{ - tput setab 7 + printf "\e[37m" } function regular() { - tput sgr0 + printf "\e[m" } diff --git a/scripts/guest/generate_sample_data b/scripts/guest/generate_sample_data new file mode 100755 index 00000000000..8efa864875f --- /dev/null +++ b/scripts/guest/generate_sample_data @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +vagrant_dir="/vagrant" + +source "${vagrant_dir}/scripts/output_functions.sh" + +host_name="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_host_name")" + +status "Generating sample data" + +incrementNestingLevel + +adminToken=$(curl -sb -X POST "http://${host_name}/rest/V1/integration/admin/token" \ + -H "Content-Type:application/json" \ + -d '{"username":"admin", "password":"123123q"}') +adminToken=$(echo ${adminToken} | sed -e 's/"//g') + +category_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/categories" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "category": { + "parentId": 2, + "name": "Test Category", + "isActive": true, + "includeInMenu": true + } + }') + +pattern='\{\"id\":([0-9]+),' +if [[ "${category_creation_response}" =~ ${pattern} ]]; then + category_id=${BASH_REMATCH[1]} +fi + +product_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "sku": "testSimpleProduct", + "name": "Test Simple Product", + "attribute_set_id": 4, + "price": 22, + "status": 1, + "visibility": 4, + "type_id": "simple", + "extension_attributes": { + "stock_item": { + "qty": 12345, + "is_in_stock": true + } + }, + "custom_attributes": [ + { + "attribute_code": "category_ids", + "value": [ + "'"${category_id}"'" + ] + } + ] + } + }') + +customer_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/customers" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "customer": { + "group_id":1, + "email":"customer@example.com", + "firstname":"FirstName", + "lastname":"LastName", + "store_id":1, + "addresses":[], + "disable_auto_group_change": 0 + }, + "password": "123123qQ" + }') + +decrementNestingLevel diff --git a/scripts/guest/m-clear-cache b/scripts/guest/m-clear-cache index 6414e52e46d..e5d9bb4f98b 100755 --- a/scripts/guest/m-clear-cache +++ b/scripts/guest/m-clear-cache @@ -9,21 +9,33 @@ incrementNestingLevel status "Clearing directories containing temporary files" +mage_mode=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_mode") + rm -f "${MAGENTO_ROOT}/app/etc/paths.php" if [[ -d "${MAGENTO_ROOT}/var" ]]; then #clear var - cd "${MAGENTO_ROOT}" && mv var/.htaccess var_htaccess.back && rm -rf var/* var/.[^.]* + cd "${MAGENTO_ROOT}" + mv var/.htaccess var_htaccess.back + if [[ -d "${MAGENTO_ROOT}/var/generation" ]] && [[ ${mage_mode} == "production" ]]; then + mv var/generation var_generation.back + fi + rm -rf var/* var/.[^.]* if [[ -f var_htaccess.back ]]; then mv var_htaccess.back var/.htaccess fi + if [[ -d "${MAGENTO_ROOT}/var_generation.back" ]] && [[ ${mage_mode} == "production" ]]; then + mv var_generation.back var/generation + fi fi -if [[ -d "${MAGENTO_ROOT}/pub" ]]; then + +if [[ -d "${MAGENTO_ROOT}/pub" ]] && [[ ${mage_mode} != "production" ]]; then #clear pub/statics cd "${MAGENTO_ROOT}/pub" && mv static/.htaccess static_htaccess.back && rm -rf static && mkdir static if [[ -f static_htaccess.back ]]; then mv static_htaccess.back static/.htaccess fi fi + if [[ -d "${MAGENTO_ROOT}/dev" ]]; then #clear integration tests tmp cd "${MAGENTO_ROOT}/dev/tests/integration" && mv tmp/.gitignore tmp_gitignore.back && rm -rf tmp && mkdir tmp diff --git a/scripts/guest/m-reinstall b/scripts/guest/m-reinstall index 393181d5bc2..17306c01b00 100755 --- a/scripts/guest/m-reinstall +++ b/scripts/guest/m-reinstall @@ -98,6 +98,7 @@ if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then sudo chown -R vagrant:vagrant ${MAGENTO_ROOT} fi +bash generate_sample_data bash configure_search_engine bash change_magento_config_for_functional_tests diff --git a/scripts/host/m_switch_to_ce.sh b/scripts/host/m_switch_to_ce.sh index caa3d6eb5f2..574e3a776f5 100755 --- a/scripts/host/m_switch_to_ce.sh +++ b/scripts/host/m_switch_to_ce.sh @@ -15,16 +15,18 @@ host_os="$(bash "${vagrant_dir}/scripts/host/get_host_os.sh")" php_executable="$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")" checkout_source_from="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "checkout_source_from")" +force_switch=0 +upgrade_only=0 +while getopts 'fu' flag; do + case "${flag}" in + f) force_switch=1 ;; + u) upgrade_only=1 ;; + *) error "Unexpected option" && decrementNestingLevel && exit 1;; + esac +done + if [[ "${checkout_source_from}" == "git" ]]; then # Current installation is Git-based - force_switch=0 - while getopts 'f' flag; do - case "${flag}" in - f) force_switch=1 ;; - *) error "Unexpected option" && decrementNestingLevel && exit 1;; - esac - done - if [[ ! -f ${magento_ee_dir}/LICENSE_EE.txt ]]; then if [[ ${force_switch} -eq 0 ]]; then error "EE codebase is not available. Use 'm-switch-to-ce -f' to switch anyway." @@ -62,6 +64,9 @@ if [[ "${checkout_source_from}" == "git" ]]; then else # Current installation is Composer-based warning "Switching between CE and EE is not possible for composer-based installation. Falling back to reinstall" + if [[ ${upgrade_only} -eq 1 ]]; then + rm "${magento_ce_dir}/composer.lock" + fi fi bash "${vagrant_dir}/scripts/host/m_clear_cache.sh" 2> >(logError) @@ -71,6 +76,13 @@ if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config read -p "$(warning "[Action Required] Wait while Magento2 code is uploaded in PhpStorm and press any key to continue...")" -n1 -s fi -bash "${vagrant_dir}/scripts/host/m_reinstall.sh" 2> >(logError) +if [[ ${upgrade_only} -eq 1 ]]; then + cd "${vagrant_dir}" && vagrant ssh -c 'chmod a+x ${MAGENTO_ROOT}/bin/magento' 2> >(logError) + bash "${vagrant_dir}/m-bin-magento" "setup:upgrade" 2> >(logError) + bash "${vagrant_dir}/m-bin-magento" "indexer:reindex" 2> >(logError) + bash "${vagrant_dir}/m-clear-cache" 2> >(logError) +else + bash "${vagrant_dir}/scripts/host/m_reinstall.sh" 2> >(logError) +fi decrementNestingLevel diff --git a/scripts/host/m_switch_to_ee.sh b/scripts/host/m_switch_to_ee.sh index e427f3a4518..5554f7c7ea3 100755 --- a/scripts/host/m_switch_to_ee.sh +++ b/scripts/host/m_switch_to_ee.sh @@ -13,16 +13,18 @@ host_os="$(bash "${vagrant_dir}/scripts/host/get_host_os.sh")" php_executable="$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")" checkout_source_from="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "checkout_source_from")" +force_switch=0 +upgrade_only=0 +while getopts 'fu' flag; do + case "${flag}" in + f) force_switch=1 ;; + u) upgrade_only=1 ;; + *) error "Unexpected option" && decrementNestingLevel && exit 1;; + esac +done + if [[ "${checkout_source_from}" == "git" ]]; then # Current installation is Git-based - force_switch=0 - while getopts 'f' flag; do - case "${flag}" in - f) force_switch=1 ;; - *) error "Unexpected option" && decrementNestingLevel && exit 1;; - esac - done - if [[ ! -f ${magento_ee_dir}/LICENSE_EE.txt ]]; then error "EE codebase is not available." decrementNestingLevel @@ -57,17 +59,29 @@ if [[ "${checkout_source_from}" == "git" ]]; then else # Current installation is Composer-based warning "Switching between CE and EE is not possible for composer-based installation. Falling back to reinstall" + if [[ ${upgrade_only} -eq 1 ]]; then + rm "${magento_ce_dir}/composer.lock" + fi fi bash "${vagrant_dir}/scripts/host/m_clear_cache.sh" 2> >(logError) bash "${vagrant_dir}/scripts/host/m_composer.sh" install 2> >(logError) -cd ${magento_ce_dir} && git checkout composer.lock 2> >(logError) > >(log) +if [[ "${checkout_source_from}" == "git" ]]; then + cd ${magento_ce_dir} && git checkout composer.lock 2> >(logError) > >(log) +fi if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs") == 0 ]]; then read -p "$(warning "[Action Required] Wait while Magento2 code is uploaded in PhpStorm and press any key to continue...")" -n1 -s fi -bash "${vagrant_dir}/scripts/host/m_reinstall.sh" 2> >(logError) +if [[ ${upgrade_only} -eq 1 ]]; then + cd "${vagrant_dir}" && vagrant ssh -c 'chmod a+x ${MAGENTO_ROOT}/bin/magento' 2> >(logError) + bash "${vagrant_dir}/m-bin-magento" "setup:upgrade" 2> >(logError) + bash "${vagrant_dir}/m-bin-magento" "indexer:reindex" 2> >(logError) + bash "${vagrant_dir}/m-clear-cache" 2> >(logError) +else + bash "${vagrant_dir}/scripts/host/m_reinstall.sh" 2> >(logError) +fi decrementNestingLevel diff --git a/scripts/output_functions.sh b/scripts/output_functions.sh index fec0e12e355..cb5ad9c77f4 100644 --- a/scripts/output_functions.sh +++ b/scripts/output_functions.sh @@ -4,7 +4,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")/.." && vagrant_dir=$PWD source "${vagrant_dir}/scripts/colors.sh" -log_file="${vagrant_dir}/log/debug.log" +default_log="${vagrant_dir}/log/debug.log" +log_file_path="${vagrant_dir}/scripts/.current_log_path" nesting_level_file="${vagrant_dir}/scripts/.current_nesting_level" function info() { @@ -53,6 +54,11 @@ function log() { input="$(cat)" fi if [[ -n "${input}" ]]; then + if [[ -f "${log_file_path}" ]]; then + log_file="${vagrant_dir}/$(cat "${log_file_path}")" + else + log_file="${default_log}" + fi echo "${input}" | sed "s/\[[[:digit:]]\{1,\}m//g" >> "${log_file}" fi } @@ -131,7 +137,17 @@ function decrementNestingLevel() function resetNestingLevel() { rm -f "${nesting_level_file}" - rm -f "${log_file}" +} + +function initLogFile() +{ + if [[ -n "${1}" ]]; then + log_file="${1}" + else + log_file="debug" + fi + echo "log/${log_file}.log" > "${log_file_path}" + rm -f "${vagrant_dir}/log/${log_file}.log" } function getIndentationByNesting()