Jonathan Lahijani Posted June 30, 2023 Share Posted June 30, 2023 I find myself continuously running various commands that interface with ProcessWire while developing a site. For example, I may want to delete all the orders in the ecommerce site I'm currently developing. My approach for a while has been to have a bunch of 1-off PHP scripts that I'd run (either via command line or through a link since it's publicly accessible), but I was wondering if there's a more formal way to do this with ProcessWire. Laravel has Artisan, Craft CMS has Console Commands for example. I think wire shell (wtf the forum software keeps breaking this word up) solved this but it's abandoned (sadly). Any recommendations? Link to comment Share on other sites More sharing options...
Robin S Posted June 30, 2023 Share Posted June 30, 2023 31 minutes ago, Jonathan Lahijani said: My approach for a while has been to have a bunch of 1-off PHP scripts that I'd run Tracy Debugger's Console panel can execute any PHP that you would otherwise run from a .php file. You can type code directly into the Console window, or if you prefer to code in your IDE you can save .php files to /site/templates/TracyDebugger/snippets/ and then run them from the Console panel. I also like to use custom actions for Admin Actions for more complicated or lengthy code, or for when I want to set various parameters using PW inputfields. 5 Link to comment Share on other sites More sharing options...
flydev Posted July 1, 2023 Share Posted July 1, 2023 (edited) Some time ago, I forked wire shell and renamed it WireChief to avoid the ads made on the defunct domain name. It was designed primarily to create pw/vite applications (the latter is about to be released). Also, I haven't looked at @bernhard’s RockShell, but maybe I'll switch to it. Edited July 1, 2023 by flydev RockShell 2 Link to comment Share on other sites More sharing options...
bernhard Posted July 1, 2023 Share Posted July 1, 2023 Definitely RockShell! It's super easy to use, works great with RockMigrations ("php rockshell db-pull" is all you need) and it is extremely easy to create custom commands: PS: If somebody wants to get personal support by me and in return help writing the docs let me know! 1 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 1, 2023 Share Posted July 1, 2023 I've just added a demo command that shows how one can add custom commands to their modules: https://github.com/baumrock/RockMigrations/commit/cce0d062d422a7e2b58815c61c5433eee0f65c71 It's also now possible to add commands to /site/assets/RockShell/Commands The idea was to build the foundation and make it super easy for others to contribute commands that we all need. I'm using it every day and alone the "db-pull" command is worth it. I've also updated the readme. Everything should be quite obvious now. 4 1 Link to comment Share on other sites More sharing options...
flydev Posted July 1, 2023 Share Posted July 1, 2023 For those who was using wire shell in the past and will send PR to rockshell, there is some handy ideas. 2 Link to comment Share on other sites More sharing options...
bernhard Posted July 1, 2023 Share Posted July 1, 2023 Thx for your screenshot! Looks like we should maybe change the syntax for commands from dash (db-pull) to colon (db:pull) to get the grouping? 2 Link to comment Share on other sites More sharing options...
teppo Posted July 1, 2023 Share Posted July 1, 2023 1 hour ago, bernhard said: Thx for your screenshot! Looks like we should maybe change the syntax for commands from dash (db-pull) to colon (db:pull) to get the grouping? It does look cleaner, especially if there can be multiple dashes in the command, making the syntax somewhat ambiguous. The only CLI tool I'm really familiar with is WP-CLI, and there the namespace is separated by a space, e.g. "wp db export dump.sql" or "wp db import dump.sql". Anyway, just wanted to drop in to say that I'm really happy to hear that RockShell is alive and actively developed. I've not used it myself yet (and I never really got into wireshell, typically just ran commands through Tracy's console or via one-off PHP files that bootstrap PW), but I've been using WP-CLI a lot recently. Probably should dig into RockShell as well ? 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 2, 2023 Share Posted July 2, 2023 Haha, turns out I only had to change one setting in RockShell to use colon instead of hyphen when loading the commands and it beautifully groups them into their namespaces ? 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 2, 2023 Share Posted July 2, 2023 15 hours ago, teppo said: but I've been using WP-CLI a lot recently What did you use it for? Also I'd be curious what others have been wire shell for? The most important and helpful commands in RockShell have been pw:install and db:pull and both seem not to be part of wire shell. On the other hand I've never ever had the need to do something like field:create or template:create so I wonder why they are there? Maybe that's something that's only useful if you are not using RockMigrations? Link to comment Share on other sites More sharing options...
flydev Posted July 2, 2023 Share Posted July 2, 2023 1 hour ago, bernhard said: both seem not to be part of wire shell. In wire shell no, but wirechief contain them and more, like pw:restore native:restore (mysqldump), duplicator:restore (working with packages), etc. My screenshot do not reflect the current version. Almost all commands contains subcommands depending on the arguments given. Too much to be listed here without spamming the thread. 1 hour ago, bernhard said: Maybe that's something that's only useful if you are not using RockMigrations I dont use migrations everywhere and the cli tool allow, for example, to create templates, fields and assiging them in seconds, or installing pw and a specific profile from the terminal without writing any code, its time saver, like artisan. Keep in mind that the tools is born 8 years ago and abandoned since 4y. 2 Link to comment Share on other sites More sharing options...
teppo Posted July 2, 2023 Share Posted July 2, 2023 6 hours ago, bernhard said: What did you use it for? Flushing caches and rewrite rules after each deploy Exporting database from production and importing it locally (sometimes, very rarely, the other way around) Editing (and sometimes just listing and filtering) users, posts/pages, rewrite rules, plugins... Managing (listing and running) registered cron jobs Managing translations Those are the most common things I use it for, ordered from most common to least common ? Looking at the commands currently available for RockShell, "db:pull" and "db:restore" seem like they could be most useful for me personally. I'm not entirely convinced about the method used there, though, considering that it needs to store temporary dump file(s) on the disk. Seems to me that using mysqldump and redirecting the output to local disk has certain benefits over this — such as eliminating the need for temporary files, and thus also eliminating any chance of multiple simultaneous pulls causing conflicts. "pw:users" could be useful as well, but if there's no way to filter users or define which fields to display, the use cases seem somewhat limited. In comparison WP-CLI makes it possible to filter users by specific fields (very handy on larger setups), and there are commands for creating users, setting field values, making bulk edits, etc. (Considering the big picture, instead of grouping "users" under "pw" as a single command, it might make more sense to define "users" or "user" as a namespace and "list" as a single command under that namespace.) Link to comment Share on other sites More sharing options...
bernhard Posted July 2, 2023 Share Posted July 2, 2023 1 hour ago, teppo said: Looking at the commands currently available for RockShell, "db:pull" and "db:restore" seem like they could be most useful for me personally. I'm not entirely convinced about the method used there, though, considering that it needs to store temporary dump file(s) on the disk. Seems to me that using mysqldump and redirecting the output to local disk has certain benefits over this — such as eliminating the need for temporary files, and thus also eliminating any chance of multiple simultaneous pulls causing conflicts. You mean to stream the output of mysqldump directly to the local dev environment? Didn't know that this was even possible, but it sounds like what you are saying makes sense ? If you want to improve that command I'd be happy to accept a PR ? For bigger teams that would definitely be an improvement. In my scenarios it was never an issue though as it is very unlikely that two people do a db:pull at the same time and really causing a serious problem. But unlikely is not impossible, so having a better solution would be great! 1 hour ago, teppo said: Flushing caches and rewrite rules after each deploy Exporting database from production and importing it locally (sometimes, very rarely, the other way around) Editing (and sometimes just listing and filtering) users, posts/pages, rewrite rules, plugins... Managing (listing and running) registered cron jobs Managing translations Similar needs here. Flushing cache is done by RockMigrations in my case, but I have thought about that already, just did not have the time/need for it in the end. Export/restore DB: Need that all the time. What I'd love to have is a db:push command but for the time being it was always easier and more secure to do that manually. Editing users/posts/pages etc: Never had that need, I'd be happy to hear examples. The only thing that I needed was changing/resetting user's passwords, which is possible via user:pass Cron jobs? How does that work? I'm doing that via my server control panel. Managing translations? That's another topic ? 6 hours ago, flydev said: duplicator:restore (working with packages) As far as I understand you could simply ship your duplicator module with some RockShell commands and once both modules are installed you would have the commands available to your rockshell CLI ? Link to comment Share on other sites More sharing options...
teppo Posted July 2, 2023 Share Posted July 2, 2023 22 hours ago, bernhard said: You mean to stream the output of mysqldump directly to the local dev environment? Yes. Current approach makes use of ProcessWire's database export feature and I'm not sure if it can do this (from what I can tell this is not really what it was meant to do; it was rather intended to store the dump "permanently"), so this might need to be a different command. Just like flydev mentioned above (native:restore). Personally I don't see much reason to use the ProcessWire db export method in this context, unless it does something special that mysqldump can't do (?). 22 hours ago, bernhard said: Editing users/posts/pages etc: Never had that need, I'd be happy to hear examples. The only thing that I needed was changing/resetting user's passwords, which is possible via user:pass Various reasons for this. Resetting passwords is one, but I've also had to remove users matching specific conditions or temporarily disable their accounts, update categories for posts (e.g. a main category is removed and all posts that belonged to it need to be connected to a new one), automate some content modification for a number of pages matching specific criteria, etc. In WP it's not as easy to create "bootstrap scripts" as it is in PW, so WP-CLI is (in my opinion) often the easiest way to do any sort of bulk edit ? 22 hours ago, bernhard said: Cron jobs? How does that work? I'm doing that via my server control panel. This is where differences between WP and PW matter. WP has a built-in cron task queue: the core maintains a list of registered tasks (some from core itself, others registered via hooks from theme(s) or plugins). Each task has a set recurrence (interval), a precalculated time for next run, and hook function to trigger when the task is due. WP-CLI can be used to trigger a specific task, run all tasks that are due now, etc. By default tasks are executed "lazily", similar to what ProcessWire does when using Lazy Cron, but typically you would not want to rely on that or slow down page views for regular users. Instead you'd set up a real cron job to run e.g. once per minute. That cron job then executes "wp cron event run --due-now --quiet". I don't say this often, but in this area WP is — in my opinion — ahead of PW. The cron setup makes a lot of sense, and it's really easy to keep track of active tasks ? 1 1 Link to comment Share on other sites More sharing options...
flydev Posted July 2, 2023 Share Posted July 2, 2023 Made you a small screencast @bernhard to get an idea. This version works fine with php-8.1. Enregistrement #59.mp4 Enregistrement #60.mp4 5 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