This repository was archived by the owner on Jan 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (89 loc) · 3.72 KB
/
Copy pathMakefile
File metadata and controls
101 lines (89 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
CMS_DIR := .
# List nodes for a given content type
list-nodes:
@read -p "Enter the content type machine name: " TYPE; \
echo "Fetching nodes of type '$$TYPE'..."; \
$(CMS_DIR)/vendor/bin/drush sql:query "\
SELECT nid, title FROM node_field_data \
WHERE type = '$$TYPE' ORDER BY nid;" | column -t; \
ids=$$($(CMS_DIR)/vendor/bin/drush sql:query --extra=--skip-column-names "\
SELECT nid FROM node_field_data \
WHERE type = '$$TYPE' ORDER BY nid;" | paste -sd, -); \
ids=$$(echo $$ids | sed 's/,$$//'); \
echo "Node IDs (comma-separated): $$ids"
# Export a node by its ID
export-node:
@read -p "Enter the node ID to export (or Ctrl+C to cancel): " NODE_ID; \
if [ -z "$$NODE_ID" ]; then \
echo "No ID provided. Aborting."; \
exit 1; \
fi; \
echo "Exporting node $$NODE_ID..."; \
$(CMS_DIR)/vendor/bin/drush dce node $$NODE_ID > node-$$NODE_ID.yml -y; \
echo "Node exported to node-$$NODE_ID.yml"
export-nodes:
@read -p "Enter the content type (bundle) machine name: " BUNDLE; \
read -p "Enter comma-separated node IDs to export (e.g., 1,4,5,6): " IDS; \
if [ -z "$$BUNDLE" ] || [ -z "$$IDS" ]; then \
echo "Content type or node IDs not provided. Aborting."; \
exit 1; \
fi; \
echo "$$IDS" | tr ',' '\n' | while read NODE_ID; do \
PADDED_ID=`printf "%02d" $$NODE_ID`; \
echo "Exporting node $$NODE_ID as node-$$BUNDLE-$$PADDED_ID.yml..."; \
$(CMS_DIR)/vendor/bin/drush dce node $$NODE_ID > node-$$BUNDLE-$$PADDED_ID.yml -y; \
done; \
echo "Export complete."
list-media:
@echo "Fetching real media image filenames..."; \
$(CMS_DIR)/vendor/bin/drush sql:query "\
SELECT mfd.mid, m.uuid, mfd.bundle, f.filename \
FROM media_field_data mfd \
JOIN media m ON mfd.mid = m.mid \
JOIN media__field_media_image img ON mfd.mid = img.entity_id \
JOIN file_managed f ON img.field_media_image_target_id = f.fid \
ORDER BY mfd.mid;" > media.txt; \
cat media.txt | column -t
export-media-all:
@echo "Exporting all media listed in media.txt..."; \
while IFS= read -r line; do \
MID=$$(echo "$$line" | awk '{print $$1}'); \
UUID=$$(echo "$$line" | awk '{print $$2}'); \
FILENAME=$$(echo "$$line" | awk '{for(i=4;i<=NF;++i) printf "%s%s", $$i, (i<NF?" ":""); printf "\n"}'); \
if [ -n "$$MID" ] && [ -n "$$UUID" ] && [ -n "$$FILENAME" ]; then \
PADDED_ID=$$(printf "%02d" $$MID); \
CLEAN_FILENAME=$$(echo "$$FILENAME" | tr -d '\r' | tr ' ' '-' | tr -cd '[:alnum:]._-'); \
# OUTFILE="media-$$PADDED_ID-$$UUID-$$CLEAN_FILENAME.yml"; \
OUTFILE="media-$$PADDED_ID-$$UUID.yml"; \
echo "Exporting media ID $$MID to $$OUTFILE..."; \
if $(CMS_DIR)/vendor/bin/drush dce media $$MID -y > "$$OUTFILE"; then \
echo "✔ Exported $$OUTFILE"; \
else \
echo "✘ Failed to export media ID $$MID" >&2; \
fi; \
fi; \
done < media.txt; \
echo "All media exports complete."
list-files:
@echo "Listing file entities used in media images..."; \
$(CMS_DIR)/vendor/bin/drush sql:query "\
SELECT f.fid, f.uuid, f.filename, f.uri \
FROM media_field_data mfd \
JOIN media__field_media_image img ON mfd.mid = img.entity_id \
JOIN file_managed f ON img.field_media_image_target_id = f.fid \
ORDER BY f.fid;" > files.txt; \
cat files.txt | column -t
export-files:
@echo "Exporting file entities from files.txt..."; \
while read -r line; do \
FID=$$(echo "$$line" | awk '{print $$1}'); \
FILENAME=$$(echo "$$line" | cut -d' ' -f3-); \
if [ -n "$$FID" ] && [ -n "$$FILENAME" ]; then \
CLEAN_NAME=$$(echo "$$FILENAME" | tr -d '\r' | tr ' ' '-' | tr -cd '[:alnum:]._-'); \
# OUTFILE="file-$$FID--$$CLEAN_NAME.yml"; \
OUTFILE="file-$$FID.yml"; \
echo "Exporting file $$FID to $$OUTFILE..."; \
$(CMS_DIR)/vendor/bin/drush dce file $$FID -y > "$$OUTFILE"; \
fi; \
done < files.txt; \
echo "All file exports complete."