Skip to content

Commit 4c054ea

Browse files
committed
Updated script and documentation
1 parent 87843f5 commit 4c054ea

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# OS2Loop AI stuff
22

3+
Clone the [`os2loop-ai-stuff` branch](https://github.com/itk-dev/os2loop/tree/ai-stuff):
4+
35
``` shell
46
git clone --branch ai-stuff https://github.com/itk-dev/os2loop os2loop-ai-stuff
57
```
68

9+
[The scripts](#scripts) must be run in a running [OS2Loop setup](https://github.com/itk-dev/os2loop) by adding the
10+
`os2loop-ai-stuff` directory (with the Git clone from above) as a volume to the `phpfpm` container, e.g.
11+
12+
``` shell
13+
docker compose run --rm --volumes $PWD/os2loop-ai-stuff:/os2loop-ai-stuff phpfpm /os2loop-ai-stuff/data-export/export.sh
14+
```
15+
16+
> [!NOTE]
17+
> Change `$PWD/os2loop-ai-stuff` to match your actual setup.
18+
719
## Scripts
820

921
``` shell
10-
./os2loop-ai-stuff/data-export/export.sh
22+
data-export/export.sh
1123
```
1224

1325
## Development

data-export/export.sh

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,42 @@ EOF
1313
fi
1414

1515
>&2 cat <<EOF
16-
Usage: ${BASH_SOURCE[0]} project-dir site-uri
16+
Usage: ${BASH_SOURCE[0]} site-uri
1717
1818
EOF
1919
exit 1
2020
}
2121

22-
if (( $# < 2 )); then
22+
if (( $# < 1 )); then
2323
usage "Too few arguments"
2424
fi
2525

26-
project_dir="$1"
27-
uri="$2"
26+
site_uri="$1"
2827

29-
if [ -z "$project_dir" ]; then
30-
usage "Invalid project directory"
31-
fi
32-
33-
if [ ! -d "$project_dir" ] ; then
34-
(>&2 echo 'Project directory "'"$project_dir"'" does not exist')
35-
exit 1
36-
fi
37-
38-
if [ -z "$uri" ]; then
28+
if [ -z "$site_uri" ]; then
3929
usage "Invalid site-uri"
4030
fi
4131

42-
cd "$project_dir"
32+
# cd "$project_dir"
4333

4434
filenames=("$script_dir"/export_*.sql)
4535

4636
for filename in "${filenames[@]}"; do
47-
echo "$filename"
37+
echo "Running $filename"
4838

4939
# JSON
5040

5141
# https://tldp.org/LDP/abs/html/string-manipulation.html
5242
output_filename=${filename/%.sql/.json}
5343
# https://github.com/drush-ops/drush/issues/3071#issuecomment-347929777
54-
vendor/bin/drush --uri="$uri" php:eval "return \Drupal::database()->query(file_get_contents('$filename'))->fetchAll()" --format=json >| "$output_filename" || true
55-
echo "$output_filename"
44+
vendor/bin/drush --uri="$site_uri" php:eval "return \Drupal::database()->query(file_get_contents('$filename'))->fetchAll()" --format=json >| "$output_filename" || true
45+
ls -lh "$output_filename"
5646

5747
# CSV
5848

5949
output_filename=${filename/%.sql/.csv}
6050
# https://stackoverflow.com/a/22421445/2502647
61-
vendor/bin/drush --uri="$uri" sql:cli < "$filename" | awk 'BEGIN { FS="\t"; OFS="," } {
51+
vendor/bin/drush --uri="$site_uri" sql:cli < "$filename" | awk 'BEGIN { FS="\t"; OFS="," } {
6252
rebuilt=0
6353
for(i=1; i<=NF; ++i) {
6454
if ($i ~ /,/ && $i !~ /^".*"$/) {
@@ -70,5 +60,6 @@ for filename in "${filenames[@]}"; do
7060
if (!rebuilt) { $1=$1 }
7161
print
7262
}' >| "$output_filename" || true
73-
echo "$output_filename"
63+
ls -lh "$output_filename"
64+
7465
done

0 commit comments

Comments
 (0)