Last active
March 16, 2018 20:23
-
-
Save arjenblokzijl/3814f3e1e286cddbb6f818cab4528684 to your computer and use it in GitHub Desktop.
Update ProcessWire $page from CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace ProcessWire; | |
include('index.php'); | |
/** | |
* CSV format | |
* | |
* title,datetime_matching_date,page_matching_person | |
* 464,12/24/2014,1132 | |
* 1750,5/9/2016,1132 | |
* 1751,5/9/2016,1132 | |
*/ | |
// Process CSV | |
$rows = array_map('str_getcsv', file('filename.csv')); | |
$header = array_shift($rows); | |
$pages = array(); | |
foreach ($rows as $row) { | |
$pages[] = array_combine($header, $row); | |
} | |
foreach ($pages as $key => $value) { | |
$title = $value['title']; | |
$datetime_matching_date = $value['datetime_matching_date']; | |
$page_matching_person = $value['page_matching_person']; | |
$page = wire("pages")->get("title=$title"); | |
if ($page->id) { | |
// Save data | |
$page->setAndSave('datetime_matching_date', $datetime_matching_date); | |
$page->setAndSave('page_matching_person', $page_matching_person); | |
// Output data to verify | |
echo ($title == $page->title) . " " . $title . " == " . $page->title . "<br>"; | |
echo "datetime_matching_date =>" . $datetime_matching_date . "<br>"; | |
echo "page_matching_person =>" . $page_matching_person . "<br>"; | |
echo "<hr>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment