Jump to content

Admin Actions


adrian

Recommended Posts

Small update that:

1) lets you add:

protected $noBackup = true;

to your action class to prevent backups (either automatic or from showing the option to backup). This is handy if your action doesn't do any DB writing in which case a backup isn't relevant.

2) lets you populate:

$this->output = 'Content for output';

to your executeAction() method. Whatever content is in this will be returned before $this->successMessage and won't be formatted with the green background. This is useful if your action queries and displays info.

Hope you guys find these useful.

 

PS - still waiting on the first PR for a user contributed action :)

  • Like 1
Link to comment
Share on other sites

EDIT: Solved this by myself, see bottom of the post.

Hi @adrian First of all, this is a really great and useful module. I want to submit the id of a page to my custom module, but I don´t want to show up the id as a field that is being shown. Right now I call the module via 

admin-actions/options?action=BewerbungsunterlagenAnfordern&id=1514

And this is my defineOptions function

        protected function defineOptions()
        {
            $missingFiles = array();
            foreach ($this->pages->get("/unterlagentypen")->children as $unterlage) {
                $missingFiles[$unterlage->id] = $unterlage->title();
            }


            return array(
                array(
                    'name' => 'missingFiles',
                    'label' => 'Fehlende Unterlagen',
                    'description' => 'Wählen Sie aus, welche Unterlagen noch benötigt werden.',
//                    'notes' => 'Only use one of "Pages" or "User Roles"',
                    'type' => 'AsmSelect',
                    'options' => $missingFiles,
                    'required' => true,
//                    'requiredIf' => 'pages=""'
                ),
                array(
                    'name' => 'id',
                    'label' => 'ID der Bewerbung',
                    'description' => 'Bitte den Inhalt dieses Feldes nicht ändern.',
                    'type' => 'Text',
                    'required' => true,
                ),

            );

        }

How can I hide the ID Field?

Just set the type to "hidden" and Voilá :)

  • Like 1
Link to comment
Share on other sites

@adrian Hi Adrian,

here are two thoughts how to improve this great module.
Remove the "<p>The '.$actionName.' action was completed successfully.</p>" in line 250 or only print it, if no custom successMessage was set.
Because one may only want to display his own messages.
Use ProcessWires $this->message or $this->error function instead of an own messaging function, so it has the "native" ProcessWire behaviour that people are used to
 

Link to comment
Share on other sites

Hi @jmartsch - good idea - I have changed it so that message is only displayed if there is no custom message defined.

As for using $this->message or $this->error - I don't see any reason why you can't already use those if you prefer - please test and let me know. The reason I went with the other approach is to allow for a larger and more obvious response than the standard PW message/error interface provides.

If you need any additional tweaks on this front, please detail them out for me. I didn't spend a lot of time on this part of the module because it was initially designed for superuser use, although I am myself starting to make actions available to other roles, so I would like to improve this experience.

Cheers,
Adrian

Link to comment
Share on other sites

@adrian Your addition with the permission "admin-actions-hide-menu" hides the menuitem for the specific role/user, but it also disables the access to the module for this user group. I logged out and in again. If I remove the permission for the role, I can access the module.

Link to comment
Share on other sites

@adrian It would be nice if you add an option to hide the "Action Code" fieldset. Maybe make it only visible to superusers. But I think an option to hide it for all users would be better.

EDIT: Because it really is not important and irritating to normal users when this is being shown.

Link to comment
Share on other sites

5 hours ago, jmartsch said:

@adrian Your addition with the permission "admin-actions-hide-menu" hides the menuitem for the specific role/user, but it also disables the access to the module for this user group. I logged out and in again. If I remove the permission for the role, I can access the module.

Ah, you're right - sorry about that - shouldn't do things in a rush. I think I am going to remove that option from the module completely. I'll see if I can find some time to answer the issue of hiding menu items another way in your other thread.

3 hours ago, jmartsch said:

@adrian It would be nice if you add an option to hide the "Action Code" fieldset. Maybe make it only visible to superusers. But I think an option to hide it for all users would be better.

EDIT: Because it really is not important and irritating to normal users when this is being shown.

It is only visible for superusers - is it still an issue for you knowing that?

Link to comment
Share on other sites

2 minutes ago, adrian said:

Ah, you're right - sorry about that - shouldn't do things in a rush. I think I am going to remove that option from the module completely. I'll see if I can find some time to answer the issue of hiding menu items another way in your other thread.

It is only visible for superusers - is it still an issue for you knowing that?

It would be nice to hide it from superusers as well, because superuser != programmer/developer

Link to comment
Share on other sites

On 3/21/2017 at 7:25 AM, jmartsch said:

It would be nice to hide it from superusers as well, because superuser != programmer/developer

Ok, there is now a new config option that needs to be checked to show the action code. 

 

On an unrelated note, I also revamped the recent $noBackup option. This is a breaking change, but now you can set:

protected $dbBackup = 'automatic' (or 'optional', or 'disabled') 

in your custom actions to override the default behavior as defined in the module config settings.

Hopefully this will be a helpful change.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

@adrian just asking... I am in the process of migrating 10+ websites to processwire and exporting and importing content works great so far, but in some fields old Smarty calls are present and I want to search and replace it with new Hannacode.

Unfortunately most of the affected content is in Profields Textareas and the admin action SearchAndReplace doesn't work there. All content is deleted...

Should it work in textareas or do you know of any quick fix ;) or snippet?

(BTW too many pages to it by hand)

Link to comment
Share on other sites

2 hours ago, Klenkes said:

@adrian just asking... I am in the process of migrating 10+ websites to processwire and exporting and importing content works great so far, but in some fields old Smarty calls are present and I want to search and replace it with new Hannacode.

Unfortunately most of the affected content is in Profields Textareas and the admin action SearchAndReplace doesn't work there. All content is deleted...

Should it work in textareas or do you know of any quick fix ;) or snippet?

(BTW too many pages to it by hand)

It shouldn't be hard to support. When I set this action up I limited it to text and textarea fields, but it makes sense to expand to others - I just didn't have time to test it then. I'll see what I can do tomorrow to get this working for you.

  • Like 1
Link to comment
Share on other sites

4 hours ago, Klenkes said:

Thanks, but no need to work witout pay on a sunday...

No problem - I'm used to it :)

I am away next week, so it's now or not for a while. I have committed a quick update that should take care of Profields Textareas. Please let me know if you have any problems.

I really need to revisit this action and add support for other field types as well - for example I haven't tested inside repeaters or page tables. I'll add this to my list, but might be a while.

  • Like 2
Link to comment
Share on other sites

Holy __insert-term-of-choice__  

This works absolutely great! I replaced stuff on hundreds of pages with textareas of type text and teatareas with CKE and didn't encouter one error!
Without BCE and the replace admin action this whole untertaking of migrating to PW wouldn't work at all!

I can't thank you enough.

  • Like 2
Link to comment
Share on other sites

  • 4 months later...

When I click on any of the actions in the list I get this:

Quote

Fatal Error

Call to undefined function token_get_all() search►

Source file

File: .../ProcessAdminActions/ProcessAdminActions.module:558



 
548: } 549: 550: 551: private function getActionName($className) { 552: return preg_replace('/(?<=\\w)(?=[A-Z])/'," $1", $className); 553: } 554: 555: 556: private function getFunctionCode($source, $functionName) { 557: 558: $tokens = token_get_all(file_get_contents($source)); 559: 560: for($i=0,$z=count($tokens); $i<$z; $i++) 561: if(is_array($tokens[$i]) 562: && $tokens[$i][0] == T_FUNCTION

Anyone know why

Link to comment
Share on other sites

@hellomoto - sorry you are having trouble. I honestly don't understand what you are seeing there. It doesn't seem like an error message. How/where is this appearing? Could you maybe send a screenshot of it?

What version of ProcessWire and PHP are you running?

Link to comment
Share on other sites

I've just pushed a new version of the Create Users Batcher which adds proper CSV parsing (so you can have commas, quotes, spaces etc in other user fields) - thanks to @Rudy for noting this deficiency.

I have also added the option to use JSON instead of CSV in case that is easier for your needs.

Creation now also supports image fields so you can use a URL to an image to have that added to the user's page.

  • Like 5
Link to comment
Share on other sites

  • 2 weeks later...
On 8/28/2017 at 5:53 PM, adrian said:

adds proper CSV parsing (so you can have commas, quotes, spaces etc in other user fields)

And today it worked for me flawlessly! A big thanks for this (and for all the other countless goodies you've shared with us....).

Just one question though, your note in the Role's block reads:
At least one of these roles must have the "profile-edit" permission so that the user can change their password the first time they log in.

The permission profile-edit is not needed if my client does not want users to change their passwords, right? At least for the time being users should not change their passwords, it is a feature we want to add later.

Edited by szabesz
fix
  • Like 1
Link to comment
Share on other sites

4 minutes ago, szabesz said:

And today it worked for me flawlessly! A big thanks for this (and for all the other countless goodies you've shared with us....).

Just one question though, your note in the Role's block reads:
At least one of these roles must have the "profile-edit" permission so that the user can change their password the first time they log in.

The permission profile-edit is not needed if my client does not want users to change their passwords, right? At least for the time being users should not change their passwords, it is a feature we want to add later.

Glad it worked so well for you!

The profile-edit permission I guess is not critical if you don't have the "Password Force Change" module installed, or if you are not relying on the "Email New User" module to automatically generate the user passwords. The thinking here is that you probably don't (or shouldn't) know the passwords of the users, so you use EmailNewUser to generate a password, but then you want to ensure they change it quickly because the password was included in an email (hence the use of PasswordForceChange). And to be able to change their password on first login, they need to be able to edit their profile.

I guess that wording needs to change to explain things better.

Any thoughts?

  • Like 1
Link to comment
Share on other sites

8 minutes ago, adrian said:

I guess that wording needs to change to explain things better.

I agree, this could be improved a bit, otherwise from the security standpoint you are – of course – right.

However, currently I need to "import" old users with passwords of the previous "old" site and their role does not let them do anything in the admin, they only have access to a custom "download page" to download some "semi sensitive" docs. This will change in the future and that is when the site will need "proper" user management.

Edited by szabesz
typo
  • Like 1
Link to comment
Share on other sites

18 hours ago, adrian said:

Taken care of with this commit:

Thanks @adrian :) 

Yesterday I actually "only" did some preliminary tests with around 50 users. It worked well but today I had to do the "real thing". I found that it was only about 33 users I could always create without timeout, more than that sometimes worked sometimes not. Since I had to deal with only about 150 users, I created them in groups of 33 or so, as I did not want to waste time with dealing with the timeout.

My other issue was that I had to deal with duplicate user names. The batcher – in such a case – fails with mysql error (...Duplicate entry 'super_duplex_user' for key 'name_parent_id'...) which is not too elegant :) I cleaned up the CSV to tackle this but was wondering if the script could look for them in advance? Is that out of the scope of this action?

Edited by szabesz
typo, missing chars and such
  • Like 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
×
×
  • Create New...