Jump to content
marcus

wireshell - an extendable ProcessWire command line interface

Recommended Posts

I am running version 5.4.37 on Mac 10.9. 

Ah, on said line is an PHP expression that only works on PHP 5.5. I guess I fixed it in the latest dev. You should be able to grab it via

composer global require wireshell/wireshell:dev-develop

Share this post


Link to post
Share on other sites

And now the next error:

composer global require wireshell/wireshell:dev-develop                                                                                           15:38:42

Changed current directory to /Users/lpa/.composer

./composer.json has been updated

Loading composer repositories with package information

Updating dependencies (including require-dev)

  - Updating wireshell/wireshell (0.4.0 => dev-develop 33ef0ed)

    Checking out 33ef0eda3d1b182c5c14a51603e80dd6cfe0d377

 

Writing lock file

Generating autoload files

 

wireshell

 

PHP Fatal error:  Can't use method return value in write context in /Users/lpa/.composer/vendor/wireshell/wireshell/src/Commands/User/UserListCommand.php on line 62

PHP Stack trace:

PHP   1. {main}() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:0

PHP   2. require() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:5

PHP   3. Composer\Autoload\ClassLoader->loadClass() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:0

PHP   4. Composer\Autoload\includeFile() /Users/lpa/.composer/vendor/composer/ClassLoader.php:301

 

Fatal error: Can't use method return value in write context in /Users/lpa/.composer/vendor/wireshell/wireshell/src/Commands/User/UserListCommand.php on line 62

 

Call Stack:

    0.0002     229376   1. {main}() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:0

    0.0005     246808   2. require('/Users/lpa/.composer/vendor/wireshell/wireshell/app/wireshell.php') /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:5

    0.1050    1695728   3. Composer\Autoload\ClassLoader->loadClass() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:0

    0.1050    1695880   4. Composer\Autoload\includeFile() /Users/lpa/.composer/vendor/composer/ClassLoader.php:301

Share this post


Link to post
Share on other sites

Dang! I missed one occurence of that error. Sorry. Please 'composer global require wireshell/wireshell:dev-develop' again, => dev-develop 88c5ae should now appear.

Share this post


Link to post
Share on other sites

And now:

PHP Fatal error:  Can't use method return value in write context in /Users/lpa/.composer/vendor/wireshell/wireshell/src/Commands/Module/ModuleDownloadCommand.php on line 81

PHP Stack trace:

PHP   1. {main}() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:0

PHP   2. require() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:5

PHP   3. Composer\Autoload\ClassLoader->loadClass() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:0

PHP   4. Composer\Autoload\includeFile() /Users/lpa/.composer/vendor/composer/ClassLoader.php:301

 

Fatal error: Can't use method return value in write context in /Users/lpa/.composer/vendor/wireshell/wireshell/src/Commands/Module/ModuleDownloadCommand.php on line 81

 

Call Stack:

    0.0002     229344   1. {main}() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:0

    0.0005     246776   2. require('/Users/lpa/.composer/vendor/wireshell/wireshell/app/wireshell.php') /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:5

    0.0726    1895576   3. Composer\Autoload\ClassLoader->loadClass() /Users/lpa/.composer/vendor/wireshell/wireshell/wireshell:0

    0.0727    1895736   4. Composer\Autoload\includeFile() /Users/lpa/.composer/vendor/composer/ClassLoader.php:301

Share this post


Link to post
Share on other sites

Sorry for being tester here. Please try again, you should catch commit 3ddb7a now.

Share this post


Link to post
Share on other sites

Yes, it works now! Thanks!

Share this post


Link to post
Share on other sites

Now just an annoying thing when I have notices on I get this on every command. Maybe I should set notices off. 

PHP Notice:  Undefined index: REQUEST_URI in /Library/WebServer/Documents/encanto/site/modules/HelperFieldLinks/HelperFieldLinks.module on line 37

Share this post


Link to post
Share on other sites

@lpa: looks like an issue with the Helper Field Links module, you might want to report it to Soma in the appropriate thread. It's incorrect behaviour to expect REQUEST_URI to always be present.

Share this post


Link to post
Share on other sites

For those who want to upgrade to the latest core version like me, I added the following command:

Common
 
Upgrade
 
Checks and optionally installs core upgrades.
$ wireshell upgrade
Available options:
$ wireshell upgrade --dev --just-check --just-download
Output Example
❯ wireshell upgrade

A ProcessWire core upgrade is available master 2.6.0

  Downloading ProcessWire Version 2.6.0...
    9.35 MB/9.35 MB ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓  100%

  Preparing new core version...

  Upgrade files copied.
  Installing new core files.

  Your index.php file is confirmed identical to the one included
  with ProcessWire version 2.6.0 so it should be safe to replace
  without further analysis.

  We have detected that your .htaccess file may contain site-specific
  customizations. Please double check before replacing it.

  Upgrade completed.
  Now double check that everything works.
  You have to replace htaccess.txt manually.

A lot of the code is taken from Ryan's ProcessWireUpgrade Module.

  • Like 3

Share this post


Link to post
Share on other sites

Bea's great contribution is now on dev :) Before it hits master, one thing though: When I tested it, I ran in some file permission problems. But I'm not sure whether it is connected to my particular setup, or MAMP.

It would be really great if some of you could grab the develop branch

composer global require wireshell/wireshell:dev-develop

and do a little test drive, and see if the updated PW installation throws a white page/500, connected to file permissions - or not. Cheers!

Share this post


Link to post
Share on other sites

Which files / folders cause the CHMOD issue? We should check this at the beginning, throw an exception or change the permissions on the fly. I guess the best approach would be to tell the users there are missing permissions and whether we should change them (using a prompt).

Share this post


Link to post
Share on other sites

It seems to be the wire folder, and the index.php in root. After upgrade they got 700 (wire) and 644 (index.php). Still, I'm not sure how general of a problem this is.
On alternative approach to your proposal is to chmod these files via PHP, wouldn't it?

Share this post


Link to post
Share on other sites

... or change the permissions on the fly.

means exactly  ;) :

On alternative approach to your proposal is to chmod these files via PHP, wouldn't it?

Share this post


Link to post
Share on other sites

means exactly  ;) :

Right, must have skipped that part while reading ;)

Share this post


Link to post
Share on other sites

Regarding this permissions-after-upgrade-issue, I just pushed a prompt to dev branch as you've suggested, b3a.

I'm still not sure whether I just tailored it for my setup and it's issues, or MAMP usage in general. Anyway, it should not hurt the command to have it there.

Share this post


Link to post
Share on other sites

Welcome, justb3a and clsource, as core contributors to wireshell! We got a dedicated GitHub organization now:  https://github.com/wireshell/wireshell - please update the remotes of your forks  :) Packagist reference is already updated, to the usual $ composer global require wireshell/wireshell will work like before.

The three of us are now toying around ideas how to improve wireshell, and one big feature would be if ProcessWire modules could provide their own wireshell commands (in addition to the wireshell core commands). We're not sure how to do this exactly, but maybe the PW community/module authors have ideas.

Our current scenario:
Besides from scanning its own /src/Commands folder for core commands (right now commands are hard-coded in /app/wireshell.php), thanks Stikki for the idea!, wireshell could search inside (ProcessWire's) /site/modules/ folder for commands provided by modules. So for example, alongside /site/modules/MyAmazingModule.module there can be a MyAmazingModuleCommand.php file (or commands, or "namespace" folder if there are more than one). The things bugging me here are a) dealing with dependencies and b) the exact details of "scanning for commands". But maybe someone could chime in here? I guess a concept of "PW module provided wireshell commands" would be a huge step forward (Drupal's drush already works this way, and makes it a really, really useful tool)

Edited by marcus
  • Like 3

Share this post


Link to post
Share on other sites

Hey @marcus 

Regarding the module downloads, I am not sure if you noticed my earlier posts

http://harikt.com/blog/2013/11/16/composer-support-for-processwire-modules/

http://harikt.com/blog/2013/11/19/composer-support-for-processwire-part-2/

That way we can install modules on the site/modules folder as we are doing with just composer.

I am also missing how processwire will support composer in the future, if anyone can give some insights / links it may also help.

EDIT : I am happy to change the vendor name and give to processwire if Ryan likes it.

Thank you

  • Like 2

Share this post


Link to post
Share on other sites

Hi Hari,

you're right - I read them back in 2013, but forgot until now - thanks!

Composer could be the solution here regarding dependencies  :) I'm also very interested in how PW3 will support it. The last PW blog post on this topic reads promising!

Share this post


Link to post
Share on other sites

Hey Marcus, 

Yes as dependency is a hell it is good to leave it to composer ;) . And as you know installing modules is simple as 

composer require <vendor/packagename>

The only thing to do is to keep a composer.json file for all the modules

{
    "name": "vendor/package-name",
    "type": "pw-module",
    "description": "Your module what it does",
    "keywords": [ "keywords", "comma", "seprated"],
    "homepage": "https://github.com/harikt",
    "license": "BSD-2-Clause",
    "authors": [
        {
            "name": "Contributors",
            "homepage": "https://github.com/harikt"
        }
    ],
    "require": {
        "hari/pw-module": "~0.0.1"
    }
}

and add to packagist. The only things to note in composer.json is the 

"type": "pw-module",

and 

"require": {
    "hari/pw-module": "~0.0.1"
}

We are all done. 

Happy PhPing!

  • Like 2

Share this post


Link to post
Share on other sites

Good morning, wireshell 0.5.0!

ws050-1.png

ws050-2.png

This great justb3a-driven update to wireshell add some more goodies to our little command line companion, such as:

  • ProcessWire core update via command line
  • Page command context: Create, List, Delete pages from wireshell, empty the trash. Listing can start at ID 1 or any other page/ID
  • Adds backups of image assets to backup command context
  • List all available templates, including system ones
  • Delete templates via wireshell
  • Clone fields via field:clone
  • wireshell runs now from everywhere within your PW installation, not just its root folder
     

As always, further documentation can be found on http://wireshell.pw

Keep in mind that we're still on a version number below 1, therefore in an experimental state - use wireshell with caution and backup before critical operations. Also, drop us a line if you run into dependency problems (such as trouble with symfony/console).

Happy CLIng!

  • Like 5

Share this post


Link to post
Share on other sites

Just noticed that there is a CLI Tool for ProcessWire, and even before giving it a try I just want to say *thanks* to the author.

CLI Tools, generators, preprocessors and stuff, modern web dev' & design is really helpful and the way to go.

\o/

  • Like 1

Share this post


Link to post
Share on other sites

Hey guys,

couple of notes:

- you haven't "released" the 0.5.0 on the GitHub, so composer tries to install 0.4.1

- on the site, the composer --globally link (in the install) has a couple of spaces between '00-intro' and '.md', so it 404s

- on the site, you don't see the whole navigation, and it isn't scrollable under 900px I think (as in: 1280x800 macbook :)

Also, I can't install 0.4.1 due to guzzlehttp/streams issue (I have global 3.0.0 installed); will wait vor the 0.5.0 version and report then if it doesn't work.

Thanks

Share this post


Link to post
Share on other sites

Thanks for the report on these issues. My bad. Version is now properly tagged. Regarding the scrolling issue on wireshell.pw: Odd, since it is overflow auto

edit: Broken link is fixed

Share this post


Link to post
Share on other sites

0.5.0 is now released  ^_^  Thanks for the hint.

I have no access to the site, therefore I'm not able to fix those issues.

edit: ... too slow^^

Share this post


Link to post
Share on other sites

Install:

Right, a global lumen installer from laravel requires guzzlehttp/*, but newer versions, so wireshell couldn't be installed (maybe a note in the docs?).

Thanks, guys

Re: scrolling

It might be just Safari, which seems to work in mysterious ways.

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.

  • Similar Content

    • By louisstephens
      Going through my long quest to get better with ajax and utilizing the api, I have hit yet another roadblock. I currently have a form with an image field (thanks to flydev for getting that sorted), "title" text input, and a select field set to multiple. In my ajax call, I added in:
      tags = $("#select-tags").val(); form_data.append('tags', tags); $.ajax({ type: 'POST', data: form_data, contentType: false, processData: false, url: '/ajax/upload-preview/', success: function(data) { console.log("Woo"); }, error: function(xhr, ajaxOptions, thrownError) { alert(xhr.responseText); } }); And in the ajax template: 
      $tags = $sanitizer->text($_POST['tags']); $image = $sanitizer->text($_POST['image']); $p = new Page(); $p->template = "preview"; $p->parent = $pages->get("/previews/"); $p->name = $title; $p->title = $title; $p->tags = $tags; $p->save(); If I select a "tag" from the select input and submit, it does indeed add it to the Page Reference field in the backend. However, this does not work with an array being passed to it of multiple options.

      So it does appear that my ajax call is trying to submit multiple options, but I am really just unsure how to get these two added in. I saw in other forums posts of add($page) and even add(array()). Do I need to handle this js array differently or do  I need to foreach through the $tags to add it like:
      foreach($tags as $tag) { $p->tags->add($tag); $p->save(); } I tried this approach, but apparently I am still missing something.
       
      Edit:
      I was doing some tweaking, and I know I can split the js array out like:
      for (i = 0, len = tags.length; i < len; i++) { console.log(tags[i]); } However, I am not sure then how to handle the POST in php if I were to split it out.
    • By louisstephens
      I have been messing around with creating pages from ajax requests, and it has gone swimmingly thus far. However, I am really struggling with creating a page and saving an image via ajax. 
      The form:
      <form action="./" role="form" method="post" enctype="multipart/form-data"> <div> <input type="text" id="preview" name="preview" placeholder="Image Title"> </div> <div> <input type="file" id="preview-name" name="preview-name"> </div> <div> <select id="select-tags" name="select-tags"> <?php $tags = $pages->find("template=tag"); ?> <option value="">Select Your Tags</option> <?php foreach ($tags as $tag) : ?> <option value="<?= $tag->name; ?>"><?= $tag->name; ?></option> <?php endforeach; ?> </select> </div> <div> <button type="button" id="submit-preview" name="submit" class="">Upload Images</button> </div> </form>  
      The ajax in my home template:
      $('#submit-preview').click(function(e) { e.preventDefault(); title = $("#preview").val(); image = $("input[name=preview-name]"); console.log(title); console.log(image); data = { title: title, image: image //not sure if this is actually needed }; $.ajax({ type: 'POST', data: data, url: '/development/upload-preview/', success: function(data) { console.log("Woo"); }, error: function(xhr, ajaxOptions, thrownError) { alert(xhr.responseText); } }); }); And finally in my ajax template:
      $imagePath = $config->paths->assets . "files/pdfs/"; //was from an older iteration $title = $sanitizer->text($_POST['title']); $image = $sanitizer->text($_POST['image']); $p = new Page(); $p->template = "preview"; $p->parent = $pages->get("/previews/"); $p->name = $title; $p->title = $title; $p->save(); $p->setOutputFormatting(false); $u = new WireUpload('preview_image'); $u->setMaxFiles(1); $u->setOverwrite(false); $u->setDestinationPath($p->preview_image->path()); $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf')); foreach($u->execute() as $filename) { $p->preview_image->add($filename); } $p->save(); I can complete the file upload but just using a simple post to the same page and it it works well, but I was really trying to work out the ajax on this so I could utilize some modals for success on creation (and to keep my templates a little cleaner). When I do run the code I have, a new/blank folder is created under assets, and a new page is created with the correct title entered. However, no image is being processed. I do get a 200 status in my console. I have searched google for help, but everything seems to be slightly off from my needs. If anyone could help point me in the right direction I would greatly appreciate it. 
    • By louisstephens
      This might be a completely dumb question, but I cant seem to wrap my head around it. I have a page reference field that allows users to select "Tags". In the front end I would like to use the titles as class names for a single item. ie:
      <?php $previews = $pages->find("template=preview"); ?> <?php foreach($previews as $preview): ?> <div class="tagOne TagTwo tagThree"> <!-- use another foreach to output--> <img src="<?=$preview->preview_image->url; ?>" /> </div> <?php endforeach; ?> I am little stumped as I know I need a foreach loop to produce each tag title, but how do I insert them all into one corresponding div class with spaces?
      Whelp, that was the easiest thing, but my brain just didnt "get it". Just put the foreach in the "class" inside of the overall foreach. Ugh 😓
    • By schwarzdesign
      We recently rebuilt the Architekturführer Köln (architectural guide Cologne) as a mobile-first JavaScript web app, powered by VueJS in the frontend and ProcessWire in the backend. Concept, design and implementation by schwarzdesign!
      The Architekturführer Köln is a guidebook and now a web application about architectural highlights in Cologne, Germany. It contains detailled information about around 100 objects (architectural landmarks) in Cologne. The web app offers multiple ways to search through all available objects, including:
      An interactive live map A list of object near the user's location Filtering based on architect, district and category Favourites saved by the user The frontend is written entirely in JavaScript, with the data coming from a ProcessWire-powered API-first backend.
      Frontend
      The app is built with the Vue framework and compiled with Webpack 4. As a learning exercise and for greater customizability we opted to not use Vue CLI, and instead wrote our own Webpack config with individually defined dependencies.
      The site is a SPA (Single Page Application), which means all internal links are intercepted by the Vue app and the corresponding routes (pages) are generated by the framework directly in the browser, using data retrieved from the API. It's also a PWA (Progressive Web App), the main feature of which is that you can install it to your home screen on your phone and launch it from there like a regular app. It also includes a service worker which catches requests to the API and returns cached responses when the network is not available. The Architekturführer is supposed to be taken with you on a walk through the city, and will keep working even if you are completely offline.
      Notable mentions from the tech stack:
      Vue Vue Router for the SPA functionality VueX for state management and storage / caching of the data returned through the API Leaflet (with Mapbox tiles) for the interactive maps Webpack 4 for compilation of the app into a single distributable Babel for transpilation of ES6+ SASS & PostCSS with Autoprefixer as a convenience for SASS in SFCs Google Workbox to generate the service worker instead of writing lots of boilerplate code Bootstrap 4 is barely used here, but we still included it's reboot and grid system Backend
      The ProcessWire backend is API-only, there are no server-side rendered templates, which means the only PHP template is the one used for the API. For this API, we used a single content type (template) with a couple of pre-defined endpoints (url segments); most importantly we built entdpoints to get a list of all objects (either including the full data, or only the data necessary to show teaser tiles), as well as individual objects and taxonomies. The API template which acts as a controller contains all the necessary switches and selectors to serve the correct response in <100 lines of code.
      Since we wanted some flexibility regarding the format in which different fields were transmitted over the api, we wrote a function to extract arbitrary page fields from ProcessWire pages and return them as serializable standard objects. There's also a function that takes a Pageimage object, creates multiple variants in different sizes and returns an object containing their base path and an array of variants (identified by their basename and width). We use that one to generate responsive images in the frontend. Check out the code for both functions in this gist.
      We used native ProcessWire data wherever possible, so as to not duplicate that work in the frontend app. For example:
      Page names from the backend translate to URLs in the frontend in the form of route parameters for the Vue Router Page IDs from ProcessWire are included in the API responses, we use those to identify objects across the app, for example to store the user's favourites, and as render keys for object lists Taxonomies have their own API endpoints, and objects contain their taxonomies only as IDs (in the same way ProcessWire uses Page References) Finally, the raw JSON data is cached using the cache API and this handy trick by @LostKobrakai to store raw JSON strings over the cache API.
      Screenshots














    • By VeiJari
      Hello forum!
      I've yet again stumbled on a head-scratching situation. We have enabled the option on our articles template and events template that it skips the title adding part and goes straight to the form. This is what our customer wants. So when you add a new article or event it automatically names it temporary to "article-0000000" and same with event. Now the problem is that obviously after saving the form we want to change to page url or "name" to the title, like it's normally. 
      Now here's the code for the hook:
      wire()->addHookBefore("Pages::saved(template=tapahtuma|artikkeli)", function($hook) {
        $page = $hook->arguments(0);
        $newUrl = wire()->sanitizer->pageName($page->title); // give it a name used in the url for the page
        wire()->log->message($page->name);
        $page->setAndSave('name', $newUrl);
      });
      I get the correct page and the name and path changes when I log them, but when I try to save it. It just loads and then I get: 
      Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) This happens in sanitizer.php
      and then another error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0
       
      What is happening? Am I not suppose to use sanitizer in this way? When we made a temporary page object in out other hook, the sanitizer worked perfectly.
      Thanks for the help!
×
×
  • Create New...