Exemplo n.º 1
0
        public override void Process(AddFromTemplateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (AddFromTemplatePresetDisabler.IsActive)
            {
                return;
            }

            if (args.Destination.Database.Name != "master")
            {
                return;
            }

            var templateItem = args.Destination.Database.GetItem(args.TemplateId);

            Assert.IsNotNull(templateItem, "Template did not exist!");

            // if this isn't a branch template, we can use the stock behavior
            if (templateItem.TemplateID != TemplateIDs.BranchTemplate)
            {
                return;
            }

            Assert.HasAccess((args.Destination.Access.CanCreate() ? 1 : 0) != 0, "AddFromTemplate - Add access required (destination: {0}, template: {1})", args.Destination.ID, args.TemplateId);

            // create the branch template instance
            var newItem = args.Destination.Database.Engines.DataEngine.AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);

            // find all rendering data sources on the branch root item that point to an item under the branch template,
            // and repoint them to the equivalent subitem under the branch instance
            this.RewriteBranchRenderingDataSources(newItem, templateItem, newItem.Paths.FullPath);

            args.Result = newItem;
        }
        public override void Process(AddFromTemplateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (args.Destination.Database.Name != "master")
            {
                return;
            }

            var templateItem = args.Destination.Database.GetItem(args.TemplateId);

            Assert.IsNotNull(templateItem, "RelinkBranchTemplateDatasources.Process: Template does not exist " + args.TemplateId);

            // if this isn't a branch template, we can use the stock behavior
            if (templateItem.TemplateID != TemplateIDs.BranchTemplate)
            {
                return;
            }

            Assert.HasAccess(
                args.Destination.Access.CanCreate(),
                $"RelinkBranchTemplateDatasources.Process: Inadequate access for (destination: {args.Destination.ID}, template: {args.TemplateId})");

            var newItem = args.Destination.Database.Engines.DataEngine
                          .AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);

            RewriteBranchRenderingDataSources(newItem, templateItem);
            args.Result = newItem;
        }
Exemplo n.º 3
0
        public override void Process(AddFromTemplateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (args.Destination.Database.Name != "master")
            {
                return;
            }

            Item templateItem = args.Destination.Database.GetItem(args.TemplateId);

            Assert.IsNotNull(templateItem, "Template did not exist!");

            // if this isn't a branch template, we can use the stock behavior
            if (templateItem.TemplateID != TemplateIDs.BranchTemplate)
            {
                return;
            }

            Assert.HasAccess((args.Destination.Access.CanCreate() ? 1 : 0) != 0, "AddFromTemplate - Add access required (destination: {0}, template: {1})", args.Destination.ID, args.TemplateId);

            // Create the branch template instance
            Item newItem = args.Destination.Database.Engines.DataEngine.AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);

            _branchInstanceItem = newItem;
            ModifyNewFromBranch(newItem, templateItem);
            args.Result = newItem;
        }
Exemplo n.º 4
0
        public override Item AddFromTemplate(string itemName, ID templateId, Item destination, ID newId)
        {
            var args = new AddFromTemplateArgs(this.DefaultProvider, itemName, templateId, destination, newId);

            CorePipeline.Run("addFromTemplate", args);

            return(args.Result);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Processes the specified upload arguments.
        /// </summary>
        /// <param name="args">
        ///     The arguments.
        /// </param>
        public override void Process([NotNull] AddFromTemplateArgs args)
        {
            // this is managed in configuration (runIfAborted=true would have to be set to override the value)
            if (args.Aborted)
            {
                return;
            }

            Assert.IsNotNull(args.FallbackProvider, "FallbackProvider is null");

            try
            {
                var item = args.FallbackProvider.AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);
                if (item == null)
                {
                    return;
                }

                args.ProcessorItem = args.Result = item;
            }
            catch (Exception ex)
            {
                Log.Error("AddFromTemplateRulesProcessor failed. Removing partially created item if it exists.", ex, this);

                var item = args.Destination.Database.GetItem(args.NewId);
                item?.Delete();

                throw;
            }

            if (AddFromTemplateRulesDisabler.IsActive)
            {
                return;
            }

            ID id;

            if (string.IsNullOrWhiteSpace(RuleFolderId) ||
                !Settings.Rules.ItemEventHandlers.RulesSupported(args.Destination.Database) ||
                !ID.TryParse(RuleFolderId, out id))
            {
                return;
            }

            var ruleContext = new PipelineArgsRuleContext <AddFromTemplateArgs>(args);

            RuleManager.RunRules(ruleContext, id);
        }
Exemplo n.º 6
0
		public override void Process(AddFromTemplateArgs args)
		{
			Assert.ArgumentNotNull(args, nameof(args));

			if (args.Destination.Database.Name != "master") return;

			var templateItem = args.Destination.Database.GetItem(args.TemplateId);

			Assert.IsNotNull(templateItem, "Template did not exist!");

			// if this isn't a branch template, we can use the stock behavior
			if (templateItem.TemplateID != TemplateIDs.BranchTemplate) return;

			Assert.HasAccess((args.Destination.Access.CanCreate() ? 1 : 0) != 0, "AddFromTemplate - Add access required (destination: {0}, template: {1})", args.Destination.ID, args.TemplateId);

			// Create the branch template instance
			Item newItem = args.Destination.Database.Engines.DataEngine.AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);

			// find all rendering data sources on the branch root item that point to an item under the branch template,
			// and repoint them to the equivalent subitem under the branch instance
			RewriteBranchRenderingDataSources(newItem, templateItem);

			args.Result = newItem;
		}