Jump to content

BillH

Members
  • Posts

    166
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by BillH

  1. Might these posts give you some starting points?
  2. Might a Select Options field suit your needs? Part of the core, and can be suitable for uses such as you describe. Details at https://processwire.com/docs/fields/select-options-fieldtype/.
  3. You may find an answer in this discussion, which has a number of suggestions and links: It might also be worth checking that you haven't run out server space.
  4. Welcome to the forums! There's a good chance that the cause of this problem is the same as that for the issue in your next post (Uploaded file showed up with 0kb size), so I'd suggest resolving that first. I'll post a response to that second post shortly...
  5. One possibility is that the pages are hidden, unpublished or no-access, which are ignored by default by $page->children. Try adding an 'include=all' selector to see if the material from the pages then appears: foreach($page->children("include=all") as $child) {
  6. I'm not sure that I fully understand what you need to do, but I have a couple of thoughts. One is that runtime fields and searches won't mix well, and if you need to maintain a field for some kind of sort code, you'd be better off hooking on saveReady to maintain a field. The other is that it can be quicker than you expect to loop through the results of a search (so long as there aren't huge numbers). So a good strategy might be to get as few pages as possible using selectors, and then loop through those pages to produce the final result.
  7. Here you go! You need to decide how big each batch will be and set the $startPage and $endPage values each time you run the script. For example, if you have 1230 pages and decide to run the script three times you could use 0 and 499; 500 and 999; 1000 and 1300. Note that you should start at 0 (because the indexing of the page array starts at 0). And it's OK if the last number is larger than the total number of pages. Note also that I haven't tested the code, so let me know if it doesn't work! <?php // If you put the script in /site/ this is OK (otherwise you may need to amend) include("../index.php"); // Change these two values for each batch $startPage = 0; $endPage = 499; // Change the selector to match your pages $selectedRecords = $wire->pages->find("template=my-template"); echo "Pages with images: " . count($selectedRecords) . "<br/>"; $pageCounter = 0; $recordsProcessed = 0; foreach($selectedRecords as $thisRecord) { $pageCounter += 1; if (($pageCounter >= $startPage) && ($pageCounter <= $endPage)) { echo $thisRecord->title . "<br/>"; $recordsProcessed += 1; if(count($thisRecord->article_images)) { $thisRecord->of(false); foreach($thisRecord->article_images as $image) { $description = $image->description; $credit = $image->credit; $image->photo_caption = $description; $image->photo_credit = $credit; $thisRecord->save('article_images'); } $thisRecord->save(); } } } echo "<p>Records processed: {$recordsProcessed}</p>"; ?>
  8. I'd definitely try @netcarver's suggestion first. And if that doesn't work, you could try putting this after saving the record, though I'm not sure if it will make a difference: $pages->uncacheAll(); Then if you still have the problem, for a one-off task you could split the processing into batches. Doing something like the following is highly inefficient, but simple and will definitely work – and is probably more efficient than spending a lot of time trying to find a better fix! $startPage = 0; // Manually change this for each batch $endPage = 1000; // And this too $pageCounter = 0; foreach($pageToProcess as $thisPage) { $pageCounter += 1; if (($pageCounter >= $startPage) && ($pageCounter <= $endPage)) { // Process $thisPage here } }
  9. The script should be a standalone PHP file, not placed in a template. So, for example, you might name the script "fix-images.php" and put the file in /site/. Then, if you normally access the site at https://www.mysite.com, run the script by accessing https://mysite.com/site/fix-images.php . For more details, take a look at this page (particularly the last section): https://processwire.com/docs/front-end/include/
  10. I did exactly the same thing a year or two ago. Here's the script I used (I've simplified the selector and a couple of other things, and added one comment). The script moves the image description and the ImageExtra field 'credit' to the new 'photo_caption' and 'photo_credit' fields. I don't know if you're familiar with running such scripts, but you simply put the script somewhere on your server and enter its URL in your browser. It might be a good idea to test with the saves commented out. <?php // Amend depending on where this script file is located include("../index.php"); $selectedRecords = $wire->pages->find("template=my-template"); echo "Pages with images: " . count($selectedRecords) . "<br/>"; $recordsProcessed = 0; foreach($selectedRecords as $thisRecord) { echo $thisRecord->title . "<br/>"; $recordsProcessed += 1; if(count($thisRecord->article_images)) { $thisRecord->of(false); foreach($thisRecord->article_images as $image) { $description = $image->description; $credit = $image->credit; $image->photo_caption = $description; $image->photo_credit = $credit; $thisRecord->save('article_images'); } $thisRecord->save(); } } echo "<p>Records processed: {$recordsProcessed}</p>"; ?> This was written for a one-off task, so I did nothing to refine it, but it worked. Note that at the time both saves were necessary, though I think this has been resolved now and, depending on which version of PW you are running, you may be able just to save the whole record - but it'd probably be easier to leave it as it is!
  11. If you create a page reference field named 'recipe_category' and want to find everything in the category 'soup', you could do something like this: $categoryPage = $pages->get("name=soups"); $soups = $pages->find("template=recipes, recipe_category=$categoryPage"); Alternatively, if you could use a select options field (easier to set up, but less flexible and harder to change anything, so usually page reference fields are better in the long run): $soups = $pages->find("template=recipes, recipe_category.title=soups");
  12. I don't know the cause of the trouble, but it might be worth checking that your .htaccess file is being read by adding some random characters at the start; a server error when you go to a page of the site will mean that it is being read. My best guess about the /assets/files/ errors is that .htaccess is being read, and that the errors are a side effect arising from the rewrite rules involving that directory. Have you looked inside the PW .htaccess? It's well commented, so the next thing might be to read through it for any ideas.
  13. I think this will tell you what you need:
  14. You could use a hook as in this discussion: Putting the hook in ready.php may well be a good plan.
  15. Regarding users, what you describe is a common situation with membership systems, where there are often things such as corporate members with associated members, so it might be worth searching the forums to see if there's anything about what others have done. And perhaps take a look at the Login Register Pro module. For file uploads, in one project that requires regular uploads by a client, I made a simple admin page containing only a file field (giving me an instant UI) and a Save button. I hooked after the page has saved to process the files. I don't know of a better idea for matching files to clients than using filenames – though that doesn't mean there isn't one! I have one suggestion: it might help to reduce errors if the filename included a checksum for the string that identifies the client.
  16. You may get them in the correct order (that is, the order they appear in the page tree) by default. But if you don't, try adding `sort=sort` to your selector - see "How to force pages to sort by their admin order" on the page https://processwire.com/docs/selectors/).
  17. Another possible approach, given $subchildren as the result of your find: $parent = null; $grandparent = null; foreach($subchildren as $subchild) { $scParent = $subchild->parent; $scGrandparent = $scParent->parent; // Or $subchild->parent->parent if($grandparent != $scGrandparent) { $grandparent = $scGrandparent; echo $grandparent->name . '<br/>'; } if($parent != $scParent) { $parent = $scParent; echo '&emsp;' . $parent->name . '<br/>'; } echo '&emsp;&emsp;' . $subchild->name . '<br/>'; } Obviously, this'll produce simple indented text, but you could adapt to generate a list or whatever you need.
  18. I suggest taking a look at the sections 'Finding pages that have specific parents or ancestors' and 'Sub-selectors: selectors within selectors' of the 'Using Selectors' page at https://processwire.com/docs/selectors/. You might end up with something a little like this, here finding all grandchildren with a name beginning with 'a' that have a grandparent with location = 'US': $grandchildren = $pages->find("has_parent=[template=grandparent, location=US], name^=a");
  19. And another thought: consider using URL segments as described at https://processwire.com/docs/front-end/how-to-use-url-segments/.
  20. Recently I was planning a project for an archive of PDFs, and I decided that a page per PDF was going to be significantly easier to work with and more flexible than grouping them in file fields. The number of pages shouldn't be a problem. You'd get around 6k pages a year, so 60k a decade, 120k after two decades... Comfortably within PW's capabilities. On the other hand, a client page with a file field holding 500 PDFs after a decade doesn't sound great! If you haven't seen it, you might find something interesting in this recent blog post about new scalability options: https://processwire.com/blog/posts/pw-3.0.175/
  21. Hi @Goca and welcome to the forums! There's a useful description of how templates work at https://processwire.com/docs/start/templates/ Don't miss the link to the pages about output strategies in the 'Next steps' section at the end. Note that if you'll have a lot of pages where each needs a slightly different template, you may find that the best approach is for them to share a template containing a little conditional logic, for example: if($page->name == 'page1') { // Display something } elseif($page->name == 'page2') { // Display something else } elseif...
  22. What happens when you try "Check again"? The same message, error 500 or something else? If error 500, there's probably something in .htaccess that your server doesn't like. It might be worth installing a fresh .htaccess, just in case an error has crept in. Other than that, if you've tried everything in the discussion mentioned above, this starts to go beyond my knowledge!
  23. If you haven't found it, this discussion might help:
  24. To set a cache that will expire at midnight today: // Expiry time string $midnight = 'today 23:59:59'; // Alternatively, the start of tomorrow is midnight today // $midnight = 'tomorrow'; // Save the cache $cache->save('test-cache', 'Value for cache', $midnight); So, to achieve what you want (if I understand you correctly), you could use the get() method something like this: $midnight = 'tomorrow'; $str = $cache->get('test-cache', $midnight, function() { return "The next cache value"; }); By the way, if you haven't discovered it, the getInfo() function is really useful for debugging, for example: print_r($cache->getInfo(false, 'test-cache'));
  25. The phrase you quote ("Optionally specify...") comes from the doc page for $cache->get(). With this function, you are specifying the maximum age of the cache you are trying to get (for example, up to 3600 second old). I could be misunderstanding you, but it sounds as if you're trying to set the expiry time for caches that you have created, in which case use $cache->save(). Or perhaps that is what you're using, in which case follow the instructions for the expire argument on the relevant page (https://processwire.com/api/ref/wire-cache/save/). Note: if you want them, the WireCache::expire constants are on the $cache page (https://processwire.com/api/ref/wire-cache/).
×
×
  • Create New...