Jump to content
Dennis Spohr

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

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks, I will look into this thead - however I don't understand why it's working on the ProcessWire Admin. It seems that it should work and I'm doing something different than the admin.

Thanks for mentioning the child()-function 😉

Share this post


Link to post
Share on other sites

imho it should work, maybe you can try it on a clean installation?

  • Like 1

Share this post


Link to post
Share on other sites

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

My other installation has the same version. I don't have any idea why it doesn't work there.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I removed my ready.php and removed all modules in my site/modules folder. But nothing changed.

Is it possible that something is corrupted? Because of this part in the error message:

Page::statusCorrupted] fields: align, textalign, position

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

I was able to solve one of the problems. For a field of type Select Options I was setting a value which was not existing.

When I'm doing the page-clone now, I don't get any error anymore.

But still, the repeater-fields don't get copied.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

I cannot confirm that. Everything is working as expected:

jrynb4N.png

NDMVFi7.png

oBhwRpu.png

s0dL0P1.png

ProcessWire 3.0.114

 

 

Share this post


Link to post
Share on other sites

yes:

bx1jiXW.png

But it works if I do what the error says: Calling $pages->of(false) before:

LT71NxR.png

Share this post


Link to post
Share on other sites

 

Quote

But it works if I do what the error says: Calling $pages->of(false) before:

Yes, but it does not work if you have child-pages with a SelectOptions-Field.

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

Share this post


Link to post
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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...