Jump to content

Changing creator


hus
 Share

Recommended Posts

There is an option in template settings (Advanced tab -> Template toggles -> Allow the 'created user' to be changed on pages).

After you activated this, you can use the API (inside a template or via Tracy Debugger console):

$p = $pages->get(11201);
d($p->created_users_id); // 41
$p->created_users_id = 10040;
$p->save();
d($p->created_users_id); // 10040

d() is dump command inside Tracy

  • Like 4
Link to comment
Share on other sites

Just to follow up on Dragan's code. To change the user via the API, you don't actually need to check the "allow the created user to be changed on pages" option.

I would also perhaps recommend a quiet save so that the modified date is not changed, eg:

$page->created_users_id = 1033;
$page->save('created_users_id', array('quiet' => true));

You can do this in the Tracy console while viewing or editing a page in the admin - $page refers to the current page being viewed or edited.

For doing this on multiple pages:

foreach($pages->find('myselector rules') as $p) {
    $p->created_users_id = 1033;
    $p->save('created_users_id', array('quiet' => true));
}

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, adrian said:

To change the user via the API, you don't actually need to check the "allow the created user to be changed on pages" option.

When I ran the code I posted above without the "allow..." check, funnily Tracy had output the new user ID, but when I re-opened the page in admin, the old created-user was still there. Kinda weird...

PW 3.0.138, advanced mode + debug mode on.

Anyway, maybe just a caching issue.

Link to comment
Share on other sites

20 hours ago, dragan said:

When I ran the code I posted above without the "allow..." check, funnily Tracy had output the new user ID, but when I re-opened the page in admin, the old created-user was still there. Kinda weird...

Not sure - I didn't rely on the output from Tracy - I just reloaded the page and looked at the created user on the Settings tab and it seemed to stick just fine. Curious to see what happens when @hus tries it.

Link to comment
Share on other sites

Thanks for your help. After activating the option in the template-settings I have taken a mouse-recording-tool with a loop (Automator/Mac) to do the job. It took about 5 hours to do the job for more than 1000 pages.

Next time, shure, I will use your code.

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