Jump to content

BillH

Members
  • Posts

    166
  • Joined

  • Last visited

  • Days Won

    1

BillH last won the day on February 23

BillH had the most liked content!

About BillH

  • Birthday 03/06/1962

Contact Methods

  • Website URL
    https://arkesis.co.uk

Profile Information

  • Gender
    Male
  • Location
    London, UK

Recent Profile Visitors

1,450 profile views

BillH's Achievements

Sr. Member

Sr. Member (5/6)

101

Reputation

  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.
×
×
  • Create New...