Programatically add a page: when is it ready?

Permalink
Hi,

I am trying to create an importer script that will actually add some new pages and content inside, using a certain logic. I am running all these inside a PHP Code block for now, probably will need to move everything in a single page or so.

I have followed the "Full Example" from here http://www.concrete5.org/documentation/developers/5.7/working-with-... and it works perfect in terms of creating a new page. Here is my code:

//prepare for page add
$parentPage = \Page::getByPath('/mummies');
$pageType = \PageType::getByHandle('imported_page');
$template = \PageTemplate::getByHandle('right_sidebar');
//do page add
$newPage = $parentPage->add($pageType, array(
    'cName' => 'Programmatic Page',
    'cDescription' => 'A programmatic page.'
), $template);

The new page appears instantly in the sitemap with the given title and description.

Then, inside the same script I'm trying to get a list of all available areas in this new page (and their handles) as I intend to use them further on to add content in each:

var_dump ( \Area::getListOnPage($newPage) );

Well, the surprise is that the last line of code returns an empty array UNTIL I visit the new page in (another) browser once! So, somehow, the page gets created but is not "populated" (?)

Is this normal behaviour? If so, is there a way to trigger "populating" the page with whatever empty areas it should have according to its template/type, as to be able to see/access them immediately in the code?

Thank you all,

Lian