November Happy Hour will be moved to Thursday December 5th.

Copied page automatically published

Vote:
 

I noticed that, if you copy a published page, the copy is automatically published as well.
In my opinion, this is unwanted behaviour since it creates duplicate content on your website.

I want to create an InitializableModule to fix this, but I'm wondering how I can detect that a page is new and is a copy of another page.

And should I just cancel the publish event or is there some kind of property that I can set that will prevent the page from being published in the first place?

#173146
Edited, Dec 15, 2016 8:31
Vote:
 

Thanks Russell, that would seem like the right thing to do then.

Is there some way I can track the issue? I don't have access to support since I'm not certified yet...

#173217
Dec 16, 2016 9:13
Vote:
 

One option is to intercept the IDataImporter interface and replace SaveAction for copy operations, something like:

using EPiServer.Core;
using EPiServer.DataAccess;
using EPiServer.Enterprise;
using EPiServer.Framework;
using EPiServer.ServiceLocation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace EPiServerSite4
{
    [InitializableModule]
    public class NotPublishedCopyModule : IConfigurableModule
    {
        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            context.Services.Intercept<IDataImporter>((s, d) => new NoPublishOnCopyDataImporter(d));
        }

        public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context){}
        public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context){}
    }

    public class NoPublishOnCopyDataImporter : IDataImporter
    {
        private IDataImporter _defaultImporter;

        public NoPublishOnCopyDataImporter(IDataImporter defaultImporter)
        {
            _defaultImporter = defaultImporter;
        }

        public void Abort()
        {
            _defaultImporter.Abort();
        }

        public ITransferLog Import(Stream stream, ContentReference destinationRoot, ImportOptions options)
        {
            if (options.TransferType == EPiServer.Core.Transfer.TypeOfTransfer.Copying)
                options.SaveAction = SaveAction.CheckOut | SaveAction.SkipValidation;

            return _defaultImporter.Import(stream, destinationRoot, options);
        }

        public IImportStatus Status
        {
            get { return _defaultImporter.Status; }
        }
    }
}
#173243
Dec 16, 2016 16:24
Vote:
 

Thanks Johan, I will try that if this is not picked up as a bug by Episerver...

#173370
Dec 22, 2016 10:40
Vote:
 

Thanks Russell, for your help.

I'm gonna talk to our product owner about this... see what we can do.

#174321
Jan 24, 2017 13:48
Vote:
 

And what is decided by the product manager?

#197031
Sep 19, 2018 16:34
Vote:
 

A simple way to copy a published page without publishing it is to use project. You create a Project,  make sure that it active and selected before you start pasting. From then, any content you copy&paste from 1 folder to another will be a new content without Published date.

#197158
Edited, Sep 25, 2018 9:07
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.