Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$page->setAndSave() does not work for "parent" #719

Closed
processwired opened this issue Oct 6, 2018 · 6 comments
Closed

$page->setAndSave() does not work for "parent" #719

processwired opened this issue Oct 6, 2018 · 6 comments

Comments

@processwired
Copy link

processwired commented Oct 6, 2018

Short description of the issue

This does not work – the parent does not get saved.
$page->setAndSave('parent', 3);

In contrast to this, the following works:
$page->setAndSave('sort', 3);

Both properties are native properties of the page, so this is somewhat inconsistent.

Expected behavior

$page->setAndSave() should work with "parent" as first parameter.

Optional: Suggestion for a possible fix

In the head of /wire/core/Page.php is a definition of $settings:

/**
* Page-specific settings which are either saved in pages table, or generated at runtime.
*
* @var array
*
*/
protected $settings = array(
    'id' => 0,
    'name' => '',
    'status' => 1,
    'numChildren' => 0,
    'sort' => -1,
    'sortfield' => 'sort',
    'modified_users_id' => 0,
    'created_users_id' => 0,
    'created' => 0,
    'modified' => 0,
    'published' => 0,
);

'parent' is missing here for no obvious reason. I did a test and added the line 'parent' => 0, to the array. $page->setAndSave('parent', 3); seems to work then.

Forum thread

Setup/Environment

  • ProcessWire version: 3.0.115
ryancramerdesign added a commit to processwire/processwire that referenced this issue Nov 29, 2018
@ryancramerdesign
Copy link
Member

Thanks i've pushed an update for this. The issue is that the Page::save() method was checking if the property was valid for the pages table in the database, and 'parent' is a runtime object, so not a valid property in the DB table (whereas 'sort' is). I don't think the valid check is needed in the save() method() as it's going to interfere with saving of other properties using setAndSave() as well, so I have just removed the check.

@netcarver
Copy link
Collaborator

@processwired Can this be closed now?

@netcarver
Copy link
Collaborator

/remind me to review and close if necessary in 1 week

@reminders reminders bot added the reminder label Feb 8, 2019
@reminders
Copy link

reminders bot commented Feb 8, 2019

@netcarver set a reminder for Feb 15th 2019

@reminders reminders bot removed the reminder label Feb 15, 2019
@reminders
Copy link

reminders bot commented Feb 15, 2019

👋 @netcarver, review and close if necessary

@netcarver
Copy link
Collaborator

Closing due to inactivity. Feel free to leave comments or open new issue if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants