private void ContentService_Publishing(IContentService sender, ContentPublishingEventArgs eventArgs) { ActionModel publish = null; int _currentUserId; using (var contextReference = _context.EnsureUmbracoContext()) { _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id; } try { using (var scope = _scopeProvider.CreateScope(autoComplete: true)) { var sql = scope.SqlContext.Sql().Select("*").From <ActionModel>() .Where <ActionModel>(x => x.id == 6); publish = scope.Database.Fetch <ActionModel>(sql).FirstOrDefault(); } } catch (Exception ex) { _logger.Error <ActionModel>("Failed to get Content Protector setting for publish action: " + ex.Message); } foreach (var node in eventArgs.PublishedEntities) { if (publish != null) { if (publish.nodes.Split(',').Contains(node.Id.ToString()) || publish.disableAction) { if (!publish.userExceptions.Split(',').Contains(_currentUserId.ToString())) { eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin", "You cannot publish " + node.Name, EventMessageType.Error)); } } } } }
private void ContentServicePublishing(IContentService sender, ContentPublishingEventArgs e) { if (!IsConfigured()) { return; } // This only handles variants that has been unpublished. Publishing is handled in the ContentCacheUpdated method var entities = e.PublishedEntities.ToList(); var jobs = new List <EnterspeedJob>(); using (var context = _umbracoContextFactory.EnsureUmbracoContext()) { foreach (var content in entities) { if (!content.ContentType.VariesByCulture()) { continue; } List <IContent> descendants = null; foreach (var culture in content.AvailableCultures) { var isCultureUnpublished = e.IsUnpublishingCulture(content, culture); if (isCultureUnpublished) { var now = DateTime.UtcNow; jobs.Add(new EnterspeedJob { ContentId = content.Id, Culture = culture, JobType = EnterspeedJobType.Delete, State = EnterspeedJobState.Pending, CreatedAt = now, UpdatedAt = now, }); if (descendants == null) { descendants = Current.Services.ContentService .GetPagedDescendants(content.Id, 0, int.MaxValue, out var totalRecords).ToList(); } foreach (var descendant in descendants) { if (descendant.ContentType.VariesByCulture()) { var descendantCultures = descendant.AvailableCultures; if (descendantCultures.Contains(culture)) { jobs.Add(new EnterspeedJob { ContentId = descendant.Id, Culture = culture, JobType = EnterspeedJobType.Delete, State = EnterspeedJobState.Pending, CreatedAt = now, UpdatedAt = now, }); } } } } } } } EnqueueJobs(jobs); }