Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/auto-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
-
name: Checkout Branch ${{ github.ref_name }}
uses: actions/checkout@v4
uses: actions/checkout@v6
-
name: Create Pull Request
run: gh pr create -B main --title "${{ github.ref_name }}" --body "Merging branch to create ${{ github.ref_name }}."
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
-
name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v6
-
name: Run PHPStan checks
run: |
Expand All @@ -23,7 +23,7 @@ jobs:
steps:
-
name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v6
-
name: Get repository name
run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
-
name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v6
-
name: Get repository name
run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
shell: bash
-
name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v6
-
name: Login to DockerHub
uses: docker/login-action@v3
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.8
2.3.0
2 changes: 1 addition & 1 deletion VERSION_MINOR
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2
2.3
2 changes: 1 addition & 1 deletion cli.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bfren/php:php8.4
FROM bfren/php:php8.5

ENV BF_PHP_EXT="curl session sodium pecl-yaml"

Expand Down
2 changes: 1 addition & 1 deletion cmd.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

#docker buildx build -f cli.Dockerfile -t obadiah:cli --load .
docker buildx build -f cli.Dockerfile -t obadiah:cli --load .
docker run \
-v $(pwd)/data:/data \
-v $(pwd)/src:/ws \
Expand Down
13 changes: 4 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bfren/nginx-php:php8.4-7.5.1
FROM bfren/nginx-php:php8.5-8.1.0

LABEL org.opencontainers.image.source="https://github.com/bfren/obadiah"

Expand Down
4 changes: 1 addition & 3 deletions docker/overlay/etc/periodic/hourly/preload
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ set -euo pipefail
#======================================================================================================================

bf-write "Calling preload script." preload
CODE=$(bf-test-url --return-status "http://localhost/preload")
[[ "${CODE}" = "200" ]] && exit 0 \
|| bf-write-error "Error executing preload (HTTP ${CODE})." preload
ob preload
6 changes: 3 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/sh

docker pull bfren/obadiah:dev
docker run \
docker run -it \
-p "127.0.0.1:3000:80" \
-e PHP_INI=development \
-e BF_PHP_ENV=development \
-v $(pwd)/src:/www \
-v $(pwd)/data:/data \
bfren/obadiah:dev
bfren/obadiah:dev nu
52 changes: 7 additions & 45 deletions src/api/preload/preload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

namespace Obadiah\Api\Preload;

use DateTimeImmutable;
use Obadiah\App;
use Obadiah\Cache\Cache;
use Obadiah\Config\Config as C;
use Obadiah\Pages\Events\Events;
use Obadiah\Preload\Preload as P;
use Obadiah\Response\Json;
use Obadiah\Router\Endpoint;
use Throwable;

App::check();

Expand All @@ -24,59 +20,25 @@ public function index_get(): Json
{
$results = array(
// Bible Reading plan
"bible" => self::load(fn() => Cache::get_bible_plan(true)),
"bible" => P::get_bible_plan(),

// Church Suite events
"events" => self::load(function () {
// clear events cache
Cache::clear_events();

// build query to preload events for this month
$today = new DateTimeImmutable(timezone: C::$events->timezone);
$start_of_month = $today->modify("first day of")->format(C::$formats->sortable_date);
$query = http_build_query(array("date_start" => $start_of_month));

// get events
Cache::get_events($query, fn($q) => Events::get_events($q));
}),
"events" => P::get_events(),

// Baserow lectionary
"lectionary" => self::load(fn() => Cache::get_lectionary(true)),
"lectionary" => P::get_lectionary(),

// People
"people" => self::load(fn() => Cache::get_people(true)),
"people" => P::get_people(),

// Refresh calendar
"refresh" => self::load(fn() => Cache::get_refresh(true)),
"refresh" => P::get_refresh(),

// Church Suite rota
"rota" => self::load(fn() => Cache::get_rota(true))
"rota" => P::get_rota()
);

// return JSON response
return new Json($results);
}

/**
* Call a function and return the result plus execution time (or error reason).
*
* @param callable $callable Callable function.
* @return mixed[] OK if $callable executed successfully, Error if not.
*/
private static function load(callable $callable): array
{
try {
// call cache loader
$start_time = microtime(true);
call_user_func($callable);
$end_time = microtime(true);

// calculate time and return result
$execution_time = ($end_time - $start_time);
return array("result" => "OK", "time" => sprintf('%05.4fs', $execution_time));
} catch (Throwable $th) {
_l_throwable($th);
return array("result" => "Error", "reason" => $th->getMessage());
}
}
}
4 changes: 2 additions & 2 deletions src/app.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class App
*/
public static function init(bool $is_http = true): void
{
// ensure we are running on PHP 8.4
version_compare(PHP_VERSION, "8.4.0", ">=") || self::die("This application requires at least PHP 8.4.");
// ensure we are running on PHP 8.5
version_compare(PHP_VERSION, "8.5.0", ">=") || self::die("This application requires at least PHP 8.5.");

// get current working directory
$cwd = __DIR__;
Expand Down
2 changes: 1 addition & 1 deletion src/classes/cache/cache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private static function clear(string $id): void
private static function get_or_set(string $id, callable $callable, array $args = [], bool $force = false): mixed
{
// clear cache if $force is set
if ($force || Request::$get->bool("force")) {
if ($force) {
self::clear($id);
}

Expand Down
48 changes: 48 additions & 0 deletions src/classes/cli/commands/preload.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Obadiah\Cli\Commands;

use Obadiah\App;
use Obadiah\Cli\Command;
use Obadiah\Helpers\Log;
use Obadiah\Preload\Preload as P;
use Obadiah\Request\Request;

App::check();

class Preload extends Command
{
/**
* Create command.
*
* @return void
*/
public function __construct() {}

/**
* Preload the caches.
*
* @return never
*/
public function execute(): void
{
$execute = function (string $name, callable $function) {
printf("%s... ", $name);
try {
$result = $function();
printf("%s\n", json_encode($result));
} catch (\Throwable $th) {
Log::error("Unable to preload %s\n%s", $name, $th);
}
};

$execute("Bible Reading Plan", fn() => P::get_bible_plan());
$execute("Events", fn() => P::get_events());
$execute("Lectionary", fn() => P::get_lectionary());
$execute("People", fn() => P::get_people());
$execute("Refresh Daily Prayers", fn() => P::get_refresh());
$execute("Rota", fn() => P::get_rota());

App::die("Done.");
}
}
86 changes: 86 additions & 0 deletions src/classes/netbible/api.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Obadiah\NetBible;

use Obadiah\App;
use Obadiah\Helpers\Log;

App::check();

class Api
{
/**
* Create API object.
*
*/
public function __construct() {}

/**
* Get a passage from the NET Bible API.
*
* @param string $passage The passage to retrieve - multiple passages should be separated by a semi-colon.
* @param string $type The return type - either 'text' (default) or 'json'.
* @return mixed If $passage is a valid Bible reference, the NET Bible text of that passage.
*/
private function get(string $passage, string $type = "text"): mixed
{
// build URL from data
$formatting = match($type) {
"text" => "para",
default => "plain"
};
$url = sprintf("https://labs.bible.org/api/?passage=%s&type=%s&formatting=%s", urlencode($passage), $type, $formatting);

// create curl request
$handle = curl_init($url);
if ($handle === false) {
_l("Unable to create cURL request for %s.", $url);
return null;
}

curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);

// make request - on error log and return null
$response = curl_exec($handle);
if (!is_string($response)) {
_l(print_r(curl_error($handle), true));
return null;
}

// if type is JSON, decode and return
if ($type === "json") {
$json = json_decode($response);
if (!$json) {
_l("Unable to decode JSON response from %s.", $url);
return null;
}

return $json;
}

// otherwise return as text
return $response;
}

/**
* Get Bible passage as JSON.
*
* @param string $passage The passage to retrieve - multiple passages should be separated by a semi-colon.
* @return mixed If $passage is a valid Bible reference, the NET Bible text of that passage.
*/
public function get_json(string $passage): mixed
{
return $this->get($passage, "json");
}

/**
* Get Bible passage as (HTML-formatted) text.
*
* @param string $passage The passage to retrieve - multiple passages should be separated by a semi-colon.
* @return ?string If $passage is a valid Bible reference, the NET Bible text of that passage.
*/
public function get_text(string $passage): ?string
{
return $this->get($passage, "text");
}
}
Loading