Jump to content

Recommended Posts

Posted

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

Posted

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
Posted

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 ?

Posted

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.

Posted

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.

Posted
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.

Posted

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

Posted

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?

Posted

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.

Posted

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?

Posted

 

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.

Posted

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

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...