Jump to content

[solved] required fields for successful import using API?


neosin
 Share

Recommended Posts

I've imported a batch of data but for whatever reason when switching language on the site, I can't get the other language data to appear.

The data exists and is editable in the admin but even editing & re-saving the record data has no effect to make it display.

To do a test I created a page along the imported records in the admin under the parent I need it in and this page displays proper data in both languages.

There must be a setting or field required that I forgot to add to make it work properly?

Here is the import script loop

$fr = $languages->get("fr");
while($row = $result->fetch_assoc()) {
	$program_id = wire("sanitizer")->text($row['program_id']);
	$p = wire('pages')->get("template=legacy-programs,program_id={$program_id}"); 
	$title_en = \Encoding::toUTF8($row['title_en']);
	$title_fr = \Encoding::toUTF8($row['title_fr']);

	if($p->id > 0){
	  // Item exists, was it updated?
	  if($p->date_updated != date('Y-m-d H:i',strtotime($today))){
		  $p->of(false);
		  $p->title = $title_en;
		  $p->setLanguageValue($fr,'title',$title_fr);
		  $p->program_id = $program_id;
		  $p->setName($program_id);
		  $p->setName($program_id, 'fr');                                           
		  $p->save();
	  }else{
		  continue;
	  }
	}else{
	  // Item doesn't exists, create it.
	  $p = new Page();
	  $p->template = "legacy-programs";
	  $p->parent_id = 2245;
	  $p->of(false);
	  $p->title = $title_en;
	  $p->setLanguageValue($fr,'title',$title_fr);
	  $p->program_id = $program_id;
	  $p->setName($program_id);
	  $p->setName($program_id, 'fr');
	  $p->save();
	}
}

This work great in the admin, I can see the data and edit it but for some reason it will not display the french version fields on the front end.

The records show that they are published and visible/searchable in record settings.

Link to comment
Share on other sites

Are the other languages active? on the settings tab of the page? You should set the status for each language to active during the import. Or after the fact you can do with the AdminActions module's "Page Active Languages Batcher" feature.

 

  • Thanks 1
Link to comment
Share on other sites

7 minutes ago, adrian said:

Are the other languages active? on the settings tab of the page? You should set the status for each language to active during the import. Or after the fact you can do with the AdminActions module's "Page Active Languages Batcher" feature.

 

aha yes I see that the "active" is not checked for the url of the french versions.

I thought this was only for the URL when visiting that link, so I was under the impression the data would still be accessible/visible.

thank you for the quick diagnosis much appreciated

 

if anyone else is curious or needs details on setting active by API

 

  • Like 1
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...