You are here

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

Same name and namespace in other branches
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Utils.php \Drupal\Driver\Database\sqlsrv\Utils::DeployCustomFunctions()
  2. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Utils.php \Drupal\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

drivers/lib/Drupal/Driver/Database/sqlsrv/Utils.php, line 107

Class

Utils
Utility function for the SQL Server driver.

Namespace

Drupal\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);
  }
}