Skip to content

Commit

Permalink
Add support to install sqlsrv and pdo_sqlsrv from GitHub releases
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Sep 9, 2023
1 parent 661ad4b commit 0c851d5
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/scripts/extensions/add_extensions.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Function to check if extension is enabled.
Function Test-Extension() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[string]
$extension
)
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
return $null -ne $extension_info
}

# Function to add extension log.
Function Add-ExtensionLog() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
Expand All @@ -7,8 +20,7 @@ Function Add-ExtensionLog() {
[ValidateNotNull()]
$message
)
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
if ($null -ne $extension_info -and ($extension_info.State -eq 'Enabled' -or $extension_info.State -eq 'Builtin')) {
if (Test-Extension $extension) {
Add-Log $tick $extension $message
} else {
Add-Log $cross $extension "Could not install $extension on PHP $( $installed.FullVersion )"
Expand Down
70 changes: 70 additions & 0 deletions src/scripts/extensions/sqlsrv.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Function to get sqlsrv extension version.
Function Get-SqlsrvReleaseVersion() {
if ($version -eq '7\.[0-2]')
{
# Use the releases from PECL for these versions
return null;
} elseif($version -eq '7.3') {
return '5.9.0'
} elseif ($version -eq '7.4') {
return '5.10.1'
} else {
return 'latest'
}
}

# Function to get sqlsrv extension release URL.
Function Get-SqlsrvReleaseUrl()
{
$extensionVersion = Get-SqlsrvReleaseVersion
if($extensionVersion) {
$repo = "$github/microsoft/msphpsql"
if($extensionVersion -eq 'latest') {
return "$repo/releases/latest/download/Windows-$version.zip"
} else {
return "$repo/releases/download/v$extensionVersion/Windows-$version.zip"
}
}
}

# Function to add sqlsrv extension from GitHub.
Function Add-SqlsrvFromGithub()
{
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[string]
$extension
)
$zipUrl = SqlsrvReleaseUrl
if($zipUrl) {
$nts = if (!$installed.ThreadSafe) { "nts" } else { "ts" }
$noDotVersion = $version.replace('.', '')
$extensionFilePath = "Windows-$version\$arch\php_${extension}_${noDotVersion}_${nts}.dll"
Get-File -Url $zipUrl -OutFile $ENV:RUNNER_TOOL_CACHE\sqlsrv.zip > $null 2>&1
Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\sqlsrv.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\sqlsrv -Force > $null 2>&1
Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\sqlsrv\$extensionFilePath" -Destination "$ext_dir\php_$extension.dll"
Enable-PhpExtension -Extension $extension -Path $php_dir
}
}

# Function to add sqlsrv extension.
Function Add-Sqlsrv() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[string]
$extension
)
$status = 'Enabled'
if (Test-Path $ext_dir\php_$extension.dll) {
Enable-PhpExtension -Extension $extension -Path $php_dir
} else {
Add-SqlsrvFromGithub $extension >$null 2>&1
if (-not(Test-Extension $extension)) {
Add-Extension $extension >$null 2>&1
}
$status = 'Installed and enabled'
}
Add-ExtensionLog sqlsrv $status
}

0 comments on commit 0c851d5

Please sign in to comment.