Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

doPublish broken?


Go to End


4 Posts   1586 Views

Avatar
Mo

Community Member, 541 Posts

5 August 2010 at 9:41am

Hi All,

I have been having a lot of trouble using the doPublish, onBeforePublish and onAfterPublish methods on my Page classes. I just cannot seem to get the Silverstripe to call them when I click "save and publish".

I have seen that some other people have had issues with this, is this a bug? I cant really find any documentation around these methods, so does anyone know any links? Or at least a way I can debug the CMS to see why it is not using them?

Cheers,

Mo

Avatar
Mo

Community Member, 541 Posts

10 August 2010 at 4:31am

Had no one else had any problems with this?

My version of SIlverstripe is 2.4.1.

Cheers,

Mo

Avatar
Willr

Forum Moderator, 5523 Posts

10 August 2010 at 2:36pm

I use doPublish() , doUnPublish() etc in UserDefinedForms and it seems to work fine. The function has to be in the model and not the controller FYI and not in some dataobject (i.e has to be on the actual page type).

What code were you having trouble with?

Avatar
Mo

Community Member, 541 Posts

18 August 2010 at 10:03pm

Hi WillR,

I have taken a lot of the code directly from the Userforms module. I have a HomePage class, with doPublish() on the model, then I have a dataobject with the Versioned extension added.

I think looking at it, my title for this thread may be incorrect. The Userforms module does work fine, but the doPublish() method just doesn't seem to get called on my page classes.

If its of any help, the code I am using is:

class HomePage extends Page {
        ...

        public function doPublish() {
            $live = Versioned::get_by_stage("QuadArea", "Live", "\"QuadArea\".\"ParentID\" = {$this->ID}");

            if($live) {
                foreach($live as $area) {
                    $area->doDeleteFromStage('Live');
                }
            }

            $areas = Versioned::get_by_stage("QuadArea", "Stage", "\"QuadArea\".\"ParentID\" = {$this->ID}");
            // publish the draft pages
            if($areas) {
                foreach($this->QuadAreas() as $area) {
                    $area->doPublish('Stage', 'Live');
                }
            }

            parent::doPublish();
        }
}

class QuadArea extends DataObject {
    ...

    static $extensions = array(
        "Versioned('Stage', 'Live')"
    );

    public function doPublish($fromStage, $toStage, $createNewVersion = false) {
        $this->publish($fromStage, $toStage, $createNewVersion);
    }

    ...
}

Any thoughts would be greatly appreciated.

Mo