lenoir Posted November 22, 2023 Posted November 22, 2023 Great module!! It's funny how very often one expects a complex solution to a problem and stumble across a very simple ProcessWire module ?. Still, I've having timeOut issues importing a simple CSV (1.3Mb) after 77 pages already. Expecting to import >2000. What's the workaround? I've installed Tasker, but I'm not sure how it works. Can anyone help me? Thanks!
psy Posted Thursday at 07:48 AM Posted Thursday at 07:48 AM On 4/5/2023 at 5:22 AM, HannaP said: Hello all, I'm about to make my site fit for php8.1 (it's php8.0 at the moment). From this ImportPagesCSV module I get deprecation warnings: Deprecated: auto_detect_line_endings is deprecated in XXX/site/modules/ImportPagesCSV/ImportPagesCSV.module on line 112 Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in XXX/site/modules/ImportPagesCSV/ImportPagesCSV.module on line 229 What to do? (PW Version is 3.0.210) Had the same problems and found the solution. Added to github issues at https://github.com/ryancramerdesign/ImportPagesCSV/issues/29 In short: Change: public function init() { parent::init(); ini_set('auto_detect_line_endings', true); } to: public function init() { parent::init(); // auto_detect_line_endings is deprecated in PHP 8 if (PHP_VERSION_ID < 80000) { ini_set('auto_detect_line_endings', '1'); } } and change: if(strlen($value)) { $f->attr('value', $value === "\t" ? 2 : 1); } else { $f->attr('value', 1); } to: if ($value !== null && strlen($value)) { $f->attr('value', $value === "\t" ? 2 : 1); } else { $f->attr('value', 1); }
MatthewSchenker Posted Thursday at 01:29 PM Posted Thursday at 01:29 PM Hi psy, If you are looking for a quick-but-reliable way to get CSV docs into PW pages, here's a snippet I've been using for years. It might not do as much as the official module, but it will get you up and going. <?php // Script to create pages from rows in a CSV file //Open CSV file. $fileHandle = fopen("replace-with-file-name.csv", "r"); //Iterate through CSV rows. // NOTE: if you have a header row, it will be used to create a page. while (($row = fgetcsv($fileHandle, 0, ",")) !== FALSE) { // Create a new ProcessWire page from each CSV row, using the row's array 0-based index matched with the correct fields. // Set up pages in the ProcessWire page tree. $np = new Page(); // create new page object $np->template = $templates->get(xx); // Set the template to use for created pages. $np->parent = $pages->get(xxxx); // Set the parent ID for created pages. // Turn output formatting off $np->of(false); // Set field values from the 0-based index of the CSV row. $np->title = $row[0]; $np->name = $row[0]; $np->field_name1 = $row[1]; $np->field_name2 = $row[2]; $np->field_name3 = $row[3]; // Save the page $np->save(); } 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now