Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit daaa3b2

Browse files
author
Alexander Paliarush
committed
Added email logging support (#9)
1 parent 7800d20 commit daaa3b2

File tree

7 files changed

+54
-1
lines changed

7 files changed

+54
-1
lines changed

CHANGELOG.md

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

2424
### Added
2525

26+
- Added logging of all emails in HTML format to `vagrant-magento/log/email`
2627
- Added host wrapper script for bin/magento command on guest
2728
- Added ability to modify guest config files (PHP, Apache etc) directly from host IDE
2829
- Added ability to choose if PhpStorm configs should be removed during project reinitialization

README.md

Lines changed: 6 additions & 0 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
* [Multiple Magento instances](#multiple-magento-instances)
@@ -134,6 +135,7 @@ Note, that semantic versioning is only used for `x.0` branches (not for `develop
134135
1. Make sure that you used `vagrant-magento` directory as project root in PHP Storm (not `vagrant-magento/magento2ce`)
135136
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
136137
1. Please make sure that currently installed software, specified in [requirements section](#requirements), meets minimum version requirement
138+
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.`
137139

138140
## Day-to-day development scenarios
139141

@@ -212,6 +214,10 @@ To debug Magento Setup script, go to [Magento installation script](scripts/guest
212214

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

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

217223
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.

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ if [ ${force_project_cleaning} -eq 1 ]; then
5252
rm -rf ${vagrant_dir}/.vagrant ${vagrant_dir}/etc/guest
5353
mkdir ${vagrant_dir}/etc/guest
5454
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
5556
if [ ${force_codebase_cleaning} -eq 1 ]; then
5657
rm -rf ${magento_ce_dir}
5758
fi

log/email/.gitignore

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

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}"

scripts/provision/configure_environment_recurring.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ function init_php56 () {
2929
set +x
3030

3131
use_php7=$4
32-
3332
vagrant_dir="/vagrant"
3433

3534
# Remove configs from host in case of force stop of virtual machine before linking restored ones
@@ -74,3 +73,16 @@ else
7473
fi
7574
service apache2 restart
7675
#end Setup PHP
76+
77+
# Enable email logging
78+
if [ ${use_php7} -eq 1 ]; then
79+
php_ini_file="/etc/php/7.0/cli/php.ini"
80+
else
81+
php_ini_file="/etc/php/5.6/cli/php.ini"
82+
fi
83+
pattern=";sendmail_path"
84+
php_config_content="$(cat ${php_ini_file})"
85+
if [[ ${php_config_content} =~ ${pattern} ]]; then
86+
sed -i "s|;sendmail_path =|sendmail_path = \"/vagrant/scripts/guest/log_email ${vagrant_dir}/log/email\"|g" ${php_ini_file}
87+
service apache2 restart
88+
fi

0 commit comments

Comments
 (0)