Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Database / Driver / sqlite / Connection.php
index a7c1496c7a8f64ecbdd95f24c4467e4f21d7c43e..ef0dd8680aee006945844cf3f9c2a0181dfaf6ba 100644 (file)
@@ -165,7 +165,6 @@ class Connection extends DatabaseConnection {
     return $pdo;
   }
 
-
   /**
    * Destructor for the SQLite connection.
    *
@@ -436,4 +435,50 @@ class Connection extends DatabaseConnection {
     return $prefix . $table;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public static function createConnectionOptionsFromUrl($url, $root) {
+    $database = parent::createConnectionOptionsFromUrl($url, $root);
+
+    // A SQLite database path with two leading slashes indicates a system path.
+    // Otherwise the path is relative to the Drupal root.
+    $url_components = parse_url($url);
+    if ($url_components['path'][0] === '/') {
+      $url_components['path'] = substr($url_components['path'], 1);
+    }
+    if ($url_components['path'][0] === '/') {
+      $database['database'] = $url_components['path'];
+    }
+    else {
+      $database['database'] = $root . '/' . $url_components['path'];
+    }
+
+    // User credentials and system port are irrelevant for SQLite.
+    unset(
+      $database['username'],
+      $database['password'],
+      $database['port']
+    );
+
+    return $database;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function createUrlFromConnectionOptions(array $connection_options) {
+    if (!isset($connection_options['driver'], $connection_options['database'])) {
+      throw new \InvalidArgumentException("As a minimum, the connection options array must contain at least the 'driver' and 'database' keys");
+    }
+
+    $db_url = 'sqlite://localhost/' . $connection_options['database'];
+
+    if (isset($connection_options['prefix']['default']) && $connection_options['prefix']['default'] !== NULL && $connection_options['prefix']['default'] !== '') {
+      $db_url .= '#' . $connection_options['prefix']['default'];
+    }
+
+    return $db_url;
+  }
+
 }