Forum for discussing general topics related to Couch.
3 posts Page 1 of 1
By way of background: I'm creating a rota for volunteers to cover an hour of duty each, covering four hours each evening in total. My plan is to use a 'page' for each hour, allow people to log in, see what is covered and what's still needed (simple listing, really), and assign themselves to individual hours (databound form, should be fairly straightforward). The 'pages' then become the record of what hours are covered / available. I'd keep 3 months worth of pages on the site at any one time.

So on about the 28th of each month, I'll need to add the hours for a new month (adding April in December, for example) ; and then on about the 3rd delete the month which has just passed.

I'm not quite clear how to do this bulk add / delete operation. I'm expecting to use a cron job on the server and call a PHP file, which can of course (and ideally should) be a Couch page. What's the best way of doing this?
You may use <cms:db_persist /> tag to create pages in a loop - viewtopic.php?p=15104#p15104

There is an equivalent tag for deletion - viewtopic.php?p=13980#p13980

Since the number of pages you'll work with is not very high (1 month x 4 pages/day = #120 pages), your script wouldn't need to worry about timing out etc. Just create a template that does the operations and, once you are sure the template works fine upon manual invocation, use cron to call it.

As a tip - you might want to name your pages after the date they belong to e.g.
2018-11-14-1
2018-11-14-2
2018-11-14-3
2018-11-14-4
for the 14'th of Nov. 2018.

This way your script can first check if that particular page exists before creating or deleting it,
This way we'll be sure that (accidental) multiple invocations of the script won't lead to unwanted consequences.

Hope this helps.
Thanks KK - I was thinking of something along those lines, but wasn't sure that you could do multiple "db_persist" operations on one page.

And yes, page naming is a good idea - and if the site admin needs to be able to override or correct individual user's actions (as it likely!), then it's also the way to make the relevant record easy to find in the control panel.
3 posts Page 1 of 1