Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
28 changes: 28 additions & 0 deletions .github/workflows/contentauthor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ jobs:
if: "!inputs.deploy"
runs-on: ubuntu-22.04

services:
mariadb:
image: mariadb:11
env:
MARIADB_ROOT_PASSWORD: mysqlpassword
MARIADB_DATABASE: edlibcontentauthor_test
ports:
- 3306:3306
options: >-
--health-cmd="healthcheck.sh --connect --innodb_initialized"
--health-interval=5s
--health-timeout=5s
--health-retries=20
postgres:
image: postgres:16-alpine
env:
POSTGRES_PASSWORD: thepgpassword
ports:
- 5432:5432
options: >-
--health-cmd=pg_isready
--health-interval=5s
--health-timeout=5s
--health-retries=20

steps:
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -100,6 +125,9 @@ jobs:
- name: Test
run: |
docker run -v "/tmp:/reports" --rm \
--network host \
-e DB_HOST=127.0.0.1 \
-e DB_PGSQL_HOST=127.0.0.1 \
test-image \
vendor/bin/phpunit --coverage-clover /reports/coverage.xml

Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ services:
depends_on:
contentauthor-startup: { condition: service_completed_successfully }
mysql: { condition: service_healthy }
postgres: { condition: service_healthy }
redis: { condition: service_healthy }
healthcheck:
test: [CMD, nc, -z, localhost, "9000"]
Expand All @@ -86,6 +87,7 @@ services:
depends_on:
contentauthor-startup: { condition: service_completed_successfully }
mysql: { condition: service_healthy }
postgres: { condition: service_healthy }
redis: { condition: service_healthy }
volumes:
- ./data/nginx/ca:/usr/local/share/ca-certificates:ro
Expand All @@ -101,6 +103,7 @@ services:
depends_on:
contentauthor-startup: { condition: service_completed_successfully }
mysql: { condition: service_healthy }
postgres: { condition: service_healthy }
redis: { condition: service_healthy }
volumes:
- ./data/nginx/ca:/usr/local/share/ca-certificates:ro
Expand All @@ -116,6 +119,7 @@ services:
depends_on:
certs: { condition: service_completed_successfully }
mysql: { condition: service_healthy }
postgres: { condition: service_healthy }
redis: { condition: service_healthy }
volumes:
- ./data/nginx/ca:/usr/local/share/ca-certificates:ro
Expand Down
1 change: 1 addition & 0 deletions localSetup/projects/mysql/init.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CREATE DATABASE IF NOT EXISTS edlibcontentauthor;
CREATE DATABASE IF NOT EXISTS moodle;
CREATE DATABASE IF NOT EXISTS edlibcontentauthor_test;
1 change: 1 addition & 0 deletions localSetup/projects/postgres/postgresinit.d/hub.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CREATE DATABASE hub;
CREATE DATABASE hub_test;
CREATE DATABASE contentauthor;
8 changes: 8 additions & 0 deletions sourcecode/apis/contentauthor/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ LOG_STACK_CHANNELS=stderr,single
LOG_LEVEL=debug
#LOG_STDERR_FORMATTER='App\Logging\JsonFormatter'

# To run contentauthor with postgresql switch the comments for these blocks.
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=edlibcontentauthor
DB_USERNAME=root
DB_PASSWORD=mysqlpassword

# DB_CONNECTION=pgsql
# DB_HOST=postgres
# DB_PORT=5432
# DB_DATABASE=contentauthor
# DB_USERNAME=postgres
# DB_PASSWORD=thepgpassword

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
Expand Down
1 change: 1 addition & 0 deletions sourcecode/apis/contentauthor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN install-php-extensions \
pcntl \
pcov \
pdo_mysql \
pdo_pgsql \
redis \
zip

Expand Down
18 changes: 9 additions & 9 deletions sourcecode/apis/contentauthor/app/H5PLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,15 @@ public function getAddons()
});
})
->select([
'l1.id as libraryId',
'l1.add_to as addTo',
'l1.name as machineName',
'l1.major_version as majorVersion',
'l1.minor_version as minorVersion',
'l1.patch_version as patchVersion',
'l1.preloaded_js as preloadedJs',
'l1.preloaded_css as preloadedCss',
'l1.patch_version_in_folder_name as patchVersionInFolderName',
'l1.id as \"libraryId\"',
'l1.add_to as \"addTo\"',
'l1.name as \"machineName\"',
'l1.major_version as \"majorVersion\"',
'l1.minor_version as \"minorVersion\"',
'l1.patch_version as \"patchVersion\"',
'l1.preloaded_js as \"preloadedJs\"',
'l1.preloaded_css as \"preloadedCss\"',
'l1.patch_version_in_folder_name as \"patchVersionInFolderName\"',
])
->whereNull('l2.name')
->whereNotNull('l1.add_to')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public function viewMaxScoreOverview()
},
])
->groupBy('id')
->having('contents_count', ">", 0)

@gunnarvelle gunnarvelle Aug 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This column is non existing in the table.

->orderBy('name')
->get()
->filter(fn(H5PLibrary $library) => $library->supportsMaxScore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Illuminate\Http\Response;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

class LibraryUpgradeController extends Controller
Expand All @@ -46,12 +45,11 @@ public function index(Request $request): View
'patch_version',
'runnable',
'restricted',
DB::raw('UNIX_TIMESTAMP(created_at) as created_ts'),
DB::raw('UNIX_TIMESTAMP(updated_at) as updated_ts'),
'created_at',
'updated_at',
])
->orderBy('major_version')
->orderBy('minor_version')
->getQuery()
->get()
->mapToGroups(function ($item) {
return [$item->name => $item];
Expand Down Expand Up @@ -105,13 +103,13 @@ public function index(Request $request): View
'hubUpgradeMessage' => '',
'hubAvailable' => false,
'canRebuild' => !empty($library->id),
'createdTs' => $library->created_ts,
'updatedTs' => $library->updated_ts,
'createdTs' => $library->created_at->timestamp,
'updatedTs' => $library->updated_at->timestamp,
];

if ($library->runnable) {
if (config('h5p.isHubEnabled')) {
$upgrades = $this->core->getUpgrades($library, $versions->toArray());
$upgrades = $this->core->getUpgrades($library, $versions->all());

$item['upgradeUrl'] = empty($upgrades) || empty($usage['content']) ? false : route('admin.library', [
'task' => 'upgrade',
Expand Down
22 changes: 11 additions & 11 deletions sourcecode/apis/contentauthor/app/Libraries/H5P/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,15 +951,15 @@ public function loadContentDependencies($id, $type = null)
}
$sql =
"SELECT hl.id
, hl.name AS machineName
, hl.major_version AS majorVersion
, hl.minor_version AS minorVersion
, hl.patch_version AS patchVersion
, hl.preloaded_css AS preloadedCss
, hl.preloaded_js AS preloadedJs
, hcl.drop_css AS dropCss
, hcl.dependency_type AS dependencyType
, hl.patch_version_in_folder_name AS patchVersionInFolderName
, hl.name AS \"machineName\"
, hl.major_version AS \"majorVersion\"
, hl.minor_version AS \"minorVersion\"
, hl.patch_version AS \"patchVersion\"
, hl.preloaded_css AS \"preloadedCss\"
, hl.preloaded_js AS \"preloadedJs\"
, hcl.drop_css AS \"dropCss\"
, hcl.dependency_type AS \"dependencyType\"
, hl.patch_version_in_folder_name AS \"patchVersionInFolderName\"
Comment on lines +954 to +962

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Postgres converts texts to lowercase unless escaped. Escaping also works on mysql/mariadb.

FROM h5p_contents_libraries hcl
JOIN h5p_libraries hl ON hcl.library_id = hl.id
WHERE hcl.content_id = ?";
Expand Down Expand Up @@ -1208,8 +1208,8 @@ public function replaceContentTypeCache($contentTypeCache)
'major_version' => $type->version->major,
'minor_version' => $type->version->minor,
'patch_version' => $type->version->patch,
'h5P_major_version' => $type->coreApiVersionNeeded->major,
'h5P_minor_version' => $type->coreApiVersionNeeded->minor,
'h5p_major_version' => $type->coreApiVersionNeeded->major,
'h5p_minor_version' => $type->coreApiVersionNeeded->minor,
'title' => $type->title,
'summary' => $type->summary,
'description' => $type->description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function getProgress(Request $request)

public function getState($contentId, $context)
{
$sql = "select data, sub_content_id, data_id from $this->tableName where content_id=:contentId and user_id=:userId and preload=1";
$sql = "select data, sub_content_id, data_id from $this->tableName where content_id=:contentId and user_id=:userId and preload=true";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Postgres treats booleans as booleans and not tinyint. This works also for mysql/mariadb.

$params = [
':contentId' => $contentId,
':userId' => $this->currentUserId,
Expand Down
2 changes: 1 addition & 1 deletion sourcecode/apis/contentauthor/config/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
*/

'failed' => [
'database' => 'mysql', 'table' => 'failed_jobs',
'database' => env('DB_CONNECTION', 'mysql'), 'table' => 'failed_jobs',
],

];
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function up()
$table->text('data');
$table->boolean('preload')->default(0);
$table->boolean('invalidate')->default(0);
$table->dateTime('updated_at')->default('0000-00-00 00:00:00');
$table->dateTime('updated_at')->useCurrent();
$table->primary(['content_id','user_id','sub_content_id','data_id'], 'cud_pk1');
});
}
Expand Down

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed for fresh databases. Existing bases are targeted in new migrations.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ class CreateH5pLibrariesLanguagesTable extends Migration
public function up()
{
Schema::create('h5p_libraries_languages', function (Blueprint $table) {
$table->increments('id');
$table->integer('library_id')->unsigned();
$table->string('language_code', 31);
$table->text('translation', 65535);
$table->primary(['library_id','language_code']);
$table->unique(['library_id','language_code']);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ class CreateH5pLibrariesLibrariesTable extends Migration
public function up()
{
Schema::create('h5p_libraries_libraries', function (Blueprint $table) {
$table->increments('id');
$table->integer('library_id')->unsigned();
$table->integer('required_library_id')->unsigned();
$table->string('dependency_type', 31);
$table->primary(['library_id','required_library_id']);
$table->unique(['library_id','required_library_id']);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public function up()
*/
public function down()
{
// Postgres needs an explicit cast to turn a string column into an integer
if (DB::connection()->getDriverName() === 'pgsql') {
foreach (['h5p_contents', 'h5p_contents_user_data', 'h5p_results'] as $tableName) {
DB::statement("ALTER TABLE $tableName ALTER COLUMN user_id TYPE integer USING user_id::integer");
}

return;
}

Schema::table('h5p_contents', function ($table) {
$table->integer('user_id')->unsigned()->change();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function up()
Schema::create('cerpus_contents_shares', function (Blueprint $table) {
$table->integer('h5p_id')->unsigned();
$table->text('email', 65535);
$table->dateTime('created_at')->default('0000-00-00 00:00:00');
$table->dateTime('created_at')->useCurrent();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function up()
$table->bigIncrements('option_id')->unsigned();
$table->string('option_name', 191)->nullable()->default(null);
$table->longText('option_value');
$table->string('autoload', 20);
$table->string('autoload', 20)->default(0);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function up()
$table->text('data');
$table->boolean('preload')->default(0);
$table->boolean('invalidate')->default(0);
$table->dateTime('updated_at')->default('0000-00-00 00:00:00');
$table->dateTime('updated_at')->useCurrent();
$table->string('context', 40)->nullable()->default(null);
$table->unique(['content_id', 'user_id', 'sub_content_id', 'data_id', 'context'], 'cu_pid');
});
Expand All @@ -57,10 +57,17 @@ public function up()
public function down()
{
Schema::table('h5p_contents_user_data', function ($table) {
$table->dropColumn(["id", "context"]);
$table->dropUnique('cu_pid');
if (!DB::connection() instanceof \Illuminate\Database\SQLiteConnection) {
$table->dropUnique('cu_pid');
$table->dropIndex(['context']);
}
});

Schema::table('h5p_contents_user_data', function ($table) {
$table->dropColumn(["id", "context"]);
});

Schema::table('h5p_contents_user_data', function ($table) {
$table->primary(['content_id', 'user_id', 'sub_content_id', 'data_id'], 'cud_pk1');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class IncreaseH5pContentsTextfieldSize extends Migration
public function up()
{
Schema::table('h5p_contents', function ($table) {
$table->string('parameters', self::longTextLength)->change();
$table->string('filtered', self::longTextLength)->change();
$table->longText('parameters')->change();
$table->longText('filtered')->change();
});

Schema::table('h5p_contents_user_data', function ($table) {
$table->string('data', self::longTextLength)->change();
$table->longText('data')->change();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class SetAllContentPrivate extends Migration
public function up()
{
DB::update('update articles set is_private=1');
DB::update('update h5p_contents set is_private=1');
DB::update('update h5p_contents set is_private=true');
}

public function down()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function up()
if (!Schema::hasTable('games')) {
Schema::create('games', function (Blueprint $table) {
$table->uuid('id');
$table->string('gametype');
Comment thread
edlib-oddarne marked this conversation as resolved.
$table->uuid('gametype');
$table->string('title');
$table->string('language_code');
$table->string('owner');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
Expand All @@ -25,6 +26,13 @@ public function up()
*/
public function down()
{
// Postgres needs an explicit cast to turn a string column into an integer
if (DB::connection()->getDriverName() === 'pgsql') {
DB::statement('ALTER TABLE ndla_article_import_statuses ALTER COLUMN ndla_id TYPE integer USING ndla_id::integer');

return;
}

Schema::table('ndla_article_import_statuses', function (Blueprint $table) {
$table->unsignedInteger('ndla_id')->change();
});
Expand Down
Loading
Loading