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
7 changes: 7 additions & 0 deletions .github/docker/ci/install-and-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export EVO_LANGUAGE=${EVO_LANGUAGE:-en}
LOG=/tmp/install.log
UPDATE_LOG=/tmp/update.log

# EVO_DB_ENGINE (mysql): the storage engine to install on, through DB_ENGINE of the
# connection config. MyISAM is supported, and its key limit is 1000 bytes: smoke.php
# then also checks that every table got it.
if [ -n "${EVO_DB_ENGINE:-}" ]; then
export DB_ENGINE=$EVO_DB_ENGINE
fi

wait_for_db

say "Installing Evolution CMS (${EVO_DB_TYPE}, database '${EVO_DB_NAME}', prefix '${EVO_DB_PREFIX}')"
Expand Down
36 changes: 36 additions & 0 deletions .github/docker/ci/legacy-myisam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Turns the database of an installed site into the kind an old site still runs on: every table
* MyISAM with utf8mb3 text, as installers of older releases left them. upgrade-and-smoke.sh runs it
* between installing the older release and copying this tree over it (EVO_DB_LEGACY=myisam), so the
* migration chain meets the MyISAM key limit (1000 bytes) and a charset it did not choose.
*
* Usage: php legacy-myisam.php <site root>
*/
$root = rtrim($argv[1] ?? '', '/');
if (!function_exists('env')) {
function env(string $key, $default = null)
{
$value = getenv($key);

return $value === false ? $default : $value;
}
}
$config = require $root . '/core/config/database/connections/default.php';
if (($config['driver'] ?? '') !== 'mysql') {
fwrite(STDERR, 'legacy-myisam: mysql only, not ' . ($config['driver'] ?? '?') . PHP_EOL);
exit(1);
}

$pdo = new PDO(
'mysql:host=' . $config['host'] . ';port=' . $config['port'] . ';dbname=' . $config['database'],
$config['username'],
$config['password'],
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
$tables = $pdo->prepare("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_TYPE = 'BASE TABLE' AND LEFT(TABLE_NAME, CHAR_LENGTH(?)) = ?");
$tables->execute([$config['prefix'], $config['prefix']]);
foreach ($tables->fetchAll(PDO::FETCH_COLUMN) as $table) {
$pdo->exec('ALTER TABLE `' . str_replace('`', '``', $table) . '` ENGINE=MyISAM, CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci');
echo ' MyISAM utf8mb3: ' . $table . PHP_EOL;
}
29 changes: 29 additions & 0 deletions .github/docker/ci/smoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,35 @@ function setting(string $name)
check($table . ' is gone', count_rows_or_null($table) === null);
}

if ($driver === 'mysql') {
echo PHP_EOL . 'MySQL storage' . PHP_EOL;
// File group keys are case-exact paths under one unique key, on every engine. A create that ran
// into the MyISAM key limit (1000 bytes) used to leave the table without its indexes.
$column = $pdo->prepare('SELECT COLLATION_NAME FROM information_schema.COLUMNS'
. ' WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?');
$column->execute([$prefix . 'file_groups', 'file']);
$collation = (string) $column->fetchColumn();
check('file_groups.file compares paths case-sensitively', str_ends_with($collation, '_bin'), 'collation: ' . $collation);
$unique = $pdo->query('SHOW INDEX FROM ' . t('file_groups') . " WHERE Non_unique = 0 AND Key_name <> 'PRIMARY'")->fetchAll();
$uniqueColumns = implode(', ', array_column($unique, 'Column_name'));
check('file_groups has its unique key (document_group, file)', $uniqueColumns === 'document_group, file', 'unique: ' . $uniqueColumns);

// EVO_DB_ENGINE: the engine the run asked for (DB_ENGINE), which every table has to have.
$engine = (string) getenv('EVO_DB_ENGINE');
if ($engine !== '') {
$tables = $pdo->prepare('SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES'
. " WHERE TABLE_SCHEMA = DATABASE() AND TABLE_TYPE = 'BASE TABLE' AND LEFT(TABLE_NAME, CHAR_LENGTH(?)) = ?");
$tables->execute([$prefix, $prefix]);
$other = [];
foreach ($tables->fetchAll() as $table) {
if (strcasecmp((string) $table['ENGINE'], $engine) !== 0) {
$other[] = $table['TABLE_NAME'] . ' ' . $table['ENGINE'];
}
}
check('every table uses ' . $engine, $other === [], implode(', ', $other));
}
}

echo PHP_EOL . 'Seeded content' . PHP_EOL;
// An upgraded site carries the content the older release seeded and whatever
// its owner added since, so only a fresh install can be held to one document
Expand Down
9 changes: 9 additions & 0 deletions .github/docker/ci/upgrade-and-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ if grep -nE 'SQLSTATE\[|Fatal error:' "$SOURCE_LOG"; then
fail "the ${from_version} installer failed to build a database to upgrade"
fi

# EVO_DB_LEGACY=myisam (mysql): the site an old installation still is - every table MyISAM
# with utf8mb3 text, and a connection config that says so (engine MyISAM, charset utf8).
# The migration chain has to get through it as it is.
if [ "${EVO_DB_LEGACY:-}" = "myisam" ]; then
say "Turning the ${from_version} database into an old MyISAM / utf8mb3 site"
php "$NEW_DIR/.github/docker/ci/legacy-myisam.php" "$APP_DIR" || fail "could not convert the ${from_version} database"
export DB_ENGINE=MyISAM DB_CHARSET=utf8 DB_COLLATION=utf8_general_ci EVO_DB_ENGINE=MyISAM
fi

say "Recording what ${from_version} left in the database"
php "$SMOKE" --mode=baseline "$APP_DIR" || fail "the ${from_version} install is not usable as an upgrade source"

Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.PHP_EXTENSIONS }}
extensions: ${{ env.PHP_EXTENSIONS }}, pdo_mysql
coverage: none
tools: composer:v2

Expand All @@ -126,14 +126,22 @@ jobs:
run: |
php -r 'exit(extension_loaded("redis") ? 0 : 1);' || echo "::warning title=No ext-redis on PHP ${{ matrix.php }}::the Redis tests are skipped"

# The MySQL tests (FileGroupsMysqlTest: the file_groups migrations on MyISAM and under
# NO_BACKSLASH_ESCAPES, which sqlite cannot show) skip without a server; the lowest
# PHP version runs them.
- name: Start mysql
if: matrix.php == needs.php.outputs.lowest
run: docker compose -f .github/docker/ci/docker-compose.yml --profile mysql up -d --wait mysql

- name: Run Pest
working-directory: core
# env:
env:
EVO_TEST_MYSQL: ${{ matrix.php == needs.php.outputs.lowest && 'root:secret@127.0.0.1:3306' || '' }}
# EVO_TEST_REDIS: 127.0.0.1:6379
run: composer test -- --compact --fail-on-warning --fail-on-risky --fail-on-deprecation

install:
name: Install on ${{ matrix.db }}
name: Install on ${{ matrix.db }}${{ matrix.engine && format(' ({0})', matrix.engine) || '' }}
needs: php
runs-on: ubuntu-latest
strategy:
Expand All @@ -149,6 +157,13 @@ jobs:
- db: mysql
user: root
password: secret
# MyISAM is a supported engine (the installers write it for older
# servers, sites keep it), and its key limit of 1000 bytes is one a
# utf8mb4 index has to fit; the suite runs on sqlite and never sees it.
- db: mysql
engine: MyISAM
user: root
password: secret
- db: pgsql
user: evo
password: secret
Expand Down Expand Up @@ -197,6 +212,7 @@ jobs:
EVO_DB_PASSWORD: ${{ matrix.password }}
EVO_DB_NAME: evolution
EVO_DB_PREFIX: evo_
EVO_DB_ENGINE: ${{ matrix.engine || '' }}
run: .github/docker/ci/install-and-smoke.sh

- name: Database server log
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ on:
from_repo:
description: 'Repository the source versions are taken from'
default: 'evolution-cms/evolution'
legacy:
description: 'mysql legs - turn the older site into MyISAM / utf8mb3 before upgrading it'
type: choice
default: none
options: [none, myisam]

permissions:
contents: read
Expand All @@ -58,18 +63,20 @@ jobs:
env:
FROM: ${{ inputs.from }}
DB: ${{ inputs.db || 'all' }}
LEGACY: ${{ inputs.legacy || 'none' }}
run: |
if [ -z "${FROM:-}" ]; then
# The nightly sweep: the oldest version still worth supporting, the
# last release, and sqlite from the branch that introduced it.
legs='[{"db":"mysql","from":"3.2.7"},{"db":"mysql","from":"3.5.7"},{"db":"pgsql","from":"3.2.7"},{"db":"pgsql","from":"3.5.7"},{"db":"sqlite","from":"nightly-3.5.x"}]'
legs='[{"db":"mysql","from":"3.2.7"},{"db":"mysql","from":"3.5.7"},{"db":"mysql","from":"3.5.7","legacy":"myisam"},{"db":"pgsql","from":"3.2.7"},{"db":"pgsql","from":"3.5.7"},{"db":"sqlite","from":"nightly-3.5.x"}]'
else
dbs=$([ "$DB" = "all" ] && echo "mysql pgsql sqlite" || echo "$DB")
legs=$(
for db in $dbs; do
echo "$FROM" | tr ',' '\n' | while read -r ref; do
ref=$(echo "$ref" | tr -d '[:space:]')
[ -n "$ref" ] && printf '{"db":"%s","from":"%s"}\n' "$db" "$ref"
legacy=$([ "$db" = "mysql" ] && [ "$LEGACY" != "none" ] && echo "$LEGACY" || true)
[ -n "$ref" ] && printf '{"db":"%s","from":"%s","legacy":"%s"}\n' "$db" "$ref" "$legacy"
done
done | paste -sd, - | sed 's/^/[/; s/$/]/'
)
Expand All @@ -78,7 +85,7 @@ jobs:
echo "$legs"

upgrade:
name: ${{ matrix.leg.from }} -> ${{ inputs.to || 'this tree' }} on ${{ matrix.leg.db }}
name: ${{ matrix.leg.from }} -> ${{ inputs.to || 'this tree' }} on ${{ matrix.leg.db }}${{ matrix.leg.legacy && format(' ({0})', matrix.leg.legacy) || '' }}
needs: matrix
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -148,6 +155,7 @@ jobs:
EVO_DB_PASSWORD: secret
EVO_DB_NAME: evolution
EVO_DB_PREFIX: evo_
EVO_DB_LEGACY: ${{ matrix.leg.legacy || '' }}
run: new/.github/docker/ci/upgrade-and-smoke.sh

- name: Database server log
Expand Down
30 changes: 29 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,34 @@ are resolved), never of the way it was found; `plan()` and `planInstall()` refus
`composerRuntimePackages()` for it, and `make:site` asks them on every update that runs it, custom
packages or not (an update package's `vendor/` may differ from its lock: 3.5.8's does).

### Migrations on MySQL: MyISAM and older charsets

MyISAM is a supported engine, not a legacy one: the installers write it into the connection config for
servers older than MySQL 5.7.6, and sites keep it, often with `charset` `utf8` (utf8mb3) and
`engine` `MyISAM` in `core/config/database/connections/default.php`. A migration has to get through
such a site as it is. Never make an update depend on converting tables to InnoDB or utf8mb4.

- An index key on MyISAM holds at most 1000 bytes (InnoDB with the DYNAMIC row format: 3072). A
utf8mb4 character counts 4 bytes, utf8mb3 3: a utf8mb4 `VARCHAR(255)` (1020) cannot be indexed on
MyISAM, and a unique `(INT, VARCHAR)` fits up to `VARCHAR(249)`. Size an indexed string column for the
engine and charset the table really gets (`core/includes/file_groups_schema.php`: `newTableEngine()`,
`newTableCharset()`, `fittingLength()`), never a prefix on a unique key.
- Change only what the migration is for. Reaching a collation through `CHARACTER SET utf8mb4` converts
the column too and widens its keys (error 1071 in `2026_10_11_000000_make_file_groups_file_case_sensitive`
up to 3.5.12). Read charset, collation and length from `information_schema` and keep them; take
collation names from `information_schema.COLLATIONS` (`utf8_bin` on MySQL 5.7, `utf8mb3_bin` on 8.0),
and expect a config that says `utf8` where MySQL 8.0.30+ lists only `utf8mb3`.
- A `Schema::create()` that fails after the table exists leaves it behind without its indexes, and the
next run skips a create guarded by `hasTable()`. Make sure the create cannot fail on a supported
configuration; where one already did, ship an idempotent repair
(`2026_12_05_000000_restore_file_groups_indexes`).
- The installer runs `install/stubs/migrations`, artisan `core/database/migrations`: a migration in both
changes in both. A migration loads shared code by path (`require EVO_CORE_PATH . 'includes/...'`), not
through a new class: the web installer migrates before it rebuilds the authoritative classmap.
- Pest runs on SQLite and never meets these limits. The `install` job of `ci.yml` installs on MySQL with
MyISAM as well (`EVO_DB_ENGINE`), and `upgrade.yml` upgrades a site turned MyISAM / utf8mb3
(`EVO_DB_LEGACY=myisam`, nightly and on demand); check a migration with MySQL DDL against both.

### Installing Evolution CMS packages

Install Composer packages from the `core/` directory through the Evolution CMS package installer:
Expand Down Expand Up @@ -495,7 +523,7 @@ The name check also catches the spellings Windows turns into such a file: traili
| Rename, move or delete an existing entry (media browser too) | the top-level rule of the classic manager, measured from the manager's own `filemanager_path` (`canModifyExisting()` in `browser.php`) |
| Delete a link | removing a symlink or junction (a passable one through the folder or file delete, any other through `deletelink`) removes the link only and never forgets the groups stored under its name, which apply again if the link returns |
| Upload over an existing file | the file's own restrictions, not just the folder's (`fileManagerCanModifyExistingPath()`); the file keeps them and is **not** given the folder's groups |
| Copy / duplicate (both file managers) | access is an AND over the restricted folders on the way and the file itself, each an OR over its groups, which one set of groups on one key cannot say. `FileManagerAccess::carriedRestrictions()` keeps the groups that satisfy every set the destination does not already enforce; the copy is refused when there are none, and when the destination is the ACL root itself or lies outside it (no per-entry row can be stored there). Never store the union of the groups. A copy takes `replaceRestrictions()` and a rename or move takes `moveRestrictions()`, which first drops rows left at the free destination by files removed outside the CMS. Rows are matched by the exact stored path (`exactRows()`), and the `file_groups.file` column is case-sensitive (`utf8mb4_bin` on MySQL), because on a case-sensitive file system `report.txt` and `REPORT.txt` are two files |
| Copy / duplicate (both file managers) | access is an AND over the restricted folders on the way and the file itself, each an OR over its groups, which one set of groups on one key cannot say. `FileManagerAccess::carriedRestrictions()` keeps the groups that satisfy every set the destination does not already enforce; the copy is refused when there are none, and when the destination is the ACL root itself or lies outside it (no per-entry row can be stored there). Never store the union of the groups. A copy takes `replaceRestrictions()` and a rename or move takes `moveRestrictions()`, which first drops rows left at the free destination by files removed outside the CMS. Rows are matched by the exact stored path (`exactRows()`), and the `file_groups.file` column is case-sensitive (on MySQL the binary collation of the column's own character set: converting it to utf8mb4 would push the indexed column past the MyISAM key limit), because on a case-sensitive file system `report.txt` and `REPORT.txt` are two files |
| Any name the media browser writes (copy, move, upload, thumbnail) | the destination is free, a dangling symlink counts as taken (`isTaken()`), and copies are made exclusively with `copyExclusive()` (`fopen` mode `x`), never `copy()` through a link |
| Move (media browser) | the same `carriedRestrictions()`, read before the move and applied with `replaceRestrictions()` after it (a moved file brings its own, possibly wider, groups); refused when no set expresses it |
| ZIP extraction | the archive and the target folder, and **each entry** via `fileManagerZipWriteGuard()` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CreateFileGroupsTable extends Migration {
Expand All @@ -10,11 +11,31 @@ public function up() {
return;
}

Schema::create('file_groups', function(Blueprint $table) {
// File group keys are paths and must stay case-sensitive; on MySQL the column takes the
// binary collation of the connection's charset, and on MyISAM a length its key limit allows.
$length = 255;
$collation = null;
$connection = DB::connection();
$schema = require EVO_CORE_PATH . 'includes/file_groups_schema.php';
if ($schema->isMysql($connection)) {
$charset = $schema->newTableCharset($connection);
if ($charset !== null) {
$collation = $schema->binaryCollation($connection, $charset);
$length = $schema->fittingLength(
$schema->keyLimit($schema->newTableEngine($connection)),
$schema->bytesPerCharacter($connection, $charset)
);
}
}

Schema::create('file_groups', function(Blueprint $table) use ($length, $collation) {
$indexPrefix = \DB::getTablePrefix() . $table->getTable();
$table->integer('id', true);
$table->integer('document_group')->default(0)->index("{$indexPrefix}_document_group");
$table->string('file', 255)->default('')->index("{$indexPrefix}_file");
$file = $table->string('file', $length)->default('')->index("{$indexPrefix}_file");
if ($collation !== null) {
$file->collation($collation);
}
$table->unique(['document_group', 'file'], "{$indexPrefix}_ix_fg_id");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,42 @@
* File group keys are paths, and on a case-sensitive file system report.txt and REPORT.txt are two
* files. A case-insensitive column collation (the database default for utf8mb4_unicode_ci) treats
* their rows as one, and the unique index then refuses the second one: the copy stays unrestricted.
*
* Only the collation changes, to the binary one of the column's own character set; length and
* character set stay. Converting utf8mb3 to utf8mb4 would widen the indexed column past the key
* limit of MyISAM (1000 bytes), and the update would stop there.
*/
class MakeFileGroupsFileCaseSensitive extends Migration
{
public function up()
{
if (!Schema::hasTable('file_groups') || DB::connection()->getDriverName() !== 'mysql') {
$connection = DB::connection();
$schema = require EVO_CORE_PATH . 'includes/file_groups_schema.php';
if (!Schema::hasTable('file_groups') || !$schema->isMysql($connection)) {
return;
}

$table = DB::getTablePrefix() . 'file_groups';
$current = DB::selectOne(
'SELECT COLLATION_NAME AS collation FROM information_schema.COLUMNS'
. ' WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?',
$current = $connection->selectOne(
'SELECT CHARACTER_SET_NAME AS charset, COLLATION_NAME AS collation, CHARACTER_MAXIMUM_LENGTH AS length'
. ' FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?',
[$table, 'file']
);
if (!$current || str_ends_with((string) $current->collation, '_bin')) {
if (!$current || empty($current->charset) || str_ends_with((string) $current->collation, '_bin')) {
return;
}

DB::statement("ALTER TABLE `{$table}` MODIFY `file` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT ''");
$collation = $schema->binaryCollation($connection, (string) $current->charset);
if ($collation === null) {
return;
}

$connection->statement($schema->modifyFileStatement(
$table,
(string) $current->charset,
$collation,
(int) $current->length ?: $schema::LENGTH
));
}

public function down()
Expand Down
Loading
Loading