Jump to content
ryan

PW 3.0.137 – Core updates

Recommended Posts

Core version 3.0.137 on the dev branch adds the ability to hook multiple methods at once, in a single call. This post details how it works and provides a useful example of how you might put it to use in your development environment. This version also refactors and improves upon several core classes—

https://processwire.com/blog/posts/pw-3.0.137/

  • Like 18
  • Thanks 1

Share this post


Link to post
Share on other sites

On-demand mirroring of remote web server files to your dev environment 😍😍😍

  • Like 3

Share this post


Link to post
Share on other sites
1 hour ago, wbmnfktr said:

On-demand mirroring of remote web server files to your dev environment 😍😍😍

This is so good! I need to study hooks more deeply. :) 

  • Like 1

Share this post


Link to post
Share on other sites

Hi @ryan,

On 8/3/2019 at 11:14 AM, wbmnfktr said:

On-demand mirroring of remote web server files to your dev environment 😍😍😍

This is indeed an ingenious little helper! Thx for sharing this idea with us!

One problem though: When I'm only in the backend, the url and filename methods get never called. Could you please make the setFilename method hookable so that this method also works when the page is just edited in the backend? It would then only need this simple hook and all files are downloaded on demand:

$wire->addHookAfter('Pagefile::setFilename', function($event) {
  $file = $event->object->filename();
  if(!file_exists($file)) {
    // download file from source if it doesn't exist here
    $src = 'https://example.com/site/assets/files/';
    $url = str_replace($this->config->paths->files, $src, $file);
    $http = new WireHttp();
    $http->download($url, $file);
  }
}); 

Or is there a better way of doing it?

  • Like 7

Share this post


Link to post
Share on other sites

@ryan any news on this? It works really great in my setup and I think this approach can open up a lot of great options for a better DEV/LIVE workflow with processwire. In my current project where I modified the core file it was really just doing a

git clone myrepo.git
git submodule update --init --recursive
# restore db dump

And I had a working copy of the site that downloaded all assets on demand while working with it! This is really awesome but it would break on every core update. I could implement some hack that does a str_replace and file_put_contents in my dev environment to prevent updates breaking this feature, but it's really just adding three underscores to one core file thanks to the ingenious hook system 🙂 

PS: I've created an issue for this: https://github.com/processwire/processwire-issues/issues/954

  • Like 2

Share this post


Link to post
Share on other sites

@bernhard Making it hookable should be fine. But I'd like to better understand what you mean about it not working in the admin, and the url and filename methods never getting called? Are you using the core files/images field? Those methods/properties are the ones used for anything asking for the filename or url of a file, whether on the front-end or in the admin. For me at least, it works the same in the admin/page editor as it does on the front-end, just tested again to confirm—editing a page downloads the images, and they appear in the images field in the page editor. So I'm not sure I understand what you mean? Also, hooking setFilename() would make it less on-demand, as it would download any images in the field rather than only those that were specifically requested. Can you think of anything different about your environment that might account for it not working?

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.

×
×
  • Create New...