Duplicating site/page tree

61 views
Skip to first unread message

Dario Marotta

unread,
Apr 15, 2022, 5:11:18 AM4/15/22
to redbeanphp
I cannot duplicate entire site with lin ked page tree.
I just got duplicated sire row, but cannot get duplicated "site_id" field in new pages.
Here's my code:                


$rootPage = R::findOne('page',' page_id IS NULL AND site_id = ?', [ $formData['id'] ]);
$dupRootPage = R::duplicate( $rootPage );
           
$site = R::load('site', $formData['id']);
$dupSite = R::duplicate( $site );
$dupSite->name = $site->name.' (copy)';
                                    
$dupSite->ownPageList[]=$dupRootPage;
$dupRootPage->traverse( 'ownPage', function( $page ) use ($dupSite){
          $dupSite->ownPageList[]=$page;
});

R::store( $dupSite );    
                    


Dario Marotta

unread,
Apr 23, 2022, 4:57:22 PM4/23/22
to redbeanphp
Changed

$dupRootPage->traverse( 'ownPage', function( $page ) use (&$dupSite){
          $dupSite->ownPageList[]=$page;
});

Passing $dupsitre by refenrence.. but nothing changes.
Ploease help!
Message has been deleted

Dario Marotta

unread,
Apr 24, 2022, 9:22:55 AM4/24/22
to redbe...@googlegroups.com
The REAL question is:

If i do:

$rootPage = R::findOne('page',' page_id IS NULL AND site_id = ?', [ $formData['id'] ]);
$dupRootPage = R::duplicate( $rootPage );
R::store( $dupRootPage );


the entire page tree is DUPLICATED!
Also,other tables, linked to page table, are also DUPLICATED (correctly)!

So, why if i do:

$site = R::load('site', $formData['id']);
$dupSite = R::duplicate( $site );
$dupSite->name = $site->name.' (copy)';
R::store( $dupSite );

Does not happen the same?
In theory, it should duplicate all tables linked to site table (i.e. page tree)

--
You received this message because you are subscribed to the Google Groups "redbeanphp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redbeanorm+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redbeanorm/10a1e991-310d-4496-8549-852701f5ec9an%40googlegroups.com.

gabor

unread,
May 20, 2022, 12:26:31 PM5/20/22
to redbeanphp
I answered this post on github
Reply all
Reply to author
Forward
0 new messages