ProcessWire 2.6 RC1 (2.5.29) and more

ProcessWire 2.6 RC1

We just pushed ProcessWire 2.5.29 to the dev branch, and this should be considered the first release candidate (RC1) of ProcessWire 2.6. Ideally this will be our only release candidate and it can be merged to the master branch is 2.6 next week. However, we could use your help with a little bit of last minute testing.

If you've got the bandwidth, please grab ProcessWire 2.5.29, test it out, and let us know how it goes by replying to this post. If everything runs perfectly, we'd love to hear that! Likewise, if you run into some issues, we'd love to hear that too.

  • New installations and upgrades of existing sites are of equal interest and please indicate which you tested.
  • If an existing site upgrade, please indicate which version you upgraded from.
  • If testing with a new installation, please indicate which site profile was used.
  • If using multi-language support please indicate that too.
  • If you run into any issues, please tell us what PHP version and what other 3rd party modules you have installed.

Thanks for your help testing! If we can get an all-clear with no major issues over the next few days, we'll plan to release early next week.

What's new this week (ProcessWire 2.5.29)

What's new? Not a lot actually, and that's a good thing. When ready to put out a major release, you don't want to have a lot of change, because all new code needs testing. So the ideal situation is to have the code base just sit for a week without the need for any changes. That's not what happened this week, though it was close.

Last week we introduced some new ways that you can use WireCache (the $cache API variable), but there was one part of it that I had wanted to finish and didn't get time to. Specifically, it was support for page selectors in cache expiration. To put it another way, I wanted to be able to tell WireCache this:

Cache this content and consider it valid until a page matching my criteria is saved.

Prior to this week, the only "criteria" that you could specify (beyond dates/times) was a single page template. Meaning, you could make a cache automatically expire once a page using a certain template was saved. That's really useful, but not enough.

Now you literally can specify any criteria that can be matched by a single in-memory selector string that matches pages. Specify that selector string as your "expires" argument rather than a date, quantity of seconds, or template.

For example, lets say that you want to generate a cache that expires any time a page having the homepage as its parent is saved… perhaps to cache the markup of primary navigation:

echo $cache->get("topnav", "parent=/", function($pages) {
  foreach($pages->get('/')->children as $item) {
    echo "<li><a href='$item->url'>$item->title</a></li>";
  }
}); 

Something to mention is that in-memory selector strings aren't quite as capable as the more commonly used database-driven selector strings. You don't have things like OR-groups or sub-selectors, among others for example. If you need to do something with this selector string that the in-memory selector isn't allowing, you can always map a database selector to a page selector like this…

$items = $pages->find("company=[locations>5, locations.title%=Finland]");
echo $cache->get("cache-name", "id=$items", function() {
  // ...
}); 

…however, hopefully the new built-in selector string support in $cache will serve the vast majority of needs one could have for cache expiration.

ProcessWire and PHP's interactive mode

You may already be familiar with WireShell, which is a great command-line companion to use with ProcessWire. But did you know that you can use the entire ProcessWire API from the command line without anything more than the core? This is admittedly something very different from WireShell, but can be very handy during development if you want to quickly test out API commands without having to edit, save and then run a PHP script. Here's how to use it:

1. To get things started, you need to be in a Terminal window at a command prompt. This can either by on a web server through SSH, or directly on your computer.

2. Change to the directory where you have ProcessWire installed. For the site I'm working on now, that's: htdocs/tripsite/ so I type:

cd htdocs/tripsite/

3. Now run PHP as an interactive shell:

php -a 

The command above will put you in PHP's interactive shell, waiting for your command, which looks like this below:

Interactive shell
php > 

4. From here you can do anything that you can in PHP. Since we're wanting to use ProcessWire's API, we'll go ahead and bootstrap ProcessWire, just by including its index.php file:

php > include("index.php"); 

Note that the php > is not something that you have to type. That is simply PHP's command prompt that appears on every line in the interactive shell automatically. I'll just leave it out of the remaining examples for brevity.

5. With ProcessWire bootstrapped, now you can run any PW API commands that you wish. For instance, lets say that we want to list the titles (one per line) of all pages with the "basic-page" template, sorted by title:

echo $pages->find("template=basic-page")->implode("\n", "title");

How about the last 10 modified page URLs with user that modified them:

echo $pages->find("limit=10")->each("{url} mod by {modifiedUser}\n");

6. Commands can span more than one line. Lets say that we want to add a new "basic-page" beneath the homepage:

$p = $pages->add('basic-page', '/', 'new-page-name');
$p->title = 'My New Page';
$p->save();

8. Remember the __debugInfo() methods we implemented a couple weeks back, that enables you to print_r() any PW object? They come in particularly handy in command line mode:

print_r($pages->find("template=basic-page")); 

Here's the output:

PageArray Object
(
  [items] => Array
    (
      [0] => /about/
      [1] => /about/background/
      [2] => /about/updates/
      [3] => /about/analysis/
      [4] => /about/disclaimer/
      [5] => /about/hello-there/
      [6] => /new-page-name/
    )
  [count] => 7
  [total] => 7
  [start] => 0
  [limit] => 0
  [selectors] => template=basic-page, status<1024
)

Next you might try doing a print_r() on one of those individual Page objects to see what's in it.

print_r($pages->find("template=basic-page")->first()); 

I'll leave the output for you to test on your own.

This interactive shell isn't anything new, but I've lately found it very handy during development, so figured I would pass it along for those that didn't already know about it.

What is new is that you can use ProcessWire's API variables directly in the shell. For example $pages rather than wire('pages'). This was added to ProcessWire's index.php file a few dev versions back. If you are using an older version of ProcessWire, you'll still need to use the wire() function to access API variables. If you are using the latest ProcessWire, then make sure your index.php file is up-to-date so that you can access PW's API variables directly.

What if to doesn't work?

My understanding is that PHP's interactive mode may not always work on Windows systems due to some platform limitations (though someone correct me if I'm wrong), so you may have to limit your usage to your web servers, Linux and OS X machines.

In my OS X environment using MAMP, the php command was actually pointing to one that comes with OS X (/usr/bin/php) rather than the one that MAMP installed. I managed to get into the interactive shell, but as soon as I typed include("index.php"); I'd get a MySQL exception, as OS X's PHP doesn't know about MAMP's MySQL. I got around that by aliasing the php command to point to MAMP's PHP rather than mine. If you have a similar need, edit the .bash_profile in your home directory (i.e. /Users/your-name/.bash_profile), and add the following to it:

alias php="/Applications/MAMP/bin/php/php5.6.2/bin/php"

Your MAMP PHP version may be different than mine, so you might want to head on over to that directory first to make sure it lines up with yours. Once you've saved your .bash_profile file, close the terminal window or type source .bash_profile in the Terminal window to reload it. Now when you type php in the terminal, it should map to MAMP's copy and enable you to use PHP's interactive shell with ProcessWire (or whatever else you'd like).

Lastly, when ready to leave the interactive shell:

php > quit

Comments

  • Michael Rockett

    Michael Rockett

    • 9 years ago
    • 32

    Hi Ryan. Great to see 2.6 nearing stable!

    I'm having an issue with one particular installation that will be going live today. The issue is with regards to a gallery template that's using a normal images field type. On my local server (which is very fast), image uploads seem to take forever. If I drop 30 images onto the field, 30 green bars appear, the most of which say "100%". Then I have to wait for a few seconds, and then it appears. I have made sure thumbnails are turned off, which would normally explain the processing time.

    It also seems to be the only field that does it. My home template with a different image field has no problem. Interestingly, if I create a field with the exact same config on an RC1 testing space, the images upload very quickly.

    I'm going to test it out on other browsers now, and see if I can pin-point the issue's source.

    Do you think this could be a PW issue?

    Thanks for all the great work, Ryan. :)

    • ryan

      ryan

      • 9 years ago
      • 32

      Glad to hear RC1 is working well with it. But if you are uploading 30+ images at once, I'd honestly be surprised if it wasn't taking a few seconds after upload. Depending on the size of the images, that's a lot of data to validate and move around even if thumbnails don't have to be generated. Keep in mind also that those images have to then re-load in your browser (client side). Since you aren't generating thumbnails, it has to send all the image data back to you so that it can display it. For 30 images from a typical digital camera, you might be talking about 90+ megabytes of data transfer, going in both ways. If you've got enough simultaneous connections at once, it won't be able to show you those images until an open connection is available (which is why you might observe a "100%" upload bar for a significant amount of time).

  • Horst

    Horst

    • 9 years ago
    • 32

    Uups, sorry, broken content. Please read on here:
    https://processwire.com/talk/topic/9807-using-php-pw-in-an-interactive-shell-on-windows/

  • slkwrm

    slkwrm

    • 9 years ago
    • 22

    Thanks for your reply, Ryan.

    An example when this thing with PageTable could be handy is when
    1) pages are used as pre-definded building blocks and put in a PageTable field
    2) and you want users to be able to edit those blocks/pages via PageTable but don't want them to add new ones.

    Now, when I think about it, if users can't add new pages to PageTable, they probably shouldn't be able to delete them as well, so you could have a rigid structure of pages/blocks that can't be broken.
    I guess this usage example outgrows what PageTable was initially designed for, so please don't bother about the whole thing - I will use hooks in this case.

    1) Yes, putting _init.php in sub-folder works (I use config->prependTemplateFile). I should have checked it in recent version before asking. Thanks!

    2) Yes, I use Markdown in description field. I just have a lot of fields that have square meters (m2) in description which I use to render measure units of my fields in front-end - and currently they look a little ugly for editors)

    3) View page in a new window in pageList view - I, personally, prefer the way it works now as well, and agree with you), but I once had this asked from a user - using a hook solved it.

    4) I think I wasn't clear enough in my first post. What I meant is a sticky footer which keeps down if the content is not enough to fill the height of a page. I would also add here forced vertical scroll bar as I think it's not visually pleasant how page twitches due to scroll bar appearing when you have page list unfolding.

    Cheers!

  • Nico

    Nico

    • 9 years ago
    • 22

    Quick note on the interactive PHP mode: It's not working if you have a compiled php version without "readline extension". So for example XAMPP will not work.

  • ryan

    ryan

    • 9 years ago
    • 32

    Either your PHP Version is before the PHP 5.6 where __debugInfo() was added, or your PW version is not the latest. The output in your video shows what print_r() looks like on a PageArray in versions of PW prior to 2.5.28 or in PHP versions prior to 5.6.

  • Pierre-Luc

    Pierre-Luc

    • 9 years ago
    • 11

    Typos are ok, I just want to avoid having everything getting changed in some part of PW. :)

  • Horst

    Horst

    • 9 years ago
    • 22

    You can mimic this, for example on windows, very easy like this:

    1) create a php file, here named "pwphp.php", with this content:

    |--[pwphp.php]------------------------------------------------->

    • ryan

      ryan

      • 9 years ago
      • 22

      Thanks for your feedback. If your Template and PageTable settings aren't in compliance with one another, it's true that it won't be able to work properly. Much of these things are hookable, so it's still going to try in case something overrides the behavior when the conditions are right. But in your case you'll want to update that template family settings so that it can work properly with your PageTable field. If the template you are using needs to have that limitation for another reason, it would be better to setup another template for PageTable to use.

      Thanks will take a look at those icons. Most likely something about the format is not recognized by PHP, since other transparent PNGs work, but we'll give it a try.

      1) This is already supported. See Setup > Templates > any template > Files. It's okay to precede your filename with a subdirectory.

      2) We use Markdown for this. Currently only inline markdown tags are supported, since description and notes are technically paragraph elements.

      3) This would drive me crazy, but I suppose it can be configurable like anything else. Will give it some thought, thanks.

      4) We'll leave this for other admin themes to explore. I'm not sure we've got anything useful enough in our footer to warrant it taking up a permanent 30+ pixels height of every viewport.

      • slkwrm

        slkwrm

        • 9 years ago
        • 22

        Hi, Ryan.

        First of all, thank you for you hard work. It's great to see how PW gets stronger with every release. I haven't been doing any webdev-related work for a long time until recently, but still was following forums and reading your updates here.

        Not so long ago I got a request for a small project, which I started implementing with PW, and I must say I'm very excited about the whole thing. Gonna try to use some new features in this projects.

        So here's the problems (bugs) I found recently:

        1) a button allowing to add new pages is available in pageTable field, even if the template of the items has the option “Can this template be used for new pages?” set to “No”. When trying to add a page, an empty window pops up. (tested on fresh dev)
        2) cropping icons from http://www.flaticon.com/packs/ (transparent png) results in black background. I saw a similar issue has been fixed not so long ago, but in this case it still doesn’t work for me (tested on fresh dev).

        Both of the above are by mo means urgent - found them while testing new things)

        Feature requests (maybe in later versions):
        1) allow placing prepended/appended files (_init.php _main.php) to templates/subfolder
        2) parse safe html tags in field's description (field's notes as well?) in back-end.
        3) add an option to open pages in a new window in pageList view just as it has been recently added to pageEdit.
        4) keep page footer in default admin theme pressed to the bottom of the page - arguable, but makes sense for me, especially in pagelist view.

        Have a good day!

        • BernhardB

          BernhardB

          • 9 years ago
          • 22

          did a very short 1:30 screencast. what's wrong with my print_r() setup?

          http://screencast-o-matic.com/watch/coheXgff2l

          • ryan

            ryan

            • 9 years ago
            • 22

            I don't think there will ever be a string freeze just because things like fixed typos don't need testing. However, it's unlikely that any text will be changing at this point, but just don't want to make any promises in case a new typo turns up or something.

            • Pierre-Luc

              Pierre-Luc

              • 9 years ago
              • 22

              Is the feature freeze also a "string" freeze? I want to carve out some time and would like to do it all in one go, so I'd prefer to wait until it's in its final state. Thanks!

              • Can

                Can

                • 9 years ago
                • 11

                Just dived more into WireCache and the expiration rules, amazing Work! I really love it!!

                Before I stumbled over the getFor function (Namespaces) I just prefixed the cache name with something so I could get("prefix*") to delete all those at once
                So now I could define a namespace as prefix right? Is there any difference?

               

              NextProcessWire 2.6 is here!

              12

              Today I’m proud to announce that ProcessWire 2.6 has been officially released. After 30 releases of our dev branch over 7 months, we are now at our most solid version ever: ProcessWire 2.6. More 

              Latest news

              • ProcessWire Weekly #519
                In the 519th issue of ProcessWire Weekly we'll check out a new third party module called RockForms, introduce the latest ProcessWire core updates, and more. Read on!
                Weekly.pw / 20 April 2024
              • ProFields Table Field with Actions support
                This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
                Blog / 12 April 2024
              • Subscribe to weekly ProcessWire news

              “ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer