Skip to content

Commit

Permalink
fix(Lucene.Core): Add error message on unsuccessful index deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
bkapustik committed Oct 21, 2024
1 parent b24d0d6 commit 9a12b22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/Kentico.Xperience.Lucene.Admin/UIPages/IndexListingPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,21 @@ public async Task<ICommandResponse<RowActionResult>> Rebuild(int id, Cancellatio
public Task<ICommandResponse> Delete(int id, CancellationToken _)
{
var index = indexManager.GetIndex(id);
var result = new RowActionResult(false);

if (index is null)
{
var result = new RowActionResult(false);

return Task.FromResult<ICommandResponse>(ResponseFrom(result)
.AddErrorMessage(string.Format("Error loading Lucene index with identifier {0}.", id)));
}

luceneClient.DeleteIndex(index!);
bool indexDeleted = luceneClient.DeleteIndex(index!);

if (!indexDeleted)
{
return Task.FromResult<ICommandResponse>(ResponseFrom(result)
.AddErrorMessage(string.Format("Errors occurred while deleting the '{0}' index. Please check the Event Log for more details.", index.IndexName)));
}

configurationStorageService.TryDeleteIndex(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public Task<int> UpsertRecords(IEnumerable<Document> documents, string indexName
return UpsertRecordsInternal(documents, indexName);
}

public void DeleteIndex(LuceneIndex luceneIndex) =>
luceneIndex?.StorageContext.DeleteIndex();
public bool DeleteIndex(LuceneIndex luceneIndex) =>
luceneIndex?.StorageContext.DeleteIndex() ?? false;

private Task<int> DeleteRecordsInternal(IEnumerable<string> itemGuids, string indexName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface ILuceneClient
/// Removes Lucene index.
/// </summary>
/// <param name="luceneIndex">The index to be deleted.</param>
void DeleteIndex(LuceneIndex luceneIndex);
bool DeleteIndex(LuceneIndex luceneIndex);

/// <summary>
/// Gets the indices of the Lucene application with basic statistics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ public void EnforceRetentionPolicy()
storageStrategy.PerformCleanup(indexStoragePathRoot);
}

public void DeleteIndex() =>
public bool DeleteIndex() =>
storageStrategy.DeleteIndex(indexStoragePathRoot);
}

0 comments on commit 9a12b22

Please sign in to comment.