Skip to content

Commit 2a56f31

Browse files
committed
DB check should NOT depend on file check
1 parent da4045a commit 2a56f31

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

build/scripts/pre-init.d/57_triage_build.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@
55
rm -rf /tmp/DRUPAL_DB_LIVE
66
rm -rf /tmp/DRUPAL_FILES_LIVE
77

8+
# Check if we can connect to the database, and a node table exists.
9+
# DO not use drush as we are unsure of the filesystem state at this point.
10+
# Use the DRUPAL_DB_* environment variables set in the container.
11+
DB_CHECK=$( \
12+
mysql \
13+
--host="$DRUPAL_DB_HOSTNAME" \
14+
--port="$DRUPAL_DB_PORT" \
15+
--user="$DRUPAL_DB_USER" \
16+
--password="$DRUPAL_DB_PASSWORD" \
17+
--database="$DRUPAL_DB_NAME" \
18+
--execute="SHOW TABLES LIKE 'node';" 2>/dev/null \
19+
)
20+
if [ "$DB_CHECK" = "Tables_in_${DRUPAL_DB_NAME} (node)" ] || [ "$DB_CHECK" = "node" ]; then
21+
touch /tmp/DRUPAL_DB_LIVE
22+
echo "Triage : Found Drupal Database with node table."
23+
fi
24+
825
# Determine if the site was previously built by checking for both .htaccess and settings.php in the public file dir.
926
if [ -f "$DRUPAL_ROOT/sites/default/files/.htaccess" ] && [ -f "$DRUPAL_ROOT/sites/default/files/settings.php" ]; then
1027
touch /tmp/DRUPAL_FILES_LIVE
1128
echo "Triage : Found Drupal Filesystem and settings.php."
1229
fi
1330

14-
# Check if the database has tables named *node*. If so, this is likely a live DB.
15-
if [ -f /tmp/DRUPAL_FILES_LIVE ]; then
16-
TABLE_COUNT=$($DRUSH sql-query "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name LIKE '%node%';" --skip-column-names)
17-
if [ "$TABLE_COUNT" -gt 0 ]; then
18-
touch /tmp/DRUPAL_DB_LIVE
19-
echo "Triage : Found Drupal Database with $TABLE_COUNT node tables."
20-
fi
21-
fi

0 commit comments

Comments
 (0)