Jump to content

pages.clone() doesn't clone repeater-fields


Dennis Spohr
 Share

Recommended Posts

Hi all,

I have a weird behavior. I'm using the following code to clone one of my pages:

$block = $salespage->children("id={$duplicate_id},include=all")->first();
$block->of(false);

if ($block && $block->id)
{
  $newone = $pages->clone($block);
}

Problem: the page itself gets cloned, but on of the fields (a repeater) does not get cloned. It's empty.

If I do the same in the ProcessWire-Admin via the PageTree, it works fine. The repeater-field gets cloned there as well.

What could be the problem?

Thanks,
Dennis

Link to comment
Share on other sites

Not sure if this thread is still relevant?

If it is, it seems cloning repeaters can be a pain ??

Btw, this:

$block = $salespage->children("id={$duplicate_id},include=all")->first();

Can be shortened to this:

$block = $salespage->child("id={$duplicate_id},include=all");

 

  • Like 1
Link to comment
Share on other sites

I have another weird behavior on this.

If I use $pages->clone($mypage) I get this error:

Quote

Exception: Can’t save page 0: /ma/.../video/: Call $page->of(false); before getting/setting values that will be modified and saved. [Page::statusCorrupted] fields: align, textalign, position

Looks like somehow something is corrupt. But I don't have any idea why and how to fix it.

Link to comment
Share on other sites

On 9/21/2018 at 10:46 PM, Dennis Spohr said:

I just tried it. On a clean install (3.0.98) it works like it should be. 

19 minutes ago, Dennis Spohr said:

If I use $pages->clone($mypage) I get this error:

Quote

Exception: Can’t save page 0: /ma/.../video/: Call $page->of(false); before getting/setting values that will be modified and saved. [Page::statusCorrupted] fields: align, textalign, position

Looks like somehow something is corrupt. But I don't have any idea why and how to fix it.

If it works on a clean install there is something else causing this problem. Most likely there's a hook somewhere that does additional things on Pages::saved or Pages::saveReady; This can be either in ready.php or in any of your modules. I'd start by commenting out all the content of ready.php, then disabling all modules one by one (by adding a dot in front of the folder name).

If anything of that works you can begin to narrow it down in that area.

Link to comment
Share on other sites

Backup your data.

Look at your table "pages" and sort by page status. I guess you'll find some pages having status 13x.xxx (cant remember the exakt code, it's something over 130k). try to set page status to 1 and see if that make a difference.

Where do you clone your page? In a module? Inside Tracy? In a template?

Link to comment
Share on other sites

Finally I was able to reproduce the problem on the clean install of ProcessWire. It seems to be a problem with a SelectOptions-FIeld, when no value is set.

I did the following on the clean install:

  • Create a new SelectOptions-Field with some values in it.
  • Assign the field to a template
  • Create a new Page of this template using the API:
$mypage = new Page();
$mypage->template = 'basic-page';
$mypage->parent = $pages->get(1);
$mypage->title = 'TEST';
$mypage->save();

print ($mypage->id);
  • Copy the ID of the new page and do the following:
$mypage = $pages->get(1042);
$pages->clone($mypage);
  • While doing this I get this exception:
Quote

Error: Exception: Can’t save page 0: /test-1/: Call $page->of(false); before getting/setting values that will be modified and saved. [Page::statusCorrupted] fields: images, selectoptions (in D:\xampp\htdocs\pw-test\wire\core\PagesEditor.php line 515)

selectoptions is the name of my SelectOptions-Field. Settings $page->selectoptions = ''; seems to create the same problem (no value set).

I don't think this should be the expected behavior?

Link to comment
Share on other sites

That's not true, please could you prove your statements with screenshots or the like and not just tell "it's not working"?

JhH03nV.png

And the current DEV:

e6FFrag.png

Recursive:

nmgaMfo.png

Quote

Thank you very much for all your help and support! I will check with the latest developer-version.

You're welcome ? Yep, no reason not to use it IMHO.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...