Skip to content

Commit 932e80f

Browse files
committed
Fix installing pecl_http PHP extension (which includes the raphf PHP extension)
1 parent fa3458e commit 932e80f

File tree

1 file changed

+73
-61
lines changed

1 file changed

+73
-61
lines changed

PhpManager/public/Install-PhpExtension.ps1

Lines changed: 73 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
$tempFolder = $null
8484
$finalDllName = $null
8585
$additionalFiles = @()
86+
$newExtensions = @()
8687
try {
8788
if (Test-Path -Path $Extension -PathType Leaf) {
8889
if ($Version -ne '') {
@@ -95,7 +96,7 @@
9596
throw 'You can''t specify the -MaximumStability argument if you specify an existing file with the -Extension argument'
9697
}
9798
$dllPath = [System.IO.Path]::GetFullPath($Extension)
98-
$newExtension = Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
99+
$newExtensions += Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
99100
$moveDll = $false
100101
}
101102
else {
@@ -165,8 +166,16 @@
165166
$dllFiles = @()
166167
}
167168
}
169+
$dllNames = $dllFiles | Where-Object -Property Name -Like "php_*.dll" | Select-Object -ExpandProperty Name
170+
if ($dllFiles.Count -eq 2 -and $dllNames -contains 'php_http.dll' -and $dllNames -contains 'php_raphf.dll') {
171+
$newExtensions += Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $(Join-Path -Path $tempFolder -ChildPath 'php_raphf.dll')
172+
$additionalExtensionsDll += 'php_raphf.dll'
173+
}
168174
$dllPath = $null
169175
foreach ($dllFile in $dllFiles) {
176+
if ($additionalExtensionsDll -contains $dllFile.Name) {
177+
continue
178+
}
170179
if ($dllFile.Name -like "php_*.dll") {
171180
if ($dllPath) {
172181
throw ("Multiple PHP DLL found in archive downloaded from {0}" -f $availablePackageVersion.PackageArchiveUrl)
@@ -184,7 +193,7 @@
184193
$keepDownloadedFile = $true
185194
$dllPath = $downloadedFile
186195
}
187-
$newExtension = Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
196+
$newExtensions += Get-PhpExtensionDetail -PhpVersion $phpVersion -Path $dllPath
188197
$moveDll = $true
189198
}
190199
catch {
@@ -202,73 +211,76 @@
202211
}
203212
}
204213
}
205-
$oldExtension = Get-PhpExtension -Path $phpVersion.ExecutablePath | Where-Object { $_.Handle -eq $newExtension.Handle }
206-
if ($null -ne $oldExtension) {
207-
if ($oldExtension.Type -eq $Script:EXTENSIONTYPE_BUILTIN) {
208-
Write-Verbose ("'{0}' is a builtin extension" -f $oldExtension.Name)
209-
}
210-
Write-Verbose ("Upgrading extension '{0}' from version {1} to version {2}" -f $oldExtension.Name, $oldExtension.Version, $newExtension.Version)
211-
if (-Not(Test-IsFileWritable($oldExtension.Filename))) {
212-
throw "Unable to write to the file $($oldExtension.Filename)"
213-
}
214-
if ($moveDll) {
215-
Move-Item -Path $dllPath -Destination $oldExtension.Filename -Force
216-
} else {
217-
Copy-Item -Path $dllPath -Destination $oldExtension.Filename -Force
218-
}
219-
try {
220-
Reset-Acl -Path $oldExtension.Filename
221-
} catch {
222-
Write-Debug -Message "Failed to reset the ACL for $($oldExtension.Filename): $($_.Exception.Message)"
223-
}
224-
foreach ($additionalFile in $additionalFiles) {
225-
$additionalFileDestination = Join-Path -Path $AdditionalFilesPath -ChildPath $(Split-Path -Path $additionalFile -Leaf)
226-
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
214+
foreach ($newExtension in $newExtensions) {
215+
$oldExtension = Get-PhpExtension -Path $phpVersion.ExecutablePath | Where-Object { $_.Handle -eq $newExtension.Handle }
216+
if ($null -ne $oldExtension) {
217+
if ($oldExtension.Type -eq $Script:EXTENSIONTYPE_BUILTIN) {
218+
Write-Verbose ("'{0}' is a builtin extension" -f $oldExtension.Name)
219+
}
220+
Write-Verbose ("Upgrading extension '{0}' from version {1} to version {2}" -f $oldExtension.Name, $oldExtension.Version, $newExtension.Version)
221+
if (-Not(Test-IsFileWritable($oldExtension.Filename))) {
222+
throw "Unable to write to the file $($oldExtension.Filename)"
223+
}
224+
if ($moveDll) {
225+
Move-Item -Path $newExtension.Filename -Destination $oldExtension.Filename -Force
226+
} else {
227+
Copy-Item -Path $newExtension.Filename -Destination $oldExtension.Filename -Force
228+
}
227229
try {
228-
Reset-Acl -Path $additionalFileDestination
230+
Reset-Acl -Path $oldExtension.Filename
229231
} catch {
230-
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
232+
Write-Debug -Message "Failed to reset the ACL for $($oldExtension.Filename): $($_.Exception.Message)"
233+
}
234+
foreach ($additionalFile in $additionalFiles) {
235+
$additionalFileDestination = Join-Path -Path $AdditionalFilesPath -ChildPath $(Split-Path -Path $additionalFile -Leaf)
236+
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
237+
try {
238+
Reset-Acl -Path $additionalFileDestination
239+
} catch {
240+
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
241+
}
242+
}
243+
if ($oldExtension.State -eq $Script:EXTENSIONSTATE_DISABLED -and -Not($DontEnable)) {
244+
Enable-PhpExtension -Extension $oldExtension.Name -Path $phpVersion.ExecutablePath
231245
}
232246
}
233-
if ($oldExtension.State -eq $Script:EXTENSIONSTATE_DISABLED -and -Not($DontEnable)) {
234-
Enable-PhpExtension -Extension $oldExtension.Name -Path $phpVersion.ExecutablePath
235-
}
236-
}
237-
else {
238-
Write-Verbose ("Installing new extension '{0}' version {1}" -f $newExtension.Name, $newExtension.Version)
239-
if (-not($NoDependencies)) {
240-
Install-PhpExtensionPrerequisite -Extension $newExtension.Handle -InstallPath $AdditionalFilesPath -PhpPath $phpVersion.ActualFolder
241-
}
242-
if ($null -eq $finalDllName) {
243-
$newExtensionFilename = [System.IO.Path]::Combine($phpVersion.ExtensionsPath, [System.IO.Path]::GetFileName($dllPath))
244-
} else {
245-
$newExtensionFilename = [System.IO.Path]::Combine($phpVersion.ExtensionsPath, [System.IO.Path]::GetFileName($finalDllName))
246-
}
247-
if ($moveDll) {
248-
Write-Verbose "Moving ""$dllPath"" to ""$newExtensionFilename"""
249-
Move-Item -Path $dllPath -Destination $newExtensionFilename
250-
} else {
251-
Write-Verbose "Copying ""$dllPath"" to ""$newExtensionFilename"""
252-
Copy-Item -Path $dllPath -Destination $newExtensionFilename
253-
}
254-
try {
255-
Reset-Acl -Path $newExtensionFilename
256-
} catch {
257-
Write-Debug -Message "Failed to reset the ACL for $($newExtensionFilename): $($_.Exception.Message)"
258-
}
259-
foreach ($additionalFile in $additionalFiles) {
260-
$additionalFileDestination = Join-Path -Path $AdditionalFilesPath -ChildPath $(Split-Path -Path $additionalFile -Leaf)
261-
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
247+
else {
248+
Write-Verbose ("Installing new extension '{0}' version {1}" -f $newExtension.Name, $newExtension.Version)
249+
if (-not($NoDependencies)) {
250+
Install-PhpExtensionPrerequisite -Extension $newExtension.Handle -InstallPath $AdditionalFilesPath -PhpPath $phpVersion.ActualFolder
251+
}
252+
if ($null -eq $finalDllName) {
253+
$newExtensionFilename = [System.IO.Path]::Combine($phpVersion.ExtensionsPath, [System.IO.Path]::GetFileName($newExtension.Filename))
254+
} else {
255+
$newExtensionFilename = [System.IO.Path]::Combine($phpVersion.ExtensionsPath, [System.IO.Path]::GetFileName($finalDllName))
256+
}
257+
if ($moveDll) {
258+
Write-Verbose "Moving ""$($newExtension.Filename)"" to ""$newExtensionFilename"""
259+
Move-Item -Path $newExtension.Filename -Destination $newExtensionFilename
260+
} else {
261+
Write-Verbose "Copying ""$($newExtension.Filename)"" to ""$newExtensionFilename"""
262+
Copy-Item -Path $newExtension.Filename -Destination $newExtensionFilename
263+
}
262264
try {
263-
Reset-Acl -Path $additionalFileDestination
265+
Reset-Acl -Path $newExtensionFilename
264266
} catch {
265-
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
267+
Write-Debug -Message "Failed to reset the ACL for $($newExtensionFilename): $($_.Exception.Message)"
268+
}
269+
foreach ($additionalFile in $additionalFiles) {
270+
$additionalFileDestination = Join-Path -Path $AdditionalFilesPath -ChildPath $(Split-Path -Path $additionalFile -Leaf)
271+
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
272+
try {
273+
Reset-Acl -Path $additionalFileDestination
274+
} catch {
275+
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
276+
}
277+
}
278+
if (-Not($DontEnable)) {
279+
Write-Verbose "Enabling extension ""$($newExtension.Name)"" for ""$($phpVersion.ExecutablePath)"""
280+
Enable-PhpExtension -Extension $newExtension.Name -Path $phpVersion.ExecutablePath
266281
}
267282
}
268-
if (-Not($DontEnable)) {
269-
Write-Verbose "Enabling extension ""$($newExtension.Name)"" for ""$($phpVersion.ExecutablePath)"""
270-
Enable-PhpExtension -Extension $newExtension.Name -Path $phpVersion.ExecutablePath
271-
}
283+
$additionalFiles = @()
272284
}
273285
}
274286
finally {

0 commit comments

Comments
 (0)