Jump to content

Uploading images via API 'Pageimages: Removed' issue


a-ok
 Share

Recommended Posts

Folks. Hope everyone is well.

I'm attempting to move some Tumblr content to PW using the API. I have the below, which seems to work fine, except even though the images are uploaded (they appear in the appropriate assets/files/** folder), when I go to edit the page the images are all removed with the message Pageimages: Removed 'images' temp file(s) for page...

Any thoughts where I'm going wrong?

$url = $config->paths->templates . "tumblr/posts/posts.xml";
$xml = simplexml_load_file($url);

$i = 0;
foreach ($xml->posts->post as $post) {

	bdb($post);
	$attributes = $post->attributes();

	$date = $sanitizer->date($attributes["unix-timestamp"]);

	$text = str_replace('</p>', '', $post->{"photo-caption"});
	$text = explode('<p>', $text);

	$title = $sanitizer->text($text[2]);
	$description = array_slice($text, 3);

	$p = new Page();
	$p->template = "blogSingle";
	$p->parent = "/blog/";

	$p->of(false);

	$p->title = $title;
	$p->date = $date;

	$descriptionString = '';
	foreach ($description as $d) {
		$descriptionString .= "<p>" . $d . "</p>";
	}
	$p->textarea = $descriptionString;

	$p->save();

	if (count($post->photoset) > 0) {
		foreach ($post->{"photoset"}->{"photo"} as $images) {
			$image = $sanitizer->url($images->{"photo-url"}[0]);
			$p->images->add($image);
			$p->save();
		}
	} else {
		$image = $sanitizer->url($post->{"photo-url"}[0]);
		$p->images->add($image);
		$p->save();
	}

	$p->save();

	$i++;
	if ($i == 2) break;

}

 

Link to comment
Share on other sites

25 minutes ago, psy said:

@a-ok try adding $p->of(false); before adding the image. You've included output formatting off above when creating the page, but then the page is saved which automatically turns it on again.

@psy Many thanks for the help. It doesn't seem to make a difference unfortunately. Hmm...

Link to comment
Share on other sites

13 hours ago, a-ok said:

$p->images->add($image);

What happens if you replace this with the hardcoded url in the tracy example?

Just replace block after block with working snippets and you'll find the problem or can at least narrow down where it is and tell us more about it ? 

Link to comment
Share on other sites

1 hour ago, bernhard said:

What happens if you replace this with the hardcoded url in the tracy example?

Just replace block after block with working snippets and you'll find the problem or can at least narrow down where it is and tell us more about it ? 

Thanks, @bernhard – I did this and it added the images (visible in the folders within assets) but upon visiting it in the backend they were removed with the same message 'Pageimages: Removed 'images' temp file(s) for..'

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...