hus Posted October 10, 2019 Share Posted October 10, 2019 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 Link to comment Share on other sites More sharing options...
dragan Posted October 10, 2019 Share Posted October 10, 2019 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 4 Link to comment Share on other sites More sharing options...
adrian Posted October 10, 2019 Share Posted October 10, 2019 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)); } 1 Link to comment Share on other sites More sharing options...
dragan Posted October 10, 2019 Share Posted October 10, 2019 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 More sharing options...
adrian Posted October 11, 2019 Share Posted October 11, 2019 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 More sharing options...
hus Posted October 12, 2019 Author Share Posted October 12, 2019 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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now