MarcC Posted November 8, 2013 Share Posted November 8, 2013 I have a big database full of various tables that I plan to import to ProcessWire as CSV. Each record/row has a field corresponding to an image number. Then I have a folder full of the numbered images. After importing the CSV, I am planning to import these image like so: foreach $imported_pages as $page { if ($page->image_number) { if (file exists with image_number in the filename) { //Code below from Ryan $page->images->add("path or URL to image"); //save the page $page->save(); } } } Does that look right? Thanks! 2 Link to comment Share on other sites More sharing options...
MadeMyDay Posted November 8, 2013 Share Posted November 8, 2013 Try on a smaller set of rows and see the magic happen ;-) looks good to me, did something similar just yesterday with success (of course). Even large MB-sized PDFs were downloaded from a external server smoothly. 4 Link to comment Share on other sites More sharing options...
horst Posted November 8, 2013 Share Posted November 8, 2013 $num = 0; foreach $imported_pages as $page { if ($page->image_number) { if (file exists with image_number in the filename) { $num++; //Code below from Ryan $page->images->add("path or URL to image"); //save the page $page->save(); echo "added image with {$page->image_number} to {$page->name}\n"; } } // added because you have said a "big database" // (it is picked up from Ryans code somewhere in forum examples) wire('pages')->uncache($page); // just in case we need the memory if($num >= 5) break; } Looks good. I'm actually working on a DB for a colleague and I have imported 2000 pages and 35.000 images similar like that. For testing I use breaks in the loop to just test only one import, or use a counter and import 5 or 10 images before breaking. When seeing it works well I comment the breaks. Also I make a SQL-Dump before testing/modifying/importing. And I write logfiles. And I love importer-scripts! 4 Link to comment Share on other sites More sharing options...
ryan Posted November 9, 2013 Share Posted November 9, 2013 Looks fine to me MarcC. My process here is pretty much identical to Horst's. Over the next couple weeks, I have to import 3000+ pages each with 10-50 photos. When doing large quantities, you may need to paginate it, or run it multiple times, if you run into any memory issues. Check if the page you are creating already exists and skip it if it does. Something you may also need at the top of your PHP file is: ini_set('max_execution_time', 60 * 60); // give it an hour. 1 Link to comment Share on other sites More sharing options...
MarcC Posted November 9, 2013 Author Share Posted November 9, 2013 Thanks everybody--I'll give it a shot on Monday and see how it goes. I just watched "Cloudy With a Chance of Meatballs" with my kids and now I'm dreading this job a bit--can't recommend watching that film before doing batch operations. 1 Link to comment Share on other sites More sharing options...
MatthewSchenker Posted November 10, 2013 Share Posted November 10, 2013 I just watched "Cloudy With a Chance of Meatballs" with my kids and now I'm dreading this job a bit--can't recommend watching that film before doing batch operations. Greetings,Very funny! But I dare you to try coding while your kid listens to "Fox in Socks" (as I did this morning). You will temporarily abandon all hope of OO or MVC. Back on topic: the importing ideas in this discussion are great! Thanks, Matthew Link to comment Share on other sites More sharing options...
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