Problem - Archived pages still published

Vote:
 

Hi!

I've ran into a bit of a problem... I'm using the archive function to store passed "events" into a an archive folder. The events have a stop publish date but once they are moved to the archive page the stop publish date is lost and the events with surtain given categories show up in a listing of events that I have. I want them to stay unpublished since they are no longer valid. Is there an easy way to fix this... or can I maybe move them directly to the trash can? My problem here is that I don't have the trash can visible in the pagetree (as before in EPiServer 6) and I'm not sure how to go about this in EPiServer 7.5. Thankful for help!

#90096
Sep 02, 2014 10:08
Vote:
 

If I remember correctly it's a build in functionality to keep them published after archived; I believe the thought is to allow for visitor access to for instance archived news pages etc. Not 100% sure though. You can try out EPi functionality on the demo sites: http://world.episerver.com/Download/Demo-Sites/Alloy/ Just log into World to get hold of usernames and passwords for editors/admins.

You may have to tweak EPi's archive job, or build your own; I don't recon it would be very complex. It may help to have a peek at the EPiServer.Util.PageArchiveJob class using ILSpy or the like.

//Mathias

#90111
Sep 02, 2014 11:33
Vote:
 

Auch! Okey, I've been doing a bit of searching without finding a good or common solution. Do you know if there is a way to set a scheduled job for a surtain node... Let's say I want to make every child page "stop publish" at a given time every day... or maybe even deleted (moved to trash)?

#90115
Sep 02, 2014 12:02
Vote:
 

If you write your own job you could just loop through all the pages that you want to delete and then mimic what the EPi archive job does,

IContentRepository contentRepository;

contentRepository.Move(current.PageLink, current.ArchiveLink, AccessLevel.NoAccess, AccessLevel.NoAccess);

but rather than using current.ArchiveLink, you could make it move to ContentReference.WasteBasket.

Unless you could just set the archive-target to wastebasket directly in the UI; not sure you can though since the basket is no longer part of the tree.

//Mathias

#90121
Sep 02, 2014 13:08
Vote:
 

Okey Mathias... I don't know if I'm doing something totally wrong here but when I'm trying to use something like this

var pages = Locate.ContentRepository().GetChildren(thePageLink);

I get "Locate" underlined and the message (The name 'Locate' does not exist...) in Visual Studio. It works alright when I'm in codebehind (on a template page) but not in my class (ScheduleTest.cs). All libraries (using) are there and the same. Confused!

I'm kind of new to IContentRepository and I've been trying to do it the old way with DataFactory. I've ran into a bit of problem there as well since I can't figure out how to get the PageLinks for my pages under my archive page. I can get/change the pagedata but I'm having problems moving them to the waste basket (since I then need the PageLinks). All very frustrating... If you can help and point me in the right direction I would be thankful! 

#90242
Sep 04, 2014 11:22
Vote:
 

Hi!

Try this for getting the contentRepository and moving the pages:

var contentRepository = ServiceLocator.Current.GetInstance();

contentRepository.Move(current.PageLink, ContentReference.WasteBasket, AccessLevel.NoAccess, AccessLevel.NoAccess);

For getting the PageLink (a ContentReference object nowadays) you could use page.ContentLink

Let me know if you run into problems.

//Mathias

#90258
Sep 04, 2014 14:00
Vote:
 

I've messed around a bit and my problem with Locate seems to be that the method is a Static method (for scheduled job). When I remove the Static declaration Locate works like a charm... But my scheduled job doesnt. It fails since it doesnt find Execute(). Do you know of a way to get around this? Thanks!

#90269
Sep 04, 2014 15:32
Vote:
 

Okey, I think I managed to solve the whole thing by creating a second class (not static) and working with the Locate and content there... Seems like a workaround when I look at it but as for now it solves my problem (I think). Is this the way to go or do you know of a cleaner way? Thank you for your help!

#90270
Sep 04, 2014 16:05
Vote:
 

Hm, do you have any more details on the Execute exception? The Execute method needs to be static, but that wasn't the one you changed was it? Not sure how Locate is implemented but the ServiceLocator-call above works in Execute for me.

Did you call Locate from the constructor?

#90272
Sep 04, 2014 16:15
Vote:
 

Yes, that's what I did... Here's the very charming class theLocateProblem ;)

public class theLocateProblem : PageTemplateBase 
{
public string message;

public theLocateProblem(PageReference pref)
{
var contentRepository = ServiceLocator.Current.GetInstance();
var repository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance();

IEnumerable pages = Locate.ContentRepository().GetChildren(pref);

message = "Removing pages...
"; if (!PageReference.IsNullOrEmpty(pref)) { foreach (var p in pages) { message += "Content moved to waste: " + p.Name + "
"; contentRepository.Move(p.ContentLink, ContentReference.WasteBasket, AccessLevel.NoAccess, AccessLevel.NoAccess); } } else { message += " PageReference för arkiv saknas... Inga sidor är borttagna"; } } }



#90275
Sep 04, 2014 16:25
Vote:
 

Hm, try doing something like this. I haven't tried the code and pieced it together in notepad so you might have to correct typos ^^;

	[EPiServer.PlugIn.ScheduledPlugIn(
		DisplayName = "Remove archived pages",
		Description = "Moves archived pages to the wastebasket.",
		SortIndex = 2)]
	public class RemoveArchivedPagesJob
	{
		private static readonly object JobLock = new object();
		public static string Execute()
		{
			if (!System.Threading.Monitor.TryEnter(JobLock))
			{
				// Other job uses the monitor
				return "Still running";
			}

			try
			{
				MovePages();
				return "OK";
			}
			catch (Exception e)
			{
				//may want to write to log here
				return string.Format("Error: {0}, {1}", e.Message, e.StackTrace);
			}
			finally
			{
				System.Threading.Monitor.Exit(JobLock);
			}
		}

		private static void MovePages()
		{
			var contentRepository = ServiceLocator.Current.GetInstance();
			var archivePageReference = new ContentReference(111); // Reference to archive container page, get it from somewhere.
			var archivedPages = contentRepository.GetChildren(archivePageReference);

			foreach (var page in archivedPages)
			{
				contentRepository.Move(page.PageLink, ContentReference.WasteBasket, AccessLevel.NoAccess, AccessLevel.NoAccess);
			}
		}
	}

The thought is that you select an archive node (the new ContentReference line, you might not want to hard code it like that), retrieves all the child pages, then loop through them moving them to trash. Ought to work :)

#90278
Sep 04, 2014 16:44
Vote:
 

Thank you Mathias... I've lost my hair over this today so I think I'll leave it for now :) Glad I finally got it working. But I'll check your code later... 

#90279
Sep 04, 2014 16:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.