Jump to content
hus

Changing creator

Recommended Posts

Is there a solution to make a search/replace in the System Field «creator» outside php myAdmin? I should change the creator ID for a great amount of pages.

Thanks for your help.

Hansueli Schiller

Share this post


Link to post
Share on other sites

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 3

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...