Skip to content

Commit c99c0c2

Browse files
committed
Merge branch 'v3.0.0' into 254-use-churchsuite-api-v2
2 parents 0aa57fd + a5681ce commit c99c0c2

14 files changed

Lines changed: 94 additions & 53 deletions

File tree

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/safeguarding/safeguarding.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function reference_post(): Json
157157
Log::debug("Reference form received: %s", json_encode($form));
158158

159159
// remove hyphens from select values
160-
$get_select = fn(int $num) => str_replace("-", " ", Arr::get($form, "select_$num"));
160+
$get_select = fn(int $num) => str_replace("-", " ", Arr::get($form, "select_$num", ""));
161161

162162
// map JSON to Baserow table fields
163163
$row = array(
@@ -170,12 +170,12 @@ public function reference_post(): Json
170170
"Equality" => $get_select(4),
171171
"Honesty etc" => $get_select(5),
172172
"Comments" => Arr::get($form, "textarea_1"),
173-
"Health" => Arr::get($form, "select_6"),
173+
"Health" => $get_select(6),
174174
"Health Details" => Arr::get($form, "textarea_2"),
175-
"Unsuitability" => Arr::get($form, "select_7"),
175+
"Unsuitability" => $get_select(7),
176176
"Unsuitability Details" => Arr::get($form, "textarea_3"),
177177
"Referee Full Name" => Arr::get($form, "name_2"),
178-
"Confirm" => Arr::get($form, "checkbox_1") == "true",
178+
"Confirm" => Arr::get_boolean($form, "checkbox_1"),
179179
"Referee Email" => Arr::get($form, "email_1"),
180180
"Referee Phone" => Arr::get($form, "phone_1"),
181181
);

src/classes/baserow/baserow.class.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public function get(array $data = []): array
112112
return [];
113113
}
114114

115-
curl_setopt($handle, CURLOPT_HTTPHEADER, array(sprintf("Authorization: Token %s", $this->token)));
115+
curl_setopt($handle, CURLOPT_HTTPHEADER, array(
116+
sprintf("Authorization: Token %s", $this->token)
117+
));
118+
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
116119

117120
// make request and return empty array on error
118121
$json = Curl::execute_with_retry($handle);
@@ -178,6 +181,9 @@ public function post(array $data): Post_Result
178181
curl_setopt($handle, CURLOPT_HTTPHEADER, array(
179182
sprintf("Authorization: Token %s", $this->token)
180183
));
184+
curl_setopt($handle, CURLOPT_POST, true);
185+
curl_setopt($handle, CURLOPT_POSTFIELDS, $form);
186+
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
181187

182188
// make request and output on error
183189
$json = Curl::execute_with_retry($handle);
@@ -188,8 +194,9 @@ public function post(array $data): Post_Result
188194

189195
// decode JSON response and output on error
190196
$result = json_decode($json, true);
191-
if ($error = Arr::get_array($result, "error")) {
192-
return new Post_Result(400, Arr::get($error, "detail"));
197+
if ($error = Arr::get($result, "error")) {
198+
$detail = is_array($error) ? Arr::get($error, "detail") : $error;
199+
return new Post_Result(400, $detail);
193200
}
194201

195202
// if we get here the POST was successful

src/classes/cache/cache.class.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,19 +352,23 @@ private static function get_or_set(string $id, callable $callable, array $args =
352352

353353
// get path to cache file
354354
$path = self::get_cache_file_path($id);
355+
$get_current_value = fn() => Serialise::parse(IO::file_get_contents($path));
355356

356357
// if the file exists, and the cache file has not expired, read and unserialise the value
357358
$last_modified = self::get_last_modified($path);
358359
if (time() - $last_modified < self::$duration_in_seconds) {
359-
return Serialise::parse(IO::file_get_contents($path));
360+
return $get_current_value();
360361
}
361362

362363
// get a fresh value and serialise it to the cache
363364
$value = call_user_func($callable, ...$args);
364-
file_put_contents($path, Serialise::store($value));
365+
if ($value !== false) {
366+
file_put_contents($path, Serialise::store($value));
367+
return $value;
368+
}
365369

366-
// return value
367-
return $value;
370+
// failed to get fresh value so return current cache value
371+
return $get_current_value();
368372
}
369373

370374
/**

src/classes/preload/preload.class.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ public static function get_events(): array
3434
// clear events cache
3535
Cache::clear_events();
3636

37-
// build query to preload events for this month
38-
$today = new DateTimeImmutable(timezone: C::$events->timezone);
39-
$start_of_month = $today->modify("first day of")->format(C::$formats->sortable_date);
40-
$query = http_build_query(array("date_start" => $start_of_month));
41-
4237
// get events
43-
Cache::get_events($query, fn($q) => Events::get_events($q), true);
38+
Cache::get_events(Events::get_default_query(), fn($q) => Events::get_events($q), true);
4439
});
4540
}
4641

src/pages/events/events.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ private static function get_query(array $values): string
7676
return http_build_query($query);
7777
}
7878

79+
/**
80+
* Return default events query to retrieve events for the current month.
81+
*
82+
* @return string URL-encoded query (using http_build_query()).
83+
*/
84+
public static function get_default_query(): string
85+
{
86+
$today = new DateTimeImmutable(timezone: C::$events->timezone);
87+
$start_of_month = $today->modify("first day of")->format(C::$formats->sortable_date);
88+
return self::get_query(array("date_start" => $start_of_month));
89+
}
90+
7991
/**
8092
* Get events from Church Suite matching the query.
8193
*

src/pages/home/home.class.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
namespace Obadiah\Pages\Home;
44

55
use DateInterval;
6+
use DateTime;
67
use DateTimeImmutable;
78
use Obadiah\App;
9+
use Obadiah\Cache\Cache;
810
use Obadiah\Config\Config as C;
11+
use Obadiah\Pages\Events\Events;
912
use Obadiah\Pages\Home\Index_Model;
1013
use Obadiah\Response\View;
1114
use Obadiah\Rota\Rota;
@@ -36,11 +39,23 @@ public function index_get(): View
3639
"api" => C::$login->api
3740
);
3841

42+
$stale_cache = new DateTime("now", C::$events->timezone);
43+
$stale_cache->sub(new DateInterval(sprintf("PT%sS", C::$cache->duration_in_seconds)));
44+
$check_cache = fn(int $timestamp) => $timestamp > $stale_cache->getTimestamp();
45+
3946
return new View("home", model: new Index_Model(
4047
this_week: $this_week,
4148
upcoming: Rota::upcoming_sundays(),
4249
refresh_print: $refresh_print,
43-
refresh_feed: $refresh_feed
50+
refresh_feed: $refresh_feed,
51+
caches_check: array(
52+
"bible" => $check_cache(Cache::get_bible_plan_last_modified()),
53+
"events" => $check_cache(Cache::get_events_last_modified(Events::get_default_query())),
54+
"lectionary" => $check_cache(Cache::get_lectionary_last_modified()),
55+
"people" => $check_cache(Cache::get_people_last_modified()),
56+
"refresh" => $check_cache(Cache::get_refresh_last_modified()),
57+
"rota" => $check_cache(Cache::get_rota_last_modified())
58+
)
4459
));
4560
}
4661
}

src/pages/home/index-model.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ class Index_Model
1515
* @param mixed[] $upcoming Rota filter values to show upcoming Sunday services.
1616
* @param mixed[] $refresh_print Query values to link to printable version of this month's refresh calendar.
1717
* @param mixed[] $refresh_feed Query values to enable refresh ICS feed.
18+
* @param mixed[] $caches_check Whether or not caches have been updated recently.
1819
*/
1920
public function __construct(
2021
public readonly array $this_week,
2122
public readonly array $upcoming,
2223
public readonly array $refresh_print,
23-
public readonly array $refresh_feed
24+
public readonly array $refresh_feed,
25+
public readonly array $caches_check,
2426
) {}
2527
}

src/pages/home/index-view.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434

3535
<?php if (Request::$session->is_admin) : ?>
3636
<h2>Caches</h2>
37+
<p>
38+
<?php foreach($model->caches_check as $key => $value): ?>
39+
<?php _h("%s %s", $value ? "<span class=\"text-success\">&check;</span>" : "<span class=\"text-danger\">&cross;</span>", ucfirst($key)); ?></br>
40+
<?php endforeach; ?>
41+
</p>
3742
<p><a href="#" id="reload-link">Reload</a> caches (this happens automatically every <?php _e("%s", C::$cache->duration_in_seconds / 60); ?> minutes).</p>
3843
<div id="reload"></div>
3944
<?php endif; ?>

vendor/composer/installed.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"packages": [
33
{
44
"name": "phpstan/phpstan",
5-
"version": "2.1.40",
6-
"version_normalized": "2.1.40.0",
5+
"version": "2.1.54",
6+
"version_normalized": "2.1.54.0",
77
"dist": {
88
"type": "zip",
9-
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/9b2c7aeb83a75d8680ea5e7c9b7fca88052b766b",
10-
"reference": "9b2c7aeb83a75d8680ea5e7c9b7fca88052b766b",
9+
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/8be50c3992107dc837b17da4d140fbbdf9a5c5bd",
10+
"reference": "8be50c3992107dc837b17da4d140fbbdf9a5c5bd",
1111
"shasum": ""
1212
},
1313
"require": {
@@ -16,7 +16,7 @@
1616
"conflict": {
1717
"phpstan/phpstan-shim": "*"
1818
},
19-
"time": "2026-02-23T15:04:35+00:00",
19+
"time": "2026-04-29T13:31:09+00:00",
2020
"bin": [
2121
"phpstan",
2222
"phpstan.phar"

0 commit comments

Comments
 (0)