Skip to content

Commit 298a782

Browse files
committed
get a little bit more output, create a reusable script
1 parent ec20a57 commit 298a782

File tree

2 files changed

+49
-22
lines changed

2 files changed

+49
-22
lines changed

bin/reloadFixtures.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
DIR=$1
4+
run () {
5+
comment="+++ "$1" +++"
6+
command=$2
7+
echo ${comment}
8+
${command} > output 2> error
9+
OUT=$?
10+
if [ ${OUT} -eq 0 ];then
11+
echo "+++ DONE +++"
12+
cat output
13+
echo
14+
else
15+
echo "+++ Errors +++"
16+
cat output
17+
cat error
18+
exit ${OUT}
19+
fi
20+
}
21+
22+
run "Remove cache directory:" "rm -rf var/cache/prod"
23+
run "Drop and init dbal:" "${DIR}/bin/console --env=prod doctrine:phpcr:init:dbal --drop --force -n"
24+
run "Init repositories:" "${DIR}/bin/console --env=prod doctrine:phpcr:repository:init -n"
25+
run "Load date fixtures:" "${DIR}/bin/console --env=prod doctrine:phpcr:fixtures:load -n"
26+
run "Warm up cache:" "${DIR}/bin/console --env=prod cache:warmup -n --no-debug"

web/reload-fixtures.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
<pre>
21
<?php
32

4-
function runCommand($command, $shouldHaveOutput = true)
3+
function outputNice($output)
54
{
6-
$output = $return_var = null;
7-
echo "Running: $command\n";
8-
exec($command, $output, $return_var);
9-
10-
if (!$shouldHaveOutput) {
11-
return;
5+
if (is_array($output)) {
6+
foreach ($output as $line) {
7+
printf("<pre><code>%s</code>", $line);
8+
}
9+
} else {
10+
printf("<pre><code>%s</code>", $output);
1211
}
12+
}
1313

14-
if (empty($output) || !is_array($output)) {
15-
echo 'Fixtures could not be loaded: '.var_export($return_var, true);
16-
exit(1);
17-
}
18-
echo PHP_EOL;
19-
echo "Output:\n";
20-
foreach ($output as $line) {
21-
echo $line."\n";
22-
}
14+
$commandFile = __DIR__.'/../bin/reloadFixtures.sh';
15+
if (!file_exists($commandFile)) {
16+
outputNice('File not found at: '.$commandFile);
2317
}
2418

25-
runCommand('rm -rf var/cache/prod', false);
26-
runCommand(__DIR__.'/../bin/console --env=prod doctrine:phpcr:init:dbal --drop --force');
27-
runCommand(__DIR__.'/../bin/console --env=prod doctrine:phpcr:repository:init');
28-
runCommand(__DIR__.'/../bin/console -v --env=prod doctrine:phpcr:fixtures:load -n');
29-
runCommand(__DIR__.'/../bin/console --env=prod cache:warmup -n --no-debug');
19+
$returnValue = null;
20+
$output = [];
21+
exec($commandFile.' '.__DIR__.'/../', $output, $returnValue);
22+
23+
if (0 !== (int) $returnValue) {
24+
outputNice('Errors on Execution:');
25+
outputNice($output);
26+
exit($returnValue);
27+
} else {
28+
outputNice($output);
29+
outputNice('Success');
30+
}

0 commit comments

Comments
 (0)