示例#1
0
        public bool IsBuilt()
        {
            var docToDoc   = relationService.GetRelationTypeByAlias(RelationTypes.DocumentToDocumentAlias);
            var docToMedia = relationService.GetRelationTypeByAlias(RelationTypes.DocumentToMediaAlias);

            if (docToDoc == null || docToMedia == null)
            {
                return(false);
            }
            var built = relationService.HasRelations(docToDoc);

            built = built || relationService.HasRelations(docToMedia);
            return(built);
        }
        public void Handle(ContentCopiedNotification notification)
        {
            if (notification.RelateToOriginal == false)
            {
                return;
            }

            var relationType = _relationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias);

            if (relationType == null)
            {
                relationType = new RelationType(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias,
                                                Constants.Conventions.RelationTypes.RelateDocumentOnCopyName,
                                                true,
                                                Constants.ObjectTypes.Document,
                                                Constants.ObjectTypes.Document,
                                                false);

                _relationService.Save(relationType);
            }

            var relation = new Relation(notification.Original.Id, notification.Copy.Id, relationType);

            _relationService.Save(relation);

            _auditService.Add(
                AuditType.Copy,
                notification.Copy.WriterId,
                notification.Copy.Id, ObjectTypes.GetName(UmbracoObjectTypes.Document),
                $"Copied content with Id: '{notification.Copy.Id}' related to original content with Id: '{notification.Original.Id}'");
        }
    public void Handle(ContentMovedToRecycleBinNotification notification)
    {
        using (IScope scope = _scopeProvider.CreateScope())
        {
            const string  relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias;
            IRelationType?relationType      = _relationService.GetRelationTypeByAlias(relationTypeAlias);

            // check that the relation-type exists, if not, then recreate it
            if (relationType == null)
            {
                Guid         documentObjectType = Constants.ObjectTypes.Document;
                const string relationTypeName   = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteName;

                relationType = new RelationType(relationTypeName, relationTypeAlias, false, documentObjectType, documentObjectType, false);
                _relationService.Save(relationType);
            }

            foreach (MoveEventInfo <IContent> item in notification.MoveInfoCollection)
            {
                IList <string> originalPath     = item.OriginalPath.ToDelimitedList();
                var            originalParentId = originalPath.Count > 2
                    ? int.Parse(originalPath[originalPath.Count - 2], CultureInfo.InvariantCulture)
                    : Constants.System.Root;

                // before we can create this relation, we need to ensure that the original parent still exists which
                // may not be the case if the encompassing transaction also deleted it when this item was moved to the bin
                if (_entityService.Exists(originalParentId))
                {
                    // Add a relation for the item being deleted, so that we can know the original parent for if we need to restore later
                    IRelation relation =
                        _relationService.GetByParentAndChildId(originalParentId, item.Entity.Id, relationType) ??
                        new Relation(originalParentId, item.Entity.Id, relationType);
                    _relationService.Save(relation);

                    _auditService.Add(
                        AuditType.Delete,
                        item.Entity.WriterId,
                        item.Entity.Id,
                        UmbracoObjectTypes.Document.GetName(),
                        string.Format(_textService.Localize("recycleBin", "contentTrashed"), item.Entity.Id, originalParentId));
                }
            }

            scope.Complete();
        }
    }
        public override void Migrate()
        {
            Logger.Debug <AddContentGuardRelationType>("Running migration {MigrationStep}", "AddContentGuardRelationType");

            var contentGuardRelationType = _relationService.GetRelationTypeByAlias("contentguard");

            if (contentGuardRelationType != null)
            {
                return;
            }

            // Insert custom relation type to Umbraco DB
            contentGuardRelationType =
                new RelationType("Relate (Lock) the Document with the Owner", "contentguard", true, null, null);

            _relationService.Save(contentGuardRelationType);
        }
示例#5
0
        private IRelationType getRelationType(int relationContentId)
        {

            
            var documentToMediaRelationType = relationService.GetRelationTypeByAlias(documentToMediaRelationTypeAlias);
            var documentToDocumentRelationType = relationService.GetRelationTypeByAlias(documentToDocumentRelationTypeAlias);

            var contentType = contentService.GetById(relationContentId);

            IRelationType relationType = null;

            //If contentType is not null, it's a page
            if (contentType != null)
            {
                relationType = documentToDocumentRelationType;
            }
            else//else it's a media item - most likely
            {
                relationType = documentToMediaRelationType;
            }

            return relationType;
        }
        => relationService.GetRelationTypeById(key);     // ??

        protected override IRelationType FindItem(string alias)
        => relationService.GetRelationTypeByAlias(alias);
        private static void ContentService_Saved(IContentService contentService, ContentSavedEventArgs e)
        {
            foreach (IContent content in e.SavedEntities)
            {
                List <string> editors = new List <string>
                {
                    Umbraco.Core.Constants.PropertyEditors.Aliases.Grid,
                    BentoItemDataEditor.EditorAlias,
                    BentoStackDataEditor.EditorAlias
                };

                foreach (Property contentProperty in content.Properties.Where(x => editors.Contains(x.PropertyType.PropertyEditorAlias)))
                {
                    IDataType editor = DataTypeService.GetDataType(contentProperty.PropertyType.DataTypeId);

                    IRelationType bentoBlocksRelationType = RelationService.GetRelationTypeByAlias(RelationTypes.BentoItemsAlias);

                    if (bentoBlocksRelationType == null)
                    {
                        RelationType relationType = new RelationType(
                            RelationTypes.BentoItemsAlias,
                            RelationTypes.BentoItemsName,
                            true,
                            UmbracoObjectTypes.Document.GetGuid(),
                            UmbracoObjectTypes.Document.GetGuid());

                        RelationService.Save(relationType);

                        bentoBlocksRelationType = RelationService.GetRelationTypeByAlias(RelationTypes.BentoItemsAlias);
                    }

                    //todo: this does work but it's a bit brute force...
                    //i guess we could store the current relationships and then store the ones we're creating and compare them and then
                    //delete the ones from the old list that arent in the new list? but that's a lot of db hits...
                    IEnumerable <IRelation> rels = RelationService.GetByParentId(content.Id);
                    foreach (IRelation currentRelation in rels.Where(x => x.RelationType.Id == bentoBlocksRelationType.Id))
                    {
                        RelationService.Delete(currentRelation);
                    }

                    if (contentProperty.PropertyType.PropertyEditorAlias == BentoItemDataEditor.EditorAlias)
                    {
                        foreach (Property.PropertyValue value in contentProperty.Values)
                        {
                            if (value.PublishedValue == null)
                            {
                                break;
                            }

                            var area = JsonConvert.DeserializeObject <Area>(value.PublishedValue.ToString());

                            if (area.Id <= 0)
                            {
                                continue;
                            }

                            var bentoContent = contentService.GetById(area.Id);

                            if (bentoContent == null)
                            {
                                continue;
                            }

                            BentoItemConfiguration config = (BentoItemConfiguration)editor.Configuration;

                            ProcessRelationship(contentService, bentoContent, content, bentoBlocksRelationType, config.ItemDoctypeCompositionAlias);
                        }
                    }
                    else
                    {
                        foreach (Property.PropertyValue value in contentProperty.Values)
                        {
                            if (value.PublishedValue == null)
                            {
                                break;
                            }

                            string valueString = value.PublishedValue?.ToString();

                            if (string.IsNullOrWhiteSpace(valueString))
                            {
                                continue;
                            }

                            IEnumerable <StackItem> items = JsonConvert.DeserializeObject <IEnumerable <StackItem> >(valueString, new StackItemConverter());

                            var itemList = items.Where(x => x.Areas != null && x.Areas.Any())
                                           .SelectMany(stackItem => stackItem.Areas.Where(x => x.Id > 0), (stackItem, x) => contentService.GetById(x.Id))
                                           .Where(bentoContent => bentoContent != null)
                                           .Distinct();

                            BentoStackConfiguration config = (BentoStackConfiguration)editor.Configuration;

                            foreach (IContent item in itemList)
                            {
                                ProcessRelationship(contentService, item, content, bentoBlocksRelationType, config.ItemDoctypeCompositionAlias);
                            }
                        }
                    }
                }
            }
        }
 public ContentGuardService(IRelationService relationService)
 {
     _relationService          = relationService;
     _contentGuardRelationType = _relationService.GetRelationTypeByAlias(ContentGuardRelationTypeAlias);
 }