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

Commit 68bfede

Browse files
authored
Merge pull request #72 from paliarush/Sample-Data-Support
Sample data support (#18)
2 parents 29d8178 + 7784d8f commit 68bfede

10 files changed

+191
-65
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1919

2020
### Added
2121

22+
- Added sample data support
2223
- Added ElasticSearch support
2324

2425
## [v2.1.0] - 2016-06-22

README.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Vagrant project for Magento 2 developers (optimized for Mac, Windows and \*nix hosts)
22

3+
[![Tests passing on OSX](docs/images/tests_badge.png)](https://github.com/paliarush/magento2-vagrant-for-developers-tests)
34
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
45
[![Semver](http://img.shields.io/SemVer/2.0.0.png?color=blue)](http://semver.org/spec/v2.0.0.html)
56
[![Latest GitHub release](docs/images/release_badge.png)](https://github.com/paliarush/magento2-vagrant-for-developers/releases/latest)
@@ -13,14 +14,15 @@
1314
* [Day-to-day development scenarios](#day-to-day-development-scenarios)
1415
* [Reinstall Magento](#reinstall-magento)
1516
* [Clear Magento cache](#clear-magento-cache)
16-
* [Update Composer dependencies](#update-composer-dependencies)
1717
* [Switch between CE and EE](#switch-between-ce-and-ee)
18+
* [Sample data installation](#sample-data-installation)
1819
* [Use Magento CLI (bin/magento)](#use-magento-cli-binmagento)
1920
* [Debugging with XDebug](#debugging-with-xdebug)
2021
* [Connecting to MySQL DB](#connecting-to-mysql-db)
2122
* [View emails sent by Magento](#view-emails-sent-by-magento)
2223
* [Accessing PHP and other config files](#accessing-php-and-other-config-files)
2324
* [Multiple Magento instances](#multiple-magento-instances)
25+
* [Update Composer dependencies](#update-composer-dependencies)
2426
* [Environment configuration](#environment-configuration)
2527
* [Switch between PHP 5.6 and 7.0](#switch-between-php-56-and-70)
2628
* [Activating Varnish](#activating-varnish)
@@ -169,15 +171,12 @@ Force switch can be done using `-f` flag even if already switched to the target
169171

170172
: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.
171173

172-
### Update Composer dependencies
174+
### Sample data installation
173175

174-
Go to 'vagrant-magento' created earlier and run in command line:
176+
Make sure that `ce_sample_data` and `ee_sample_data` are defined in [config.yaml](etc/config.yaml.dist) and point CE and optionally EE sample data repositories.
177+
During initial project setup or during `bash init_project.sh -fc` (with `-fc` project will be re-created from scratch), sample data repositories willl be checked out to `vagrant_project_root/magento2ce/magento2ce-sample-data` and `vagrant_project_root/magento2ce/magento2ee-sample-data`.
175178

176-
```
177-
bash m-composer install
178-
OR
179-
bash m-composer update
180-
```
179+
To install Magento with sample data set `install_sample_data` in [config.yaml](etc/config.yaml.dist) to `1` and run `bash m-switch-to-ce -f` or `bash m-switch-to-ee -f`, depending on the edition to be installed. To disable sample data, set this option to `0` and force-switch to necessary edition (using the same commands).
181180

182181
### Use Magento CLI (bin/magento)
183182

@@ -229,6 +228,16 @@ After editing configs in IDE it is still required to restart related services ma
229228
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.
230229
Unique IP address, SSH port and domain name will be generated for each new instance if not specified manually in `etc/config.yaml`
231230

231+
### Update Composer dependencies
232+
233+
Go to 'vagrant-magento' created earlier and run in command line:
234+
235+
```
236+
bash m-composer install
237+
OR
238+
bash m-composer update
239+
```
240+
232241
## Environment configuration
233242

234243
### Switch between PHP 5.6 and 7.0

docs/images/tests_badge.png

3.12 KB
Loading

docs/images/tests_badge.svg

+20
Loading

etc/config.yaml.dist

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
repository_url:
22
# [To apply changes: init-project -fc]
3+
# git@github.com:magento/magento2ce.git OR custom one
34
ce: "git@github.com:magento/magento2.git"
5+
# git@github.com:magento/magento2ee.git OR custom one
46
ee: ""
7+
# can be replaced with custom repository
8+
ce_sample_data: "git@github.com:magento/magento2-sample-data.git"
9+
# git@github.com:magento/magento2-sample-data-ee.git OR custom one
10+
ee_sample_data: ""
511
guest:
612
# [To apply changes: init-project -f]
713
# NFS will be used for folder synchronization on *nix and OSX hosts by default.
@@ -22,6 +28,8 @@ environment:
2228
# [To apply changes: m-reinstall]
2329
search_engine: "mysql"
2430
magento:
31+
# [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f]
32+
install_sample_data: 0
2533
# [To apply changes: init-project -f]
2634
host_name: "magento2.vagrant2"
2735
# [To apply changes: m-reinstall]

init_project.sh

+11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
vagrant_dir=$PWD
44
magento_ce_dir="${vagrant_dir}/magento2ce"
5+
magento_ce_sample_data_dir="${magento_ce_dir}/magento2ce-sample-data"
56
magento_ee_dir="${magento_ce_dir}/magento2ee"
7+
magento_ee_sample_data_dir="${magento_ce_dir}/magento2ee-sample-data"
68
config_path="${vagrant_dir}/etc/config.yaml"
79
host_os=$(bash "${vagrant_dir}/scripts/host/get_host_os.sh")
810
use_nfs=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs")
@@ -69,11 +71,20 @@ if [[ ! -d ${magento_ce_dir} ]]; then
6971
fi
7072
# Check out CE repository
7173
git clone ${repository_url_ce} "${magento_ce_dir}"
74+
# Check out CE sample data repository
75+
repository_url_ce_sample_data=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "repository_url_ce_sample_data")
76+
git clone ${repository_url_ce_sample_data} ${magento_ce_sample_data_dir}
7277
# Check out EE repository
7378
# By default EE repository is not specified and EE project is not checked out
7479
if [[ -n "${repository_url_ee}" ]]; then
7580
git clone ${repository_url_ee} "${magento_ee_dir}"
7681
fi
82+
# Check out EE sample data repository
83+
# By default EE sample data repository is not specified and EE project is not checked out
84+
repository_url_ee_sample_data=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "repository_url_ee_sample_data")
85+
if [ -n "${repository_url_ee_sample_data}" ]; then
86+
git clone ${repository_url_ee_sample_data} ${magento_ee_sample_data_dir}
87+
fi
7788
fi
7889

7990
# Update Magento dependencies via Composer

m-reinstall

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ vagrant_dir=$(cd "$(dirname "$0")"; pwd)
66
set -ex
77

88
cd "${vagrant_dir}"
9-
vagrant ssh -c "m-reinstall"
9+
vagrant ssh -c "m-reinstall"

m-switch-to-ce

+30-29
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,40 @@ while getopts 'f' flag; do
1717
esac
1818
done
1919

20-
if [[ ! -f ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ]]; then
21-
set +x
22-
echo "EE codebase is not available"
23-
set -x
24-
if [[ ${force_switch} -eq 1 ]]; then
25-
bash "${vagrant_dir}/m-reinstall"
20+
if [[ ! -f ${magento_ee_dir}/app/etc/enterprise/di.xml ]]; then
21+
if [[ ${force_switch} -eq 0 ]]; then
22+
set +x
23+
echo "EE codebase is not available. Use 'm-switch-to-ce -f' to switch anyway."
24+
set -x
25+
exit 0
2626
fi
27-
exit 0
28-
fi
29-
30-
if [[ ! -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]] && [[ ${force_switch} -eq 0 ]]; then
31-
set +x
32-
echo "Already switched to CE. Use 'm-switch-to-ce -f' to switch anyway."
33-
exit 0
34-
fi
35-
36-
${php_executable} -f ${magento_ee_dir}/dev/tools/build-ee.php -- --command=unlink --ee-source="${magento_ee_dir}" --ce-source="${magento_ce_dir}"
37-
38-
cd ${magento_ce_dir}
39-
git checkout composer.json
40-
git checkout composer.lock
41-
42-
if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs") == 0 ]]; then
43-
# Prevent issues on Windows with incorrect symlinks to files
44-
if [[ -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]]; then
45-
rm ${magento_ce_dir}/app/etc/aliases_to_classes_map.json
27+
else
28+
if [[ ! -f ${magento_ce_dir}/app/etc/enterprise/di.xml ]] && [[ ${force_switch} -eq 0 ]]; then
29+
set +x
30+
echo "Already switched to CE. Use 'm-switch-to-ce -f' to switch anyway."
31+
exit 0
4632
fi
47-
if [[ -f ${magento_ce_dir}/app/etc/enterprise/di.xml ]] && [[ ! -L ${magento_ce_dir}/app/etc/enterprise ]]; then
48-
rm ${magento_ce_dir}/app/etc/enterprise/di.xml
49-
rmdir ${magento_ce_dir}/app/etc/enterprise
33+
34+
${php_executable} -f ${magento_ee_dir}/dev/tools/build-ee.php -- --command=unlink --ee-source="${magento_ee_dir}" --ce-source="${magento_ce_dir}"
35+
36+
cd ${magento_ce_dir}
37+
git checkout composer.json
38+
git checkout composer.lock
39+
40+
if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs") == 0 ]]; then
41+
# Prevent issues on Windows with incorrect symlinks to files
42+
if [[ -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]]; then
43+
rm ${magento_ce_dir}/app/etc/aliases_to_classes_map.json
44+
fi
45+
if [[ -f ${magento_ce_dir}/app/etc/enterprise/di.xml ]] && [[ ! -L ${magento_ce_dir}/app/etc/enterprise ]]; then
46+
rm ${magento_ce_dir}/app/etc/enterprise/di.xml
47+
rmdir ${magento_ce_dir}/app/etc/enterprise
48+
fi
5049
fi
5150
fi
5251

52+
bash "${vagrant_dir}/scripts/host/relink_sample_data.sh"
53+
5354
bash "${vagrant_dir}/m-clear-cache"
5455
bash -c "${vagrant_dir}/m-composer install"
5556

@@ -58,4 +59,4 @@ if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config
5859
read -p "Wait while Magento2 code is uploaded in PhpStorm and press any key to continue..." -n1 -s
5960
fi
6061

61-
bash "${vagrant_dir}/m-reinstall"
62+
bash "${vagrant_dir}/m-reinstall"

m-switch-to-ee

+32-27
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ 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
13-
set +x
14-
echo "EE codebase is not available"
15-
exit 0
16-
fi
17-
1812
force_switch=0
1913
while getopts 'f' flag; do
2014
case "${flag}" in
@@ -23,30 +17,41 @@ while getopts 'f' flag; do
2317
esac
2418
done
2519

26-
if [[ -f ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]] && [[ ${force_switch} -eq 0 ]]; then
27-
set +x
28-
echo "Already switched to EE. Use 'm-switch-to-ee -f' to switch anyway."
29-
exit 0
30-
fi
31-
32-
${php_executable} -f ${magento_ee_dir}/dev/tools/build-ee.php -- --command=link --ee-source="${magento_ee_dir}" --ce-source="${magento_ce_dir}"
33-
34-
cp ${magento_ee_dir}/composer.json ${magento_ce_dir}/composer.json
35-
cp ${magento_ee_dir}/composer.lock ${magento_ce_dir}/composer.lock
36-
37-
if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs") == 0 ]]; then
38-
# Prevent issues on Windows with incorrect symlinks to files
39-
if [[ -f ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ]] && [[ -L ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]]; then
40-
rm ${magento_ce_dir}/app/etc/aliases_to_classes_map.json
41-
cp ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ${magento_ce_dir}/app/etc/aliases_to_classes_map.json
20+
if [[ ! -f ${magento_ee_dir}/app/etc/enterprise/di.xml ]]; then
21+
if [[ ${force_switch} -eq 0 ]]; then
22+
set +x
23+
echo "EE codebase is not available. Use 'm-switch-to-ee -f' to switch anyway."
24+
set -x
25+
exit 0
4226
fi
43-
if [[ -f ${magento_ee_dir}/app/etc/enterprise/di.xml ]] && [[ -L ${magento_ce_dir}/app/etc/enterprise ]]; then
44-
rm ${magento_ce_dir}/app/etc/enterprise
45-
mkdir ${magento_ce_dir}/app/etc/enterprise
46-
cp ${magento_ee_dir}/app/etc/enterprise/di.xml ${magento_ce_dir}/app/etc/enterprise/di.xml
27+
else
28+
if [[ -f ${magento_ce_dir}/app/etc/enterprise/di.xml ]] && [[ ${force_switch} -eq 0 ]]; then
29+
set +x
30+
echo "Already switched to EE. Use 'm-switch-to-ee -f' to switch anyway."
31+
exit 0
32+
fi
33+
34+
${php_executable} -f ${magento_ee_dir}/dev/tools/build-ee.php -- --command=link --ee-source="${magento_ee_dir}" --ce-source="${magento_ce_dir}"
35+
36+
cp ${magento_ee_dir}/composer.json ${magento_ce_dir}/composer.json
37+
cp ${magento_ee_dir}/composer.lock ${magento_ce_dir}/composer.lock
38+
39+
if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs") == 0 ]]; then
40+
# Prevent issues on Windows with incorrect symlinks to files
41+
if [[ -f ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ]] && [[ -L ${magento_ce_dir}/app/etc/aliases_to_classes_map.json ]]; then
42+
rm ${magento_ce_dir}/app/etc/aliases_to_classes_map.json
43+
cp ${magento_ee_dir}/app/etc/aliases_to_classes_map.json ${magento_ce_dir}/app/etc/aliases_to_classes_map.json
44+
fi
45+
if [[ -f ${magento_ee_dir}/app/etc/enterprise/di.xml ]] && [[ -L ${magento_ce_dir}/app/etc/enterprise ]]; then
46+
rm ${magento_ce_dir}/app/etc/enterprise
47+
mkdir ${magento_ce_dir}/app/etc/enterprise
48+
cp ${magento_ee_dir}/app/etc/enterprise/di.xml ${magento_ce_dir}/app/etc/enterprise/di.xml
49+
fi
4750
fi
4851
fi
4952

53+
bash "${vagrant_dir}/scripts/host/relink_sample_data.sh"
54+
5055
bash "${vagrant_dir}/m-clear-cache"
5156
bash "${vagrant_dir}/m-composer" install
5257

@@ -55,4 +60,4 @@ if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config
5560
read -p "Wait while Magento2 code is uploaded in PhpStorm and press any key to continue..." -n1 -s
5661
fi
5762

58-
bash "${vagrant_dir}/m-reinstall"
63+
bash "${vagrant_dir}/m-reinstall"

scripts/host/relink_sample_data.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
3+
vagrant_dir=$(cd "$(dirname "$0")/../.."; pwd)
4+
magento_ce_dir="${vagrant_dir}/magento2ce"
5+
magento_ee_dir="${magento_ce_dir}/magento2ee"
6+
magento_ce_sample_data_dir="${magento_ce_dir}/magento2ce-sample-data"
7+
magento_ee_sample_data_dir="${magento_ce_dir}/magento2ee-sample-data"
8+
php_executable="$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")"
9+
install_sample_data=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_install_sample_data")
10+
11+
12+
# Enable trace printing and exit on the first error
13+
set -ex
14+
15+
install_ee=0
16+
if [[ -f "${magento_ce_dir}/app/etc/enterprise/di.xml" ]]; then
17+
install_ee=1
18+
fi
19+
20+
# As a precondition, disable CE sample data
21+
if [[ -f "${magento_ce_sample_data_dir}/dev/tools/build-sample-data.php" ]]; then
22+
${php_executable} -f "${magento_ce_sample_data_dir}/dev/tools/build-sample-data.php" -- --command=unlink --ce-source="${magento_ce_dir}" --sample-data-source="${magento_ce_sample_data_dir}"
23+
set +x
24+
echo "CE Sample data disabled"
25+
set -x
26+
fi
27+
# As a precondition, disable EE sample data
28+
if [[ -f "${magento_ee_sample_data_dir}/dev/tools/build-sample-data.php" ]]; then
29+
"${php_executable}" -f "${magento_ee_sample_data_dir}/dev/tools/build-sample-data.php" -- --command=unlink --ce-source="${magento_ce_dir}" --sample-data-source="${magento_ee_sample_data_dir}"
30+
set +x
31+
echo "EE Sample data disabled"
32+
set -x
33+
fi
34+
35+
if [[ ${install_ee} -eq 1 ]]; then
36+
"${php_executable}" -f "${magento_ee_dir}/dev/tools/build-ee.php" -- --command=link --ee-source="${magento_ee_dir}" --ce-source="${magento_ce_dir}"
37+
fi
38+
39+
if [[ ${install_sample_data} -eq 1 ]]; then
40+
# Installing CE or EE, in both cases CE sample data should be linked
41+
if [[ ! -f "${magento_ce_sample_data_dir}/dev/tools/build-sample-data.php" ]]; then
42+
# Sample data not available and should be enabled
43+
set +x
44+
echo "CE Sample data repository is not available. Recreate project using \"init_project.sh -fc\", which will delete Magento code base and recreate project from scratch. Or clone sample data to <project_dir>/magento2ce/magento2ce-sample-data."
45+
set -x
46+
exit 0
47+
else
48+
# Sample data available and should be enabled
49+
set +x
50+
echo "CE Sample data enabled"
51+
set -x
52+
"${php_executable}" -f "${magento_ce_sample_data_dir}/dev/tools/build-sample-data.php" -- --command=link --ce-source="${magento_ce_dir}" --sample-data-source="${magento_ce_sample_data_dir}"
53+
fi
54+
55+
if [[ ${install_ee} -eq 1 ]]; then
56+
# Installing EE
57+
if [[ ! -f "${magento_ee_sample_data_dir}/dev/tools/build-sample-data.php" ]]; then
58+
# Sample data not available and should be enabled
59+
set +x
60+
echo "EE Sample data repository is not available. Recreate project using \"init_project.sh -fc\", which will delete Magento code base and recreate project from scratch. Or clone sample data to <project_dir>/magento2ce/magento2ee-sample-data."
61+
set -x
62+
exit 0
63+
else
64+
# Sample data available and should be enabled
65+
set +x
66+
echo "EE Sample data enabled"
67+
set -x
68+
"${php_executable}" -f "${magento_ee_sample_data_dir}/dev/tools/build-sample-data.php" -- --command=link --ce-source="${magento_ce_dir}" --sample-data-source="${magento_ee_sample_data_dir}"
69+
fi
70+
fi
71+
fi

0 commit comments

Comments
 (0)