Jump to:

23376 Posts in 18214 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » doPublish broken?

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

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

Page: 1
Go to End
Author Topic: 1043 Views
  • Mo
    Avatar
    Community Member
    505 Posts

    doPublish broken? Link to this post

    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

  • Mo
    Avatar
    Community Member
    505 Posts

    Re: doPublish broken? Link to this post

    Had no one else had any problems with this?

    My version of SIlverstripe is 2.4.1.

    Cheers,

    Mo

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: doPublish broken? Link to this post

    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?

  • Mo
    Avatar
    Community Member
    505 Posts

    Re: doPublish broken? Link to this post

    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

    1043 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.