Jump to content

ZGD

Members
  • Posts

    52
  • Joined

  • Last visited

Posts posted by ZGD

  1. I've been using PW for a few years now and I believe this is the only problem I frequently encounter, although this latest case is particularly relevant. I'm sure there must be a simple solution, but I've yet to work it out.

    Thanks to a great collaboration with a member of the community, we have a website (still in development...) that imports data from an external service into PW via a JSON feed. The import process can create hundreds of pages with new images that are saved from URLs specified in the feed. As these can be very high resolution, we use the $image->size() method to resize them to acceptable dimensions.

    As this import process is happening constantly in the background, images on certain pages are constantly changing. This means a large number of images may not have variants generated until that page is visited by a user, and that process can take quite a while. Some pages have 50+ images (lazyloaded!).

    What is the normal way of solving this problem? I'd considered writing a module that would imitate a user visit to these pages each time they are saved and thus generate the variants. Is there a simpler solution?

  2. Sorry adrian, you're right, I don't know why I mentioned $file->title! $file returns the filename, I must have been thinking of that. Updated question with strikethrough. 

    No errors, and filesize($file->filename) also returns nothing unfortunately. Code below from the module:
     

    public function ___execute() {
    
        // this will be dynamic later
        $fieldname = "image";
    
        $old_name = "";
        $pagesWithImages = wire('pages')->find($fieldname.".count>0, sort=title");
        $allImages = array();
    
        foreach($pagesWithImages as $p) {
            $imagedata = $p->get($fieldname);
            if (is_array($imagedata)) {
                foreach($imagedata as $image) {
                    $allImages[] = $image;
                }
            } else {
                $allImages[] = $imagedata;
            }
        }
    
        $out .= "<h3>".count($allImages)." images found.</h3>";
        if (count($allImages)) {
            $adminURL = $this->config->urls->admin;
            $table = $this->modules->get('MarkupAdminDataTable');
            $table->setEncodeEntities(false); 
            $table->headerRow(array(
                $this->_x('Page', 'list-table'), 
                $this->_x('Filename', 'list-table'), 
                $this->_x('Filesize', 'list-table')
                ));
    
            foreach ($allImages as $i) {
                $pg = $i->page;
                $pagelink = "<a target='_blank' href='".$adminURL."page/edit/?id={$pg->id}'>".$pg->title." (".$pg->id.")</a>";
    
                $filesize = filesize($i->filename);
    
                $table->row(array(
                    $pagelink,
                    $i,
                    $filesize
                )); 
            }
            $out .= $table->render();
        }
        return $out;
    }
  3. I'm currently building a module that checks image filesizes and returns a list of those that match some specific criteria. The list needs to be accessible from a page the module installs under the admin Setup page.

    However I seem unable to access $file->filesize within an admin template. I can access other properties, like $file->title and $file->page. I've used the same code to echo a list of filesizes from an array of files on the frontend and it works perfectly. Is this normal behaviour?

  4. I'm creating a simple module for hooks, but have run into a small problem.

    The hook is basically to keep two fields in sync. I have two templates "template1" and "template2" each with a Page Field that references the other. So a page using "template1" has a Page Field that contains multiple pages using "template2", and a page using "template2" has a Page Field that contains multiple pages using "template1".

    I'm hooking Pages::saveReady to detect any pages added/removed from the Page Field on either of these templates, and then adding/removing the relevant pages from the other's Page Field. However as each hook saves other pages before it saves itself, I assume this will create some kind of loop? The actual code is more complex, but I've tried to give some example code below:
     

    public function init() {
        $this->addHookBefore('Pages::saveReady', $this, 'save');
    }
    
    public function save($event) {
    
        $page = $event->arguments[0];
    
        if ($page->template->name == "template1" || $page->template->name == "template2") {
            $clone = clone($page);
            $this->pages->uncache($clone);
            $prev = $this->pages->get($clone->id);
    
            $prev_related = $prev->related_pages;
            $page_related = $page->related_pages;
    
            $deleted_ids = array_diff($prev_related->explode('id'), $page_related->explode('id'));
            $added_ids = array_diff($page_related->explode('id'), $prev_related->explode('id'));
    
            $pagesToSave = new PageArray();
    
            foreach($added_ids as $added_id) {
                $added = $this->pages->get($added_id);
                if (!$added->relatedPageField->has($page)) {
                    $added->relatedPageField->add($page);
                    $pagesToSave->add($added);
                }
            }
    
            foreach ($deleted_ids as $deleted_id) {
                $removed = $this->pages->get($deleted_id);
                if ($removed->relatedPageField->has($page)) {
                    $removed->relatedPageField->remove($page);
                    $pagesToSave->add($removed);
                }
            }
    
            $this->message("saving ".count($pagesToSave)." pages.");
            foreach ($pagesToSave as $pageToSave) {
                $pageToSave->save();
            }
    
        }
    }
    
  5. We're looking for someone to complete two Processwire modules for us. One is half built but needs added functionality, the other would be a new module completely. Looking for the work to be completed ASAP.

    The first module syncs pages/fields with a simple JSON feed. This one is half built, at the moment the sync works for adding new/editing existing records found, but has no way of deleting previously added pages if the associated record is removed from the feed.

    The second module will need to use the Instagram API. We need a field that will accept an Instagram shortcode or URL and then use the API to save the timestamp/text/image etc for that post into the site database.

    If anyone could help with either of these or if you have further questions, please post here or send a PM and I'll get back with details.

  6. Any known limitations with the number of pages/fieldtypes? I'm trying to export a CSV of 400 pages, 25 fields per page. Field types include Title, Checkbox, Page, Text, Options, Page, MapMarker, Textarea, Image, Rangeslider, Datetime and Options.

    Exporting a CSV seems to fail, no error message/log as far as I can see though.

  7. Thanks adrian, the users have very restricted access to non-sensitive information for this one, it's more of a formality really. I will definitely be using ForcePasswordChange for future projects though, super easy to manage users through PW with these kinds of modules.

    • Like 1
  8. Very strange indeed, I'd checked it multiple times, but copy pasting the email address back into the same input seems to have fixed it. I have no idea what happened there, but thanks for suggesting to check it once again.

    I have one other question regarding using this in conjunction with Ryan's Import Pages from CSV module. I have a test CSV with 4 columns (title,displayname,email,roles) and 5 rows. I'm trying to import multiple users and have EmailNewUser auto-generate a password for each, it works successfully for the first user/row, but then I get the error "No email was sent to the new user because either their email address or password was not set." after that, I'm assuming because of line 137 (although I'm not sure if it's because of the email or password being blank? Has anyone successfully managed to do this?

    EDIT: Seems if I include the 'pass' column, and use "" as the value for each row, it works!

    • Like 1
  9. Hi, I'm consistently getting the error: 

     No email was sent to the new user because of an unknown problem. Please try the 'Re-send Welcome Message' option.

    I'm assuming this is a server configuration problem, does anyone have any idea how to go about rectifying/troubleshooting this?

    EDIT: Really strange, if I hardcode the 'from' email address into line 141 instead of using the passed variable (which as far as I can see is exactly the same) it works correctly.

×
×
  • Create New...