2

I have a page redirect set up on my silverstripe 3 site. eg. When event has passed its date the page is unpublished and user redirected to main events page. - this is done in init function

public function init()
    {
        parent::init();

        if ($this->ExpiryDate) {
            $expiryDate = strtotime($this->ExpiryDate);
            $currentDate = strtotime("now");

            if ($expiryDate < $currentDate) {
                $this->doUnpublish();
                $this->redirect('event-no-longer-available/');
            }
        }
    }

However, when I go to edit the unpublished pages in the cms the page is still redirected so I can't access the page to edit it.

I want to update the event page at a later date and change details and expiry date, for example.. when the same event happens again at a later date, just edit then republish the old page instead of creating a whole new page.

Is there a way I can set this up so that the page will redirect on the site but not while I'm trying to edit it in the cms??

subs
  • 179
  • 1
  • 11
  • 2
    Is that init() function from a SiteTree subclass or a controller? You could try putting it in your controller instead (I'm assuming it's not in a controller) which wouldn't affect the CMS. Note that it still would if you're previewing in the CMS, so you might also need to add some "is CMS preview" logic too with the relevant permission checks – scrowler Apr 12 '19 at 00:00
  • @RobbieAverill yup, that's in the controller already. Didn't think to check that but yeah that sorts it when it's not in preview mode.. will just need to find a logic condition I can use to check that, thanks – subs Apr 12 '19 at 03:29

1 Answers1

0

Solved by fixing code.

$this->redirect('event-no-longer-available/');

was not required. Alternative to this can be seen in my other question Can I set a custom error page in silverstripe for certain page types? and by doing this it stopped the redirect.

subs
  • 179
  • 1
  • 11