Skip to content

Commit 3c9a680

Browse files
author
Hayder Sharhan
committed
Merge remote-tracking branch 'remotes/origin/2.0' into varnish_support
2 parents fa14504 + b732418 commit 3c9a680

19 files changed

+137
-79
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2323

2424
### Added
2525

26+
- Added setup and upgrade cron scripts to crontab
27+
- Added logging of all emails in HTML format to `vagrant-magento/log/email`
2628
- Added host wrapper script for bin/magento command on guest
2729
- Added ability to modify guest config files (PHP, Apache etc) directly from host IDE
2830
- Added ability to choose if PhpStorm configs should be removed during project reinitialization

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* [Use Magento CLI (bin/magento)](#use-magento-cli-binmagento)
2020
* [Debugging with XDebug](#debugging-with-xdebug)
2121
* [Connecting to MySQL DB](#connecting-to-mysql-db)
22+
* [View emails sent by Magento](#view-emails-sent-by-magento)
2223
* [Accessing PHP and other config files](#accessing-php-and-other-config-files)
2324
* [Switch between PHP 5.6 and 7.0](#switch-between-php-56-and-70)
2425
* [Activating Varnish](#activating-varnish)
@@ -135,6 +136,7 @@ Note, that semantic versioning is only used for `x.0` branches (not for `develop
135136
1. Make sure that you used `vagrant-magento` directory as project root in PHP Storm (not `vagrant-magento/magento2ce`)
136137
1. If code is not synchronized properly on Windows hosts (or when NFS mode is disabled in [config.yaml](etc/config.yaml.dist) explicitly), make sure that PhpStorm is running before making any changes in the code. This is important because otherwise PhpStorm will not be able to detect changes and upload them to the guest machine
137138
1. Please make sure that currently installed software, specified in [requirements section](#requirements), meets minimum version requirement
139+
1. If MySQL fails to start and Magento reinstallation fails with `ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)`, try to run login to virtual machine using `vagrant ssh` and then run `sudo dpkg-reconfigure mysql-server-5.6`, then `sudo service mysql restart.`
138140

139141
## Day-to-day development scenarios
140142

@@ -213,6 +215,10 @@ To debug Magento Setup script, go to [Magento installation script](scripts/guest
213215

214216
Answer can be found [here](https://github.com/paliarush/magento2-vagrant-for-developers/issues/8)
215217

218+
### View emails sent by Magento
219+
220+
All emails are saved to 'vagrant-magento/log/email' in HTML format.
221+
216222
### Accessing PHP and other config files
217223

218224
It is possible to view/modify majority of guest machine config files directly from IDE on the host. They will be accessible in [etc/guest](etc/guest) directory only when guest machine is running. The list of accessible configs includes: PHP, Apache, Mysql, Varnish, RabbitMQ.
@@ -239,17 +245,15 @@ Unique IP address, SSH port and domain name will be generated for each new insta
239245

240246
### Reset environment
241247

242-
It is possible to reset project environment to default state, which you usually get just after project initialization. The following command will delete vagrant box, vagrant project settings and PhpStorm project settings. After that it will initialize project from scratch. Magento 2 code base (`magento2ce` directory) and [etc/config.yaml](etc/config.yaml.dist) will stay untouched, but guest config files (located in [etc/guest](etc/guest)) will be removed.
248+
It is possible to reset project environment to default state, which you usually get just after project initialization. The following command will delete vagrant box and vagrant project settings. After that it will initialize project from scratch. Magento 2 code base (`magento2ce` directory) and [etc/config.yaml](etc/config.yaml.dist) and PhpStorm settings will stay untouched, but guest config files (located in [etc/guest](etc/guest)) will be cleared.
243249

244250
Go to 'vagrant-magento' created earlier and run in command line:
245251

246252
```
247253
bash init_project.sh -f
248254
```
249255

250-
You can reset project settings and Magento 2 code base at the same time. Magento 2 code base will be deleted and then cloned from the repositories specified in [etc/config.yaml](etc/config.yaml.dist)
251-
252-
Go to 'vagrant-magento' created earlier and run in command line:
256+
It is possible to reset Magento 2 code base at the same time. Magento 2 code base will be deleted and then cloned from the repositories specified in [etc/config.yaml](etc/config.yaml.dist)
253257

254258
```
255259
bash init_project.sh -fc
@@ -259,6 +263,10 @@ To reset PhpStorm project configuration, in addition to `-f` specify `-p` option
259263

260264
```
261265
bash init_project.sh -fp
262-
OR
266+
```
267+
268+
Ultimate project reset can be achieved by combining all available flags:
269+
270+
```
263271
bash init_project.sh -fcp
264272
```

Vagrantfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Vagrant.configure(VAGRANT_API_VERSION) do |config|
4949
config.vm.synced_folder '.', '/vagrant', disabled: true
5050
config.vm.synced_folder './etc', '/vagrant/etc', mount_options: ["dmode=775,fmode=664"]
5151
config.vm.synced_folder './scripts', '/vagrant/scripts'
52+
config.vm.synced_folder './log', '/vagrant/log'
5253
config.vm.synced_folder './.idea', '/vagrant/.idea', create: true
5354
if use_nfs_for_synced_folders
5455
guest_magento_dir = host_magento_dir

init_project.sh

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ if ! echo ${vagrant_plugin_list} | grep -q 'vagrant-host-shell' ; then
2424
fi
2525

2626
# Generate random IP address and host name to prevent collisions, if not specified explicitly in local config
27-
if [ ! -f "${vagrant_dir}/etc/config.yaml" ]; then
28-
cp "${config_path}.dist" ${config_path}
27+
if [[ ! -f "${vagrant_dir}/etc/config.yaml" ]]; then
28+
cp "${config_path}.dist" "${config_path}"
2929
fi
3030
random_ip=$(( ( RANDOM % 240 ) + 12 ))
3131
forwarded_ssh_port=$(( random_ip + 3000 ))
@@ -46,48 +46,49 @@ while getopts 'fcp' flag; do
4646
*) error "Unexpected option ${flag}" ;;
4747
esac
4848
done
49-
if [ ${force_project_cleaning} -eq 1 ]; then
49+
if [[ ${force_project_cleaning} -eq 1 ]]; then
5050
vagrant destroy -f
51-
mv ${vagrant_dir}/etc/guest/.gitignore ${vagrant_dir}/etc/.gitignore.back
52-
rm -rf ${vagrant_dir}/.vagrant ${vagrant_dir}/etc/guest
53-
mkdir ${vagrant_dir}/etc/guest
54-
mv ${vagrant_dir}/etc/.gitignore.back ${vagrant_dir}/etc/guest/.gitignore
55-
if [ ${force_codebase_cleaning} -eq 1 ]; then
56-
rm -rf ${magento_ce_dir}
51+
mv "${vagrant_dir}/etc/guest/.gitignore" "${vagrant_dir}/etc/.gitignore.back"
52+
rm -rf "${vagrant_dir}/.vagrant" "${vagrant_dir}/etc/guest"
53+
mkdir "${vagrant_dir}/etc/guest"
54+
mv "${vagrant_dir}/etc/.gitignore.back" "${vagrant_dir}/etc/guest/.gitignore"
55+
cd "${vagrant_dir}/log" && mv email/.gitignore email_gitignore.back && rm -rf email && mkdir email && mv email_gitignore.back email/.gitignore
56+
if [[ ${force_codebase_cleaning} -eq 1 ]]; then
57+
rm -rf "${magento_ce_dir}"
5758
fi
5859
fi
5960

60-
if [ ! -d ${magento_ce_dir} ]; then
61+
if [[ ! -d ${magento_ce_dir} ]]; then
6162
if [[ ${host_os} == "Windows" ]]; then
6263
git config --global core.autocrlf false
6364
git config --global core.eol LF
6465
git config --global diff.renamelimit 5000
6566
fi
6667
# Check out CE repository
6768
repository_url_ce=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "repository_url_ce")
68-
git clone ${repository_url_ce} ${magento_ce_dir}
69+
git clone ${repository_url_ce} "${magento_ce_dir}"
6970
# Check out EE repository
7071
# By default EE repository is not specified and EE project is not checked out
7172
repository_url_ee=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "repository_url_ee")
72-
if [ -n "${repository_url_ee}" ]; then
73-
git clone ${repository_url_ee} ${magento_ee_dir}
73+
if [[ -n "${repository_url_ee}" ]]; then
74+
git clone ${repository_url_ee} "${magento_ee_dir}"
7475
fi
7576
fi
7677

7778
# Update Magento dependencies via Composer
78-
cd ${magento_ce_dir}
79+
cd "${magento_ce_dir}"
7980
bash "${vagrant_dir}/scripts/host/composer.sh" install
8081

8182
# Create vagrant project
82-
cd ${vagrant_dir}
83+
cd "${vagrant_dir}"
8384
vagrant up
8485

8586
set +x
8687
echo "Configuring PhpStorm..."
87-
if [ ${force_project_cleaning} -eq 1 ] && [ ${force_phpstorm_config_cleaning} -eq 1 ]; then
88-
rm -rf ${vagrant_dir}/.idea
88+
if [[ ${force_project_cleaning} -eq 1 ]] && [[ ${force_phpstorm_config_cleaning} -eq 1 ]]; then
89+
rm -rf "${vagrant_dir}/.idea"
8990
fi
90-
if [ ! "$(ls -A ${vagrant_dir}/.idea)" ]; then
91+
if [[ ! "$(ls -A "${vagrant_dir}/.idea")" ]]; then
9192
bash "${vagrant_dir}/scripts/host/configure_php_storm.sh"
9293
fi
9394

log/email/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

m-switch-to-ce

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ php_executable=$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")
99
# Enable trace printing and exit on the first error
1010
set -ex
1111

12-
if [ ! -f ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ]; then
12+
if [[ ! -f ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ]]; then
1313
echo "EE codebase is not available"
1414
exit 0
1515
fi
1616

17-
if [ ! -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]; then
17+
if [[ ! -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]]; then
1818
echo "Already switched to CE"
1919
exit 0
2020
fi
@@ -27,10 +27,10 @@ git checkout composer.lock
2727

2828
if [[ ${host_os} == "Windows" || $(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs") == 0 ]]; then
2929
# Prevent issues on Windows with incorrect symlinks to files
30-
if [ -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]; then
30+
if [[ -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]]; then
3131
rm ${magento_ce_dir}/app/etc/aliases_to_classes_map.json
3232
fi
33-
if [ -f ${magento_ce_dir}/app/etc/enterprise/di.xml ] && [ ! -L ${magento_ce_dir}/app/etc/enterprise ]; then
33+
if [[ -f ${magento_ce_dir}/app/etc/enterprise/di.xml ]] && [[ ! -L ${magento_ce_dir}/app/etc/enterprise ]]; then
3434
rm ${magento_ce_dir}/app/etc/enterprise/di.xml
3535
rmdir ${magento_ce_dir}/app/etc/enterprise
3636
fi

m-switch-to-ee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ php_executable=$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")
99
# Enable trace printing and exit on the first error
1010
set -ex
1111

12-
if [ ! -f ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ]; then
12+
if [[ ! -f ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ]]; then
1313
echo "EE codebase is not available"
1414
exit 0
1515
fi
1616

17-
if [ -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]; then
17+
if [[ -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]]; then
1818
echo "Already switched to EE"
1919
exit 0
2020
fi
@@ -26,11 +26,11 @@ cp ${magento_ee_dir}/composer.lock ${magento_ce_dir}/composer.lock
2626

2727
if [[ ${host_os} == "Windows" || $(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs") == 0 ]]; then
2828
# Prevent issues on Windows with incorrect symlinks to files
29-
if [ -f ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ] && [ -L ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]; then
29+
if [[ -f ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ]] && [[ -L ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]]; then
3030
rm ${magento_ce_dir}/app/etc/aliases_to_classes_map.json
3131
cp ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ${magento_ce_dir}/app/etc/aliases_to_classes_map.json
3232
fi
33-
if [ -f ${magento_ee_dir}/app/etc/enterprise/di.xml ] && [ -L ${magento_ce_dir}/app/etc/enterprise ]; then
33+
if [[ -f ${magento_ee_dir}/app/etc/enterprise/di.xml ]] && [[ -L ${magento_ce_dir}/app/etc/enterprise ]]; then
3434
rm ${magento_ce_dir}/app/etc/enterprise
3535
mkdir ${magento_ce_dir}/app/etc/enterprise
3636
cp ${magento_ee_dir}/app/etc/enterprise/di.xml ${magento_ce_dir}/app/etc/enterprise/di.xml

scripts/get_config_value.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ parse_yaml() {
55
local prefix=$2
66
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
77
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
8-
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
8+
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
99
awk -F$fs '{
1010
indent = length($1)/2;
1111
vname[indent] = $2;

scripts/guest/link_configs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ function process_configs () {
55
configs=$2
66
for config in "${configs[@]}"
77
do
8-
if [ ! -d /vagrant/etc/guest/${config} ] && [ ! -f /vagrant/etc/guest/${config} ]; then
9-
if [ -d ${configs_path}/${config} ] || [ -f ${configs_path}/${config} ]; then
8+
if [[ ! -d /vagrant/etc/guest/${config} ]] && [[ ! -f /vagrant/etc/guest/${config} ]]; then
9+
if [[ -d ${configs_path}/${config} ]] || [[ -f ${configs_path}/${config} ]]; then
1010
sudo rm -rf "${configs_path}/${config}.back"
1111
sudo cp -rp ${configs_path}/${config} "${configs_path}/${config}.back"
1212
sudo mv ${configs_path}/${config} /vagrant/etc/guest/${config}

scripts/guest/log_email

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
email_log_dir=$1
4+
if [[ ! -d ${email_log_dir} ]]; then
5+
mkdir -p "${email_log_dir}"
6+
fi
7+
8+
# Construct email file path
9+
current_time=$( date +"%Y-%m-%d_%H-%M-%S" )
10+
# Add random suffix to file name just in case there several emails sent in one second
11+
random_suffix=$(( RANDOM % 100 ))
12+
email_file_path="${email_log_dir}/${current_time}_${random_suffix}"
13+
14+
raw_email_output=$(cat)
15+
16+
# Add email topic to file name
17+
pattern="Subject: (.*)\sX-PHP-Originating-Script:"
18+
if [[ "${raw_email_output}" =~ ${pattern} ]]; then
19+
email_topic=${BASH_REMATCH[1]}
20+
email_file_path="${email_file_path}_${email_topic}"
21+
fi
22+
email_file_path="${email_file_path}.html"
23+
24+
# Output content
25+
echo ${raw_email_output} > "${email_file_path}"
26+
27+
# Process raw content of an email to make it a valid HTML
28+
sed -i "s|.*<\!DOCTYPE|<\!DOCTYPE|g" "${email_file_path}"
29+
sed -i "s|=3D|=|g" "${email_file_path}"
30+
sed -i "s|=0A||g" "${email_file_path}"
31+
sed -i "s|= ||g" "${email_file_path}"

0 commit comments

Comments
 (0)