Jump to content

Search the Community

Showing results for tags 'ImportPagesCSV'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 2 results

  1. This works for me to support page references in Ryan's ImportPagesCSV.module, in function importPageValue: elseif($field->type instanceof FieldtypePage) { $value = trim($value); if(wire("pages")->find("$name=$value")) $page->set($name, $value); } I need to also be able to import repeater fields though.. Anyone know how to do that?
  2. [Posted this in another post, but realized it's doesn't really pertain to it, so I've moved it to this new topic -- again sorry] Hi Ryan (and everyone else!), Just starting using PW and I'm loving it... I've got a site build that requires a bunch of CSV loading and would like some help with API Importing, as I am running into some glitches with page fields. So far I have a bunch of CSVs that work fine with my php code, but I have one that crashes, unless I put in the pageID. I think it may be something larger as I have tried using both BatchChildEditor & ImportPagesCSV modules with a modified CSV, and both get the same error as my code. So, here's my code, it does the following: Reads a page field to get CSV filename Reads 1st row of file to figure out what template and parent to use Reads 2nd row for field titles Processes the remaining rows as data, it also echoes out what it is doing -- not elegant, but it's only for my use // If no filename exit if ($wire->page->getUnformatted('section_slogan') == '') throw new Wire404Exception(); // File Pointer $myfile = "http://" . $config->httpHost . $config->urls->templates . "loaders/" . $wire->page->getUnformatted('csvfilename'); $content = "<p>Using Loader File '{$myfile}'</p><hr/>"; // Read The Data File if (($handle = fopen("$myfile", "r")) !== FALSE) { // Get the Setup Info if (($data = fgetcsv($handle, 0, ",")) !== FALSE) { $myTemplate = $templates->get("$data[0]"); $myParent = $wire->pages->get("path='$data[1]'"); if (($myTemplate->id == 'NullPage') || ($myParent->id == 'NullPage')){ throw new Wire404Exception(); } } else { throw new Wire404Exception(); } // Setup the parent $newItem = new Page(); $newItem->template = $myTemplate; // Tell User what's going on: $content .= "<p>Adding New Pages based on the '{$newItem->template->name}' template to parent '{$myParent->title}' path: '{$myParent->path}'</p><hr/>"; // List out the fields in the template $num = count($newItem->fields); $content .= "<p> $num fields in template</p><ol>"; foreach($newItem->fields as $itemfd) { $content .= "<li>" . $itemfd->name . "</li>"; } $content .= "</ol><hr/>"; // Read header record and match-up fields to template $fieldmatchup = ''; if (($data = fgetcsv($handle, 0, ",")) !== FALSE) { $num = count($data); for ($c=0; $c < $num; $c++) { foreach($newItem->fields as $itemfd) { if($data[$c] == $itemfd->name) { $fieldmatchup[$itemfd->name] = $c; } } } } // Show the File's Field Array $content .= "<p>Display the Field Array</p><ul>"; foreach($fieldmatchup as $item_key => $item_value) { $content .= "<li>['" . $item_key . "'] = '" . $item_value . "'</li>"; } $content .= "</ul><hr/><h4>Reading File</h4><hr/>"; // Now add the data $row = 0; $newItem = ''; while (($data = fgetcsv($handle, 0, ",")) !== FALSE) { $num = count($data)-1; $row++; $mySel = "parent=" . $myParent->id . ", title='" . $data[$fieldmatchup['title']] . "'"; $dupPage = $wire->pages->get($mySel); if($dupPage->id == 'NullPage') { $content .= "<p>newItem (" . $mySel . ")<br/><b>-- Creating from File</b>.</p>\n"; // Setup blank WireArray based on a template $newItem = new Page(); $newItem->template = $myTemplate; $newItem->title = $data[$fieldmatchup['title']]; $newItem->parent = $myParent; $newItem->save(); } else { $content .= "<p>Duplicate Found (" . $mySel . ")<br/><b>-- Updating from File</b>.</p>\n"; $newItem = $dupPage; } $content .= "<p> {$num} fields in record {$row}: <br /></p>\n"; $newItem->of(false); foreach($newItem->fields as $itemfd) { $key = $itemfd->name; if ($key != 'title') { $value = $data[$fieldmatchup[$key]]; $content .= "[{$key}] = [{$value}]<br />\n"; $newItem->set($key, $value); } } $newItem->save(); $content .= "<b>-- Saved: </b> <a target='_blank' href='" . $newItem->editUrl . "'>" . $newItem->title . " [" . $newItem->id . "]</a><hr/>"; } fclose($handle); } $content .= "<b>{$row} records added/updated</b>"; And here's a sample of data that works: (associated_stat & special_category are page fields) skill,"/systems/sol/" title,associated_stat,multiplier,special,special_category,body Alien Archeology,Int,4,,,"Skill description" Alien Tech,Tech,4,,,"Skill description" Alien Weapons,Ref,4,1,Weapons,"Skill description" And the file that's giving me issues:(pc_role_category, associated_book, sa_skill are page fields, career_skills is a multiple page field) cp-role,"/systems/sol/" title,pc_role_category,associated_book,page_no,verified_via,sa_skill,career_skills,body "Merc","Combat Related","Book Name","8","Book Review","Combat Zen","Athletics|Alien Tech|Drive|Shoot","Role Description" It's the associated_book field that's giving me the issue, if I blank it or put in the PageID it works, but with anything else it errors out with this: Fatal Error Call to a member function __unset() on boolean search Source File: ...\core\wire\modules\Fieldtype\FieldtypePage.module:439 431: if($value instanceof Page) { 432: // ok 433: } else if($value instanceof PageArray) { 434: $value = $value->first(); 435: } else if(is_string($value) || is_int($value)) { 436: $value = $this->sanitizeValueString($page, $field, $value); 437: if($value instanceof PageArray) $value = $value->first(); 438: if($value->_FieldtypePage_remove === $value->id) { 439: $value->__unset('_FieldtypePage_remove'); 440: $value = null; // remove item 441: } 442: } So, looking at this field, and the associated page template, everything is setup the same as all the other page fields, except that the page template in question (books) has a field that references a page field (associated_system) that I'm not even referencing, so I'm not sure if that's the culprit or not, but that is the only thing that separated this template from the others is this custom label code and that the pages are outside of the parent: And yes, I've removed the custom label and it still has the same error. With my luck it's something simple, but I can't see it... Any help would be appreciated
×
×
  • Create New...