Some refactoring and small changes:

- Use webObjectsSvc.GetServerManager()
- Do not make any changes if the PHP5 handler is not changed in the UI
- Added text on IIS70_Settings page to inform that the PHP5 Executable Path can be ignored
This commit is contained in:
Olov Karlsson 2014-10-09 11:14:45 +02:00
parent d7ac9fa36f
commit 170b4da51d
5 changed files with 62 additions and 45 deletions

View file

@ -278,34 +278,5 @@ namespace WebsitePanel.Providers.Web.Handlers
srvman.CommitChanges(); srvman.CommitChanges();
} }
} }
internal void MoveHandlerToTop(string handlerName, string siteName, string vDirPath)
{
if (string.IsNullOrEmpty(siteName))
{
return;
}
if (string.IsNullOrEmpty(vDirPath))
{
vDirPath = "/";
}
using (var srvman = GetServerManager())
{
var config = srvman.GetWebConfiguration(siteName, vDirPath);
var handlersSection = (HandlersSection)config.GetSection(Constants.HandlersSection, typeof(HandlersSection));
var handlersCollection = handlersSection.Handlers;
var handlerElement = handlersCollection[handlerName];
handlersCollection.Remove(handlerElement);
handlersCollection.AddCopyAt(0, handlerElement);
srvman.CommitChanges();
}
}
} }
} }

View file

@ -882,22 +882,19 @@ namespace WebsitePanel.Providers.Web
{ {
if (PhpMode == Constants.PhpMode.FastCGI && virtualDir.PhpInstalled.Contains('|')) if (PhpMode == Constants.PhpMode.FastCGI && virtualDir.PhpInstalled.Contains('|'))
{ {
var path = PhpExecutablePath;
var args = virtualDir.PhpInstalled.Split('|'); var args = virtualDir.PhpInstalled.Split('|');
if (args.Count() > 1) if (args.Count() > 1)
{ {
// Handler name is present, let us try to find the corresponding path to executable // Handler name is present, use it to set choosen version
var phpVersion = GetPhpVersions(virtualDir).SingleOrDefault(p => p.HandlerName == args[1]); var handlerName = args[1];
if (phpVersion != null)
{
path = phpVersion.ExecutionPath;
}
}
if (!String.IsNullOrEmpty(path) && File.Exists(path)) if (handlerName != GetActivePhpHandlerName(virtualDir))
{ {
handlersSvc.CopyInheritedHandlers(((WebSite)virtualDir).SiteId, virtualDir.VirtualPath); // Only change handler if it is different from the current one
handlersSvc.MoveHandlerToTop(args[1], ((WebSite) virtualDir).SiteId, virtualDir.VirtualPath); handlersSvc.CopyInheritedHandlers(((WebSite)virtualDir).SiteId, virtualDir.VirtualPath);
MakeHandlerActive(handlerName, virtualDir);
}
} }
} }
else else
@ -4511,12 +4508,21 @@ namespace WebsitePanel.Providers.Web
protected PhpVersion[] GetPhpVersions(WebVirtualDirectory virtualDir) protected PhpVersion[] GetPhpVersions(WebVirtualDirectory virtualDir)
{ {
using (var srvman = new ServerManager()) using (var srvman = webObjectsSvc.GetServerManager())
{ {
return GetPhpVersions(srvman, virtualDir); return GetPhpVersions(srvman, virtualDir);
} }
} }
protected string GetActivePhpHandlerName(WebVirtualDirectory virtualDir)
{
using (var srvman = webObjectsSvc.GetServerManager())
{
return GetActivePhpHandlerName(srvman, virtualDir);
}
}
protected string GetActivePhpHandlerName(ServerManager srvman, WebVirtualDirectory virtualDir) protected string GetActivePhpHandlerName(ServerManager srvman, WebVirtualDirectory virtualDir)
{ {
var config = srvman.GetWebConfiguration(((WebSite)virtualDir).SiteId, virtualDir.VirtualPath); var config = srvman.GetWebConfiguration(((WebSite)virtualDir).SiteId, virtualDir.VirtualPath);
@ -4529,11 +4535,34 @@ namespace WebsitePanel.Providers.Web
).FirstOrDefault(); ).FirstOrDefault();
} }
private static string GetPhpExecutableVersion(string phpexePath) protected static string GetPhpExecutableVersion(string phpexePath)
{ {
return FileVersionInfo.GetVersionInfo(phpexePath).ProductVersion; return FileVersionInfo.GetVersionInfo(phpexePath).ProductVersion;
} }
protected void MakeHandlerActive(string handlerName, WebVirtualDirectory virtualDir)
{
using (var srvman = webObjectsSvc.GetServerManager())
{
var config = srvman.GetWebConfiguration(((WebSite)virtualDir).SiteId, virtualDir.VirtualPath);
var handlersSection = (HandlersSection)config.GetSection(Constants.HandlersSection, typeof(HandlersSection));
var handlersCollection = handlersSection.Handlers;
var handlerElement = handlersCollection[handlerName];
var activeHandlerElement = handlersCollection[GetActivePhpHandlerName(srvman, virtualDir)];
var activeHandlerIndex = handlersCollection.IndexOf(activeHandlerElement);
handlersCollection.Remove(handlerElement);
handlersCollection.AddCopyAt(activeHandlerIndex, handlerElement);
srvman.CommitChanges();
}
}
#endregion #endregion
} }
} }

View file

@ -256,7 +256,10 @@
<data name="txtPublicSharedIP.Text" xml:space="preserve"> <data name="txtPublicSharedIP.Text" xml:space="preserve">
<value>Web Sites Public Shared Address:</value> <value>Web Sites Public Shared Address:</value>
</data> </data>
<data name="chkHeliconApeGlobalRegistration.Text"> <data name="chkHeliconApeGlobalRegistration.Text" xml:space="preserve">
<value xml:space="preserve">Register Helicon Ape module globally:</value> <value>Register Helicon Ape module globally:</value>
</data>
<data name="litPHP5Info.Text" xml:space="preserve">
<value>If any PHP5 FastCGI handlers are present on the server, the PHP 5.x Executable Path given above will be ignored and not used.</value>
</data> </data>
</root> </root>

View file

@ -291,6 +291,11 @@
</asp:DropDownList> </asp:DropDownList>
</td> </td>
</tr> </tr>
<tr>
<td colspan="2" class="Normal">
<asp:Literal ID="litPHP5Info" runat="server" meta:resourcekey="litPHP5Info" Text="If any PHP5 FastCGI handlers are present on the server, the PHP 5.x Executable Path given above will be ignored and not used."></asp:Literal>
</td>
</tr>
<tr> <tr>
<td class="Normal" valign="top"> <td class="Normal" valign="top">
<asp:Label runat="server" meta:resourcekey="perlPathLabel" Text="Perl Executable Path:"></asp:Label> <asp:Label runat="server" meta:resourcekey="perlPathLabel" Text="Perl Executable Path:"></asp:Label>

View file

@ -490,6 +490,15 @@ namespace WebsitePanel.Portal.ProviderControls {
/// </remarks> /// </remarks>
protected global::System.Web.UI.WebControls.DropDownList ddlPhpMode; protected global::System.Web.UI.WebControls.DropDownList ddlPhpMode;
/// <summary>
/// litPHP5Info control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal litPHP5Info;
/// <summary> /// <summary>
/// perlPath control. /// perlPath control.
/// </summary> /// </summary>