Ejemplo n.º 1
0
        private bool PostSaveUpdateIdsInParent(
            int appId,
            Dictionary <Guid, int> postSaveIds,
            IEnumerable <IGrouping <string, BundleWithHeader <IEntity> > > pairsOrSingleItems)
        {
            var wrapLog = Log.Call <bool>($"{appId}");
            var app     = Factory.Resolve <Apps.App>().Init(new AppIdentity(Eav.Apps.App.AutoLookupZone, appId),
                                                            ConfigurationProvider.Build(Block, true), false, Log);

            foreach (var bundle in pairsOrSingleItems)
            {
                Log.Add("processing:" + bundle.Key);
                var entity = app.Data.List.One(bundle.First().Header.ListParent());
                var targetIsContentBlock = entity.Type.Name == BlocksRuntime.BlockTypeName;

                var primaryItem = targetIsContentBlock ? FindContentItem(bundle) : bundle.First();
                var primaryId   = GetIdFromGuidOrError(postSaveIds, primaryItem.Entity.EntityGuid);

                var ids = targetIsContentBlock
                    ? new[] { primaryId, FindPresentationItem(postSaveIds, bundle) }
                    : new[] { primaryId as int? };

                var index = primaryItem.Header.ListIndex();

                // add or update slots
                //var itemIsReallyNew = primaryItem.EntityId == 0; // only really add if it's really new
                var willAdd = primaryItem.Header.ListAdd();// && itemIsReallyNew;

                // 2019-07-01 2dm needed to add this, because new-save already gives it an ID
                //if (primaryItem.Header.ReallyAddBecauseAlreadyVerified != null)
                //    willAdd = primaryItem.Header.ReallyAddBecauseAlreadyVerified.Value;

                Log.Add($"will add: {willAdd}; " + // add-pre-verified:{primaryItem.Header.ReallyAddBecauseAlreadyVerified}; " +
                        $"Group.Add:{primaryItem.Header.Add}; EntityId:{primaryItem.Entity.EntityId}");

                var cms       = new CmsManager(app, Log);
                var fieldPair = targetIsContentBlock
                    ? ViewParts.PickPair(primaryItem.Header.Group.Part)
                    : new[] { primaryItem.Header.Field };

                if (willAdd) // this cannot be auto-detected, it must be specified
                {
                    cms.Entities.FieldListAdd(entity, fieldPair, index, ids, cms.EnablePublishing);
                }
                else
                {
                    cms.Entities.FieldListReplaceIfModified(entity, fieldPair, index, ids, cms.EnablePublishing);
                }
            }

            // update-module-title
            BlockEditorBase.GetEditor(Block).UpdateTitle();
            return(wrapLog("ok", true));
        }
Ejemplo n.º 2
0
        private bool PostSaveUpdateIdsInParent(IBlock block,
                                               Dictionary <Guid, int> postSaveIds,
                                               IEnumerable <IGrouping <string, BundleWithHeader <IEntity> > > pairsOrSingleItems)
        {
            var wrapLog = Log.Call <bool>($"{_appIdentity.AppId}");

            if (block == null)
            {
                return(wrapLog("no block, nothing to update", true));
            }

            // todo: if no block given, skip all this

            foreach (var bundle in pairsOrSingleItems)
            {
                Log.Add("processing:" + bundle.Key);
                var entity = CmsManager.Read.AppState.List.One(bundle.First().Header.ListParent());
                var targetIsContentBlock = entity.Type.Name == BlocksRuntime.BlockTypeName;

                var primaryItem = targetIsContentBlock ? FindContentItem(bundle) : bundle.First();
                var primaryId   = GetIdFromGuidOrError(postSaveIds, primaryItem.Entity.EntityGuid);

                var ids = targetIsContentBlock
                    ? new[] { primaryId, FindPresentationItem(postSaveIds, bundle) }
                    : new[] { primaryId as int? };

                var index = primaryItem.Header.ListIndex();

                var willAdd = primaryItem.Header.ListAdd();

                Log.Add($"will add: {willAdd}; Group.Add:{primaryItem.Header.Add}; EntityId:{primaryItem.Entity.EntityId}");

                var fieldPair = targetIsContentBlock
                    ? ViewParts.PickFieldPair(primaryItem.Header.Group.Part)
                    : new[] { primaryItem.Header.Field };

                if (willAdd) // this cannot be auto-detected, it must be specified
                {
                    CmsManager.Entities.FieldListAdd(entity, fieldPair, index, ids, block.Context.Publishing.ForceDraft);
                }
                else
                {
                    CmsManager.Entities.FieldListReplaceIfModified(entity, fieldPair, index, ids, block.Context.Publishing.ForceDraft);
                }
            }

            // update-module-title
            BlockEditorBase.GetEditor(block).UpdateTitle();
            return(wrapLog("ok", true));
        }
Ejemplo n.º 3
0
        private bool PostSaveUpdateIdsInParent(IBlock block,
                                               Dictionary <Guid, int> postSaveIds,
                                               IEnumerable <IGrouping <string, BundleWithHeader <IEntity> > > pairsOrSingleItems)
        {
            var wrapLog = Log.Call <bool>($"{_appIdentity.AppId}");

            if (block == null)
            {
                return(wrapLog("no block, nothing to update", true));
            }

            // todo: if no block given, skip all this

            //var sp = CmsManager.ServiceProvider;
            //var app = sp.Build<Apps.App>().Init(_appIdentity, sp.Build<AppConfigDelegate>().Init(Log).Build(block), Log);

            foreach (var bundle in pairsOrSingleItems)
            {
                Log.Add("processing:" + bundle.Key);
                var entity = CmsManager.Read.AppState.List.One(bundle.First().Header.ListParent()); // app.Data.Immutable.One(bundle.First().Header.ListParent());
                var targetIsContentBlock = entity.Type.Name == BlocksRuntime.BlockTypeName;

                var primaryItem = targetIsContentBlock ? FindContentItem(bundle) : bundle.First();
                var primaryId   = GetIdFromGuidOrError(postSaveIds, primaryItem.Entity.EntityGuid);

                var ids = targetIsContentBlock
                    ? new[] { primaryId, FindPresentationItem(postSaveIds, bundle) }
                    : new[] { primaryId as int? };

                var index = primaryItem.Header.ListIndex();

                // add or update slots
                //var itemIsReallyNew = primaryItem.EntityId == 0; // only really add if it's really new
                var willAdd = primaryItem.Header.ListAdd();// && itemIsReallyNew;

                // 2019-07-01 2dm needed to add this, because new-save already gives it an ID
                //if (primaryItem.Header.ReallyAddBecauseAlreadyVerified != null)
                //    willAdd = primaryItem.Header.ReallyAddBecauseAlreadyVerified.Value;

                Log.Add($"will add: {willAdd}; " + // add-pre-verified:{primaryItem.Header.ReallyAddBecauseAlreadyVerified}; " +
                        $"Group.Add:{primaryItem.Header.Add}; EntityId:{primaryItem.Entity.EntityId}");

                //var cms = new CmsManager().Init(app, Log);
                var fieldPair = targetIsContentBlock
                    ? ViewParts.PickPair(primaryItem.Header.Group.Part)
                    : new[] { primaryItem.Header.Field };

                if (willAdd) // this cannot be auto-detected, it must be specified
                {
                    CmsManager.Entities.FieldListAdd(entity, fieldPair, index, ids, block.Context.Publishing.ForceDraft);
                }
                else
                {
                    CmsManager.Entities.FieldListReplaceIfModified(entity, fieldPair, index, ids, block.Context.Publishing.ForceDraft);
                }
            }

            // update-module-title
            BlockEditorBase.GetEditor(block).UpdateTitle();
            return(wrapLog("ok", true));
        }