Adding methods to delete specific versions from content by version id or date.
This commit is contained in:
@@ -301,6 +301,48 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return content;
|
||||
}
|
||||
|
||||
public void Delete(int id, Guid versionId)
|
||||
{
|
||||
var documentDto = Database.FirstOrDefault<DocumentDto>("WHERE nodeId = @Id AND versionId = @VersionId AND newest = @Newest", new { Id = id, VersionId = versionId, Newest = false });
|
||||
Mandate.That<Exception>(documentDto != null);
|
||||
|
||||
using(var transaction = Database.GetTransaction())
|
||||
{
|
||||
DeleteVersion(id, versionId);
|
||||
|
||||
transaction.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(int id, DateTime versionDate)
|
||||
{
|
||||
var list = Database.Fetch<DocumentDto>("WHERE nodeId = @Id AND VersionDate < @VersionDate", new {Id = id, VersionDate = versionDate});
|
||||
Mandate.That<Exception>(list.Any());
|
||||
|
||||
using (var transaction = Database.GetTransaction())
|
||||
{
|
||||
foreach (var dto in list)
|
||||
{
|
||||
DeleteVersion(id, dto.VersionId);
|
||||
}
|
||||
|
||||
transaction.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private method to execute the delete statements for removing a single version for a Content item.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> to delete a version from</param>
|
||||
/// <param name="versionId">Guid id of the version to delete</param>
|
||||
private void DeleteVersion(int id, Guid versionId)
|
||||
{
|
||||
Database.Delete<PreviewXmlDto>("WHERE nodeId = @Id AND versionId = @VersionId", new { Id = id, VersionId = versionId });
|
||||
Database.Delete<PropertyDataDto>("WHERE nodeId = @Id AND versionId = @VersionId", new { Id = id, VersionId = versionId });
|
||||
Database.Delete<ContentVersionDto>("WHERE nodeId = @Id AND VersionId = @VersionId", new { Id = id, VersionId = versionId });
|
||||
Database.Delete<DocumentDto>("WHERE nodeId = @Id AND versionId = @VersionId", new { Id = id, VersionId = versionId });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PropertyCollection GetPropertyCollection(int id, Guid versionId, IContentType contentType)
|
||||
|
||||
@@ -6,7 +6,33 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IContentRepository : IRepositoryQueryable<int, IContent>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list of all versions for an <see cref="IContent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> to retrieve versions from</param>
|
||||
/// <returns>An enumerable list of the same <see cref="IContent"/> object with different versions</returns>
|
||||
IEnumerable<IContent> GetAllVersions(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a specific version of an <see cref="IContent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> to retrieve version from</param>
|
||||
/// <param name="versionId">Id of the version to retrieve</param>
|
||||
/// <returns>An <see cref="IContent"/> item</returns>
|
||||
IContent GetByVersion(int id, Guid versionId);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a specific version from an <see cref="IContent"/> object.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> object to delete a version from</param>
|
||||
/// <param name="versionId">Id of the version to delete</param>
|
||||
void Delete(int id, Guid versionId);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes versions from an <see cref="IContent"/> object prior to a specific date.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> object to delete versions from</param>
|
||||
/// <param name="versionDate">Latest version date</param>
|
||||
void Delete(int id, DateTime versionDate);
|
||||
}
|
||||
}
|
||||
@@ -150,6 +150,38 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional Id of the User deleting the Content</param>
|
||||
void Delete(IContent content, int userId = -1);
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes versions from an <see cref="IContent"/> object prior to a specific date.
|
||||
/// </summary>
|
||||
/// <param name="content">Id of the <see cref="IContent"/> object to delete versions from</param>
|
||||
/// <param name="versionDate">Latest version date</param>
|
||||
/// <param name="userId">Optional Id of the User deleting versions of a Content object</param>
|
||||
void Delete(IContent content, DateTime versionDate, int userId = -1);
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes a specific version from an <see cref="IContent"/> object.
|
||||
/// </summary>
|
||||
/// <param name="content">Id of the <see cref="IContent"/> object to delete a version from</param>
|
||||
/// <param name="versionId">Id of the version to delete</param>
|
||||
/// <param name="userId">Optional Id of the User deleting versions of a Content object</param>
|
||||
void Delete(IContent content, Guid versionId, int userId = -1);
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes versions from an <see cref="IContent"/> object prior to a specific date.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> object to delete versions from</param>
|
||||
/// <param name="versionDate">Latest version date</param>
|
||||
/// <param name="userId">Optional Id of the User deleting versions of a Content object</param>
|
||||
void Delete(int id, DateTime versionDate, int userId = -1);
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes a specific version from an <see cref="IContent"/> object.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> object to delete a version from</param>
|
||||
/// <param name="versionId">Id of the version to delete</param>
|
||||
/// <param name="userId">Optional Id of the User deleting versions of a Content object</param>
|
||||
void Delete(int id, Guid versionId, int userId = -1);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an <see cref="IContent"/> object by moving it to the Recycle Bin
|
||||
/// </summary>
|
||||
|
||||
@@ -473,6 +473,52 @@ namespace Umbraco.Web.Services
|
||||
_unitOfWork.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes versions from an <see cref="IContent"/> object prior to a specific date.
|
||||
/// </summary>
|
||||
/// <param name="content">Id of the <see cref="IContent"/> object to delete versions from</param>
|
||||
/// <param name="versionDate">Latest version date</param>
|
||||
/// <param name="userId">Optional Id of the User deleting versions of a Content object</param>
|
||||
public void Delete(IContent content, DateTime versionDate, int userId = -1)
|
||||
{
|
||||
Delete(content.Id, versionDate, userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes a specific version from an <see cref="IContent"/> object.
|
||||
/// </summary>
|
||||
/// <param name="content">Id of the <see cref="IContent"/> object to delete a version from</param>
|
||||
/// <param name="versionId">Id of the version to delete</param>
|
||||
/// <param name="userId">Optional Id of the User deleting versions of a Content object</param>
|
||||
public void Delete(IContent content, Guid versionId, int userId = -1)
|
||||
{
|
||||
Delete(content.Id, versionId, userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes versions from an <see cref="IContent"/> object prior to a specific date.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> object to delete versions from</param>
|
||||
/// <param name="versionDate">Latest version date</param>
|
||||
/// <param name="userId">Optional Id of the User deleting versions of a Content object</param>
|
||||
public void Delete(int id, DateTime versionDate, int userId = -1)
|
||||
{
|
||||
var repository = RepositoryResolver.ResolveByType<IContentRepository, IContent, int>(_unitOfWork);
|
||||
repository.Delete(id, versionDate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes a specific version from an <see cref="IContent"/> object.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> object to delete a version from</param>
|
||||
/// <param name="versionId">Id of the version to delete</param>
|
||||
/// <param name="userId">Optional Id of the User deleting versions of a Content object</param>
|
||||
public void Delete(int id, Guid versionId, int userId = -1)
|
||||
{
|
||||
var repository = RepositoryResolver.ResolveByType<IContentRepository, IContent, int>(_unitOfWork);
|
||||
repository.Delete(id, versionId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an <see cref="IContent"/> object by moving it to the Recycle Bin
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user