Skip to content

Commit

Permalink
Bugfixes for Form Attachments and Media Library Consistency Check mod…
Browse files Browse the repository at this point in the history
…ule (#130)

* If the site had no forms, this script would sql underflow at the end, causing an error. A check on the length of the sql query fixes this.

* Remove IIF reference to allow SQL 2008, and due to using ClassIsForm, this control requires Kentico 8.0 +.

* Need to check that a path exists before trying to find files in it.
  • Loading branch information
ChristopherBass authored and ChristopherJennings committed Dec 9, 2016
1 parent 7f26eda commit 158f8dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions KInspector.Modules/Modules/Content/DBFileConsistencyModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public ModuleMetadata GetModuleMetadata()
{
Name = "Form Attachments and Media Library Consistency Check",
SupportedVersions = new[] {
new Version("6.0"),
new Version("7.0"),
new Version("8.0"),
new Version("8.1"),
new Version("8.2"),
Expand Down Expand Up @@ -368,14 +366,21 @@ public static FileInfo[] GetFiles(string baseUri, bool recursive, IInstanceInfo
throw new ArgumentNullException($"baseUri value is null");
}

if(baseUri.StartsWith("~/"))
try
{
if(baseUri.StartsWith("~/"))
{
var absPath = Combine(info.Directory.FullName, baseUri.Substring(2));
return Directory.Exists(absPath) ? new DirectoryInfo(absPath).GetFiles("*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) : new FileInfo[] { };
}
else
return Directory.Exists(baseUri) ? new DirectoryInfo(baseUri).GetFiles("*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) : new FileInfo[] { };
}
catch(Exception ex)
{
var absPath = Combine(info.Directory.FullName, baseUri.Substring(2));
return new DirectoryInfo(absPath).GetFiles("*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
throw ex;
}
else
return new DirectoryInfo(baseUri).GetFiles("*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
}
}

/// <summary>
/// Combines a base url with a list of folders afterwards.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ select @sql = @sql + 'Select [' + columnname + '] as AttachmentGUID, ' + siteID


--remove the trailing 'union'
Select @sql = substring(@sql, 1, len(@sql) - 6)
Select @sql = CASE WHEN len(@sql) - 6 >= 0 THEN substring(@sql, 1, len(@sql) - 6) ELSE 'Select top 0 newid() as AttachmentGUID, 0 as SiteID, '''' as TableName' END

exec (@sql)

0 comments on commit 158f8dd

Please sign in to comment.