Jump to content
marcus

wireshell - an extendable ProcessWire command line interface

Recommended Posts

Re: scrolling

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

Seeing this on Safari too. Appears randomly, can't see any obvious pattern here.

The joy of debugging front-end issues.

Share this post


Link to post
Share on other sites

Safari. Of course. This browser is such a catastrophe. Will check soon!

Regarding patterns: Seems to be an issue which container is focused on scroll event; either body (lighter grey) or the navigation (darker grey).

Edited by marcus

Share this post


Link to post
Share on other sites

Regarding patterns: Seems to be an issue which container is focused on scroll event; either body (lighter grey) or the navigation (darker grey).

Yes, except clicking on the nav doesn't seem to give it focus.

Share this post


Link to post
Share on other sites

First, let me thank Marcus for wireshell.

I have installed on both linux and windows machines, and I'm seeing a small glitch in windows.  The little checkmark by superuser role in a user list doesn't display properly in windows but does on linux.  How would I find out the keycode for the checkmark?   When I look in the src for UserListCommand, I just see a non-printable box in windows, but see the checkbox in linux.

My windows environment is using xampp and git-bash shell.  I see the same garbage characters on w7 or w10, and in the dos command window, git-bash, or the xampp shell.

tia,

Share this post


Link to post
Share on other sites

Well, I know more about utf-8 and windows now.  I figured out its a utf-8 heavy check mark code e2 9c 94 (thank you, vim)

My google research hints it may be a windows/unicode/command line problem, apparently there are issues with the command line and unicode.

I'm not going to worry about this minor glitch any longer.

Share this post


Link to post
Share on other sites

wireshell 0.5.1 
 
Changelog

  • Adds log:tail command including filters --limit=, --text=, --from=, --to=
  • Adds log:list command
  • Improves new command, support for site profiles (path/to/profile.zip OR one of beginner, blank, classic, default, languages), autocompletion for timezone
  • Adds field:list command including filters --all, --template=, --type=
  • Adds list field:types command
  • Extends field:create command, allow custom field types
  • Extends new command: adds ability to specify version of ProcessWire --dev, --devns, --sha=
  • Extends upgrade command: adds ability to specify version of ProcessWire --dev, --devns, --sha=
  • Removes unnecessary empty state checks
  • Removes command aliases for better list overview #36
  • Fixes wrong iso format
  • Improves changelog format
  • Adds field commands field:delete and field:tag
  • Adds tag option for field:create command
  • Extends user:create command, ask for password and email address
  • Extends backup:db command, add option --target

... and there is a brand new documentation! If you use the develop branch, there is another documentation branch.
Furthermore all the documentation files are inside the repository, everybody can easily edit them. It's written in markdown and uses a post commit hook to build the documentation. 

  • Like 10

Share this post


Link to post
Share on other sites

quick installation question: I was able to get wireshell working globally on root but would prefer it to work for another user but couldn't work it out.

Share this post


Link to post
Share on other sites

That's probably a include path or permission issue within your operating system rather than an issue of wireshell. Composer does use a specific folder to install global packages and this does need to be included in your users path variable and you need to have permission to execute files in that folder.

  • Like 2

Share this post


Link to post
Share on other sites

Before I install Wireshell I have a question: Can I use WS to batch set a field to a specific value on all pages using a specific template?

Share this post


Link to post
Share on other sites

Not sure if wireshell does allow for that, but if not you could go that way. 

> php -a
php> include "index.php";
php> $pages->find("template=some_template")->each(function($p){ $p->setAndSave("field", "value"; });
  • Like 3

Share this post


Link to post
Share on other sites

I managed to install wireshell via composer, but am stuck trying to run "new" command. I am getting this:

post-2275-0-10646500-1456146757_thumb.pn

What can it be?

Edit: Could not find any documentation or examples of "new" command other than inline help. Is there any?

Edited by Ivan Gretsky

Share this post


Link to post
Share on other sites

here is the documentation. I'll try to reproduce this error..

Edit: For me everything works as expected.

Edited by justb3a
  • Like 1

Share this post


Link to post
Share on other sites

Could you please try: 

❯ curl -I https://raw.githubusercontent.com/ryancramerdesign/ProcessWire/master/wire/core/ProcessWire.php

What does this return? The error message occurs, if this curl request returns a state not equal to 200.

Edit: This error message contains now more detailed information, there will be also an option `-v` to increase the verbosity of messages  (coming soon):

 [RuntimeException]
 Error loading sha `xxx`, curl request failed (status code: XXX).
 Try `curl -I https://raw.githubusercontent.com/ryancramerdesign/ProcessWire/xxx/wire/core/ProcessWire.php`
 This should return `HTTP/x.x 200 OK`.
Edited by justb3a
  • Like 1

Share this post


Link to post
Share on other sites

I am on windows so no CLI cURL available. Could this be the problem? I have it through php extension though.

Should I install cURL to check the connection?

Edit:

I used git bash, which has in-built cURL and ran

curl -I https://raw.githubusercontent.com/ryancramerdesign/ProcessWire/master/wire/core/ProcessWire.php

as you suggested. I got 200 OK status.

Running

wireshell new

there still returns the same error.

Edited by Ivan Gretsky

Share this post


Link to post
Share on other sites

Here's what I did to install wireshell on windows 10 and xampp

* Download composer-setup.exe and install it.  Identify \utl\xampp\php\php.exe* composer global require wireshell/wireshell* Add %USERPROFILE\AppData\Roaming\Composer\vendor\bin to user PATH (in system properties, environment variables)* Run wireshell.
  • Like 1

Share this post


Link to post
Share on other sites

Could you please check whether the php curl extension is enabled? It seems that it comes with xampp but isn't enabled by default (I don't use xampp so this is just a guess). 

Have a look at your php.ini, uncomment the following line:

;extension=php_curl.dll

Restart your Apache server and check your phpinfo() to see whether curl has been properly enabled or not.

  • Like 1

Share this post


Link to post
Share on other sites

1) Thanks for trying to solve my problem!

As I wrote, I got php_curl enabled. It is listed in phpinfo() output.

I am able to execute another commands like wireshell status or wireshell t:l on my local PW 2.x installations.

2) I get error

Error:  Call to undefined function Wireshell\Helpers\wire() (line 69 of C:\Composer\vendor\wireshell\wireshell\src\Helpers\PwConnector.php)

trying to run those command on PW 3.0.8. I do not know, if it is known, so decided to mention it.

Share this post


Link to post
Share on other sites

One more idea. Maybe it's a SSL certificate problem. Could you try to copy this cert to such a location (you need to adapt the path): /Applications/AMPPS/extra/etc/openssl/certs/cacert.pem.

Then update php.ini and restart Apache:

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo="/Applications/AMPPS/extra/etc/openssl/certs/cacert.pem"
openssl.cafile="/Applications/AMPPS/extra/etc/openssl/certs/cacert.pem"

Found on stackoverflow.

I extended the error message again, added curl_error() output. Could you please pull the develop branch, test again and paste the error message?

  • Like 1

Share this post


Link to post
Share on other sites

Thank you very much, Bea! The develop version of the script does show the more verbose message

[RuntimeException]
Error loading sha `master`, curl request failed (status code: 0, url: https://raw.githubusercontent.com/ryancramerdesign/ProcessWire/master/wire/core/ProcessWire.php).
cURL error: SSL certificate problem: unable to get local issuer certificate

...and your solution does fix the problem like a charm)

Not sure what it all means though :). Need to research all that SSL thing.

Share this post


Link to post
Share on other sites

One more simple question. Sorry if it has been answered before.
I am using MySQL with root user and no password. Is there a way to not use a password during installation via wireshell?

Share this post


Link to post
Share on other sites

New version 0.6.0 brings an improved new command and a  brand new module:upgrade command. I've been missing this for a very long time and finally I managed to implement it. 

 
Check if module upgrades are available.
$ wireshell module:upgrade --check

An upgrade is available for:
  - FlagPages: 0.0.8 -> 0.2.3
  - ImageExtra: 0.0.1 -> 0.0.3

Download and upgrade existing module.

$ wireshell module:upgrade ImageExtra

An upgrade for ImageExtra is available: 0.0.3
Downloading module ImageExtra...
  840.40 KB/840.40 KB ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓  100%

 Preparing module...

 Module ImageExtra downloaded successfully.

Module `ImageExtra` was updated successfully.
  • Like 6

Share this post


Link to post
Share on other sites

Regarding 2): wireshell 0.X.X is not yet ready for PW 3.X

Any  timescales on PW3 compatibility?

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...