Programatically add a new page without publishing a version

Permalink 2 users found helpful
When I use $newPage = $parentPage->add($pt,$data); to create a new page, a version of the page is published immediately.

Is there a method to create/add a new page so that the new page is not published?

Thanks,
Marcus.

mrowell
 
Job replied on at Permalink Reply
Job
As far as I'm aware this is only possible when pushing updates to a pre-existing page.

As in, in my News System, when people where making edits within my GUI, their updates weren't being automatically approved unless I called:

$p->getVersionObject()->approve();


As far as I can see, throughout the forum people have asked time and time again whether its possible through GUI to which everyone has responded no, so I would imagine thats the case for programatically as well.

I can't see anything in the CollectionVersion class (https://github.com/concrete5/concrete5/blob/5.5.2-devel/web/concrete/models/collection_version.php#L22).

It might be worth looking into changing permissions programatically so that Guests can't read the page and added the exclude from nav attribute.

Let me know how you go on.

If this helps, be sure to mark it as the answer.

Job.
mrowell replied on at Permalink Reply
mrowell
Job,

Thanks for the reply.

It must be possible because if I use the add page button on the tool bar of a page, the new page does create a new unpublished version, just like I want.

Thanks,
Marcus
Job replied on at Permalink Best Answer Reply
Job
Scrap that. It's possible...

Here you go, utilise the "cvIsApproved" in your $data array like so ...

<?php
   $p = Page::getById(1);
   $ct = CollectionType::getByHandle("Full");  
   if(!is_object($p)) {
      die('P not object');
   } else {
      $data = array(
         'cName' => 'cName', 
         'cDescription' => 'cDesc',
         'cvIsApproved'=> false
      );
      $p->add($ct, $data);
   }
?>


Don't forget to mark it as the answer if it helps!

Job.
mrowell replied on at Permalink Reply
mrowell
Awesome Job.

Thanks so much for tracking that down for me.

It works and so simple.
Job replied on at Permalink Reply
Job
Glad I could help mrowell :-)!
lexbi replied on at Permalink Reply
Do you think it's also possible to set Attributes with this method? Or does it require something a little different?

$data = array(
                    'name' => "sample2",
                    'cHandle' => "sample2handle",
                    'cDescription' => "Add page test.",
                    'cvIsApproved'=> false,
                    'attribute_name'=> 'stuff'
            );
mrowell replied on at Permalink Reply
mrowell
Yes.

For others looking into this issue, Remo confirmed this is possible at http://www.concrete5.org/community/forums/customizing_c5/add-page-p...