Fixed issue with list view filter; further unit tests for list view paging
This commit is contained in:
@@ -659,6 +659,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
var sql = translator.Translate()
|
||||
.Where<DocumentDto>(x => x.Newest);
|
||||
|
||||
// Apply filter
|
||||
if (!string.IsNullOrEmpty(filter))
|
||||
{
|
||||
sql = sql.Where("cmsDocument.text LIKE @0", "%" + filter + "%");
|
||||
}
|
||||
|
||||
// Apply order according to parameters
|
||||
if (!string.IsNullOrEmpty(orderBy))
|
||||
{
|
||||
@@ -678,22 +684,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
// So we'll modify the SQL.
|
||||
var modifiedSQL = sql.SQL.Replace("SELECT *", "SELECT cmsDocument.nodeId");
|
||||
|
||||
// HACK: the .Where<DocumentDto>(x => x.Newest) clause above is also being used in PerformGetQuery, so included here,
|
||||
// but it doesn't look to do anything as the clause isn't added to the the generated SQL.
|
||||
// So we'll add it here.
|
||||
modifiedSQL = modifiedSQL.Replace("WHERE ", "WHERE Newest = 1 AND ");
|
||||
|
||||
// HACK: Apply filter. Again, can't get expression based Where filter to be added to the generated SQL,
|
||||
// so working with the raw string. Potential SQL injection here so, although escaped, should be modified.
|
||||
if (!string.IsNullOrEmpty(filter))
|
||||
{
|
||||
modifiedSQL = modifiedSQL.Replace("WHERE ",
|
||||
string.Format("WHERE cmsDocument.text LIKE '%{0}%' AND ", filter.Replace("'", "''")));
|
||||
}
|
||||
|
||||
// Get page of results and total count
|
||||
IEnumerable<IContent> result;
|
||||
var pagedResult = Database.Page<DocumentDto>(pageNumber, pageSize, modifiedSQL);
|
||||
var pagedResult = Database.Page<DocumentDto>(pageNumber, pageSize, modifiedSQL, sql.Arguments);
|
||||
totalRecords = Convert.ToInt32(pagedResult.TotalItems);
|
||||
if (totalRecords > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user