function SqliteDatabaseExcluder::excludeDatabaseFiles
Excludes SQLite database files from stage operations.
Parameters
\Drupal\package_manager\Event\CollectPathsToExcludeEvent $event: The event object.
File
-
core/
modules/ package_manager/ src/ PathExcluder/ SqliteDatabaseExcluder.php, line 42
Class
- SqliteDatabaseExcluder
- Excludes SQLite database files from stage operations.
Namespace
Drupal\package_manager\PathExcluderCode
public function excludeDatabaseFiles(CollectPathsToExcludeEvent $event) : void {
// If the database is SQLite, it might be located in the project directory,
// and should be excluded.
if ($this->database
->driver() === 'sqlite') {
// @todo Support database connections other than the default in
// https://www.drupal.org/i/3441919.
$db_path = $this->database
->getConnectionOptions()['database'];
// Exclude the database file and auxiliary files created by SQLite.
$paths = [
$db_path,
"{$db_path}-shm",
"{$db_path}-wal",
];
// If the database path is absolute, it might be outside the project root,
// in which case we don't need to do anything.
if ($this->pathFactory
->create($db_path)
->isAbsolute()) {
try {
$event->addPathsRelativeToProjectRoot($paths);
} catch (\LogicException) {
// The database is outside the project root, so we're done.
}
}
else {
// The database is in the web root, and must be excluded relative to it.
$event->addPathsRelativeToWebRoot($paths);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.