Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/main/Drupal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getPort, { portNumbers } from 'get-port';
import { OutputType, PhpCommand } from './PhpCommand';
import { app, type MessagePortMain } from 'electron';
import { ComposerCommand } from './ComposerCommand';
import { join } from 'node:path';
import { dirname, join } from 'node:path';
import { access, copyFile, glob, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import * as tar from 'tar';
import logger from 'electron-log';
Expand Down Expand Up @@ -189,18 +189,22 @@ export class Drupal
join(siteDir, 'settings.local.php'),
);

// Uncomment the last few lines of default.settings.php so that the local
// settings get loaded. It's a little clunky to do this as an array operation,
// but as this is a one-time change to a not-too-large file, it's an acceptable
// trade-off.
const settingsPath: string = join(siteDir, 'default.settings.php');
// Create settings.php.
const settingsPath: string = join(siteDir, 'settings.php');
await copyFile(
join(dirname(settingsPath), 'default.settings.php'),
settingsPath,
);
// Uncomment the last few lines of settings.php to load the local settings. It's
// a little clunky to do this as an array operation, but as a one-time change to
// a not-too-large file, it's an acceptable trade-off.
const lines: string[] = (await readFile(settingsPath)).toString().split('\n');
const replacements: string[] = lines.slice(-4).map((line: string): string => {
return line.startsWith('# ') ? line.substring(2) : line;
});
lines.splice(-4, 3, ...replacements);
// Export configuration outside the web root.
lines.push(`$settings['config_sync_directory'] = '../config';`);
lines.push(`$settings['config_sync_directory'] = '../config';\n`);
await writeFile(settingsPath, lines.join('\n'));

// Add the drupal_association_extras module to every install profile. We don't want to
Expand Down
19 changes: 1 addition & 18 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import logger from 'electron-log';
import { autoUpdater } from 'electron-updater';
import assert from 'node:assert';
import { access } from 'node:fs/promises';
import { basename, join } from 'node:path';
import * as Sentry from "@sentry/electron/main";
import { Drupal } from './Drupal';
Expand Down Expand Up @@ -115,23 +114,7 @@ ipcMain.handle('drupal:start', async ({ sender: win }): Promise<string | null> =
});

ipcMain.handle('drupal:clear-cache', async (): Promise<void> => {
// If settings.php doesn't exist, return early because clearing the cache on a site
// that isn't installed will raise an error. This check isn't foolproof; settings.php
// is created in the early installer, before the database is set up, and if the
// cache is cleared *during* the installation, weird things could happen. This
// doesn't prevent that possibility, but we're assuming that users will be more
// interested in interacting with Drupal than clicking buttons in the launcher.
const webRoot = drupal.webRoot();
try {
await access(
join(webRoot, 'sites', 'default', 'settings.php'),
);
}
catch {
return;
}

const cwd = join(webRoot, 'core');
const cwd = join(drupal.webRoot(), 'core');
try {
// First, generate the token we need to invoke `rebuild.php` with.
const { stdout: token } = await new PhpCommand(
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/basic/assert-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
assert(PHP_SAPI === 'cli');
$app_root = __DIR__ . '/web';
$site_path = 'sites/default';
require $app_root . '/' . $site_path . '/default.settings.php';
require $app_root . '/' . $site_path . '/settings.php';

assert(isset($settings));
assert($settings['skip_permissions_hardening'] === true);
Expand Down
5 changes: 0 additions & 5 deletions tests/fixtures/basic/web/sites/default/settings.php

This file was deleted.