You are here

public static function Utils::deployCustomFunctions in Drupal driver for SQL Server and SQL Azure 4.2.x

Same name and namespace in other branches
  1. 3.1.x src/Driver/Database/sqlsrv/Utils.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Utils::deployCustomFunctions()
  2. 4.0.x src/Driver/Database/sqlsrv/Utils.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Utils::deployCustomFunctions()
  3. 4.1.x src/Driver/Database/sqlsrv/Utils.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Utils::deployCustomFunctions()

Deploy custom functions for Drupal Compatiblity.

Parameters

Connection $connection: Connection used for deployment.

bool $redeploy: Wether to redeploy existing functions, or only missing ones.

File

src/Driver/Database/sqlsrv/Utils.php, line 108

Class

Utils
Utility function for the SQL Server driver.

Namespace

Drupal\sqlsrv\Driver\Database\sqlsrv

Code

public static function deployCustomFunctions(Connection $connection, $redeploy = FALSE) {
  $yaml = new Parser();
  $base_path = dirname(__FILE__) . '/Programability';
  $configuration = $yaml
    ->parse(file_get_contents("{$base_path}/configuration.yml"));

  /** @var Schema $schema */
  $schema = $connection
    ->schema();
  foreach ($configuration['functions'] as $function) {
    $name = $function['name'];
    $path = "{$base_path}/{$function['file']}";
    $exists = $schema
      ->functionExists($name);
    if ($exists && !$redeploy) {
      continue;
    }
    if ($exists) {
      $connection
        ->queryDirect("DROP FUNCTION [{$name}]");
    }
    $script = trim(static::removeUtf8Bom(file_get_contents($path)));
    $connection
      ->queryDirect($script);
  }
}