Sign in to follow this  
cosmicsafari

Page save() method dying without output?

Recommended Posts

Hi all,

Im a bit confused by an issue I have come across today.

I have a module which connects to a third party (once an hour using LazyCron), parses a publicly available XML file, turns it into useable information which I then use the API to save as PW Pages.

On the whole this has been working great however today I noticed that it kept failing on one of the imports.

After doing some investigation I realised its appears to be dying at the save page stage.

From the documentation $page-save() should return either True/False, so I thought I would update the code to reflect this while debugging.

$this->log(1);
$bool = $p->save();
if($bool){
  $this->log('Saved successfully');
} else {
  $this->log('Fail to save');
}
$this->log(2);

However the script only gets to the save() part and then appears to terminate. Then when checking the error log the latest entry is always just '1'

Any ideas as i'm a tad confused why I at least don't get a response of some kind?

 

 

 

Share this post


Link to post
Share on other sites

Not sure, but I would first of all look at the XML file. Has anything changed recently? What happens if you "manually" grab the XML, and update/create page(s)?

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the reply but I think I have sussed it, not sure why it was never an issue up to this point right enough.

I updated my code from above to try:

$this->log(1);
try {
     $p->save();
} catch (\Exception $e) {
     $this->log($e);
}
$this->log(2);

Which gave me an error mentioning using $p->setOutputFormatting();

So I updated to

$this->log(1);
try {
     $p->setOutputFormatting(false);
     $p->save();
} catch (\Exception $e) {
     $this->log($e);
}
$this->log(2);

Which appears to have fixed the issue.

:)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By phillipschmitz
      500 Error after the latest Core Update.
      I have no idea why and what causes the problem, or how to solve it. (Maybe reupload the wire folder?)

       

      Any ideas? 
    • By noelboss
      Hi, I'm stuck since hours and don't know what to do. Here is my Problem:
      I try to generate Previews of PDF using imagick. I have 4 PDF, I generate a preview of the first page of the pdf, save it to a temporary file and want to import it using the api into an image field. It works for the later 3 pdf but not the first. I add it to the image field and save it. Inside the function that saves it, the image is stored in 'data' as well as in 'itemsAdded' but as soon as i leave the function, its nowhere to be found.
      Process:
      1. create previewimage using imagick and create Pageimage > works
      2. add image to filed 'filepreviews', returns Pageimages array with image added > okay
      3. save page > returns true
      4. Outside renderPreview method, image is not anymore in 'filepreviews'
      // mymodule // … // foreach($files as $file){ $preview = wire('page')->filepreviews->get('name*='.$file->basename(false)); // if there is no preview image… if (!$preview instanceof Pageimage) { $this->renderPreview($file) // we create one using $this->renderPreview > should return true on successful save dump(wire('page')->filepreviews); // my Image is nowhere to be found $preview = wire('page')->filepreviews->get('name*='.$file->basename(false)); } // end for each // render a preview of an otherwhise not supported file format // return true if sucessfull save private function renderPreview($file) { $page = wire('page'); // get path to temporary image $tempFile = $path.$file->basename(false).'-preview.jpg'; // … some imagick code // … and save it: $imagick->writeImage($tempFile); $img = new Pageimage($page->filepreviews, $tempFile); $img->description = $file->basename(false); // destroy temp image unlink($tempFile); // this is my Pageimage, all good… dump($img); // save image, my Pageimage can be found in data and itemsAdded – all good dump($page->filepreviews->add($img)); $page->of(false); $success = $page->save(); // sucess = true dump($success); return $success; }
       
      Second question:
      Would there a generally better approach? Like using pageFiles somehow. Goal is to be able to use the image api like scale etc – I don't generally need the images to be stored in an image field.
       
    • By matsn0w
      Hey everyone, hope you're all doing well!
      I'm building my first ProcessWire website at the moment, which is of course a very good way to understand all of the possibilities ProcessWire has to offer. But that also means that I'm facing some troubles now and then, and so is the case right now.
      I made a template for a couple of pages, like the homepage, the contact page, etc. I am using Bootstrap 4.0 for the layout. 
      So here's the deal: I want to show an alert box on top of every page, warning the user that the website is still under construction. Of course, I can just include the code and add the fields I made for the alert into the template, but that means I have to do that for every page, which I obviously don't want. So I made a template with the code and fields for the alert. When I did this, I realised that I can create multiple alerts this way, so I made two pages, containing different alerts. (And converted the code into a foreach-loop in the template).
      But now my question; how can I include these pages in a different template? Can I make a field or something to insert a page or is this simply not possible? Or do I have to approach this in a different way?
      I hope I explained my problem clear!
      Thank you in advance,
      matsn0w
    • By rareyush
      I am using new processwire and I am receiving this error in my _func.php
       
      Parse Error: syntax error, unexpected 'return' (T_RETURN) Parse Error: syntax error, unexpected '$out' processwire anyone knows anything ??