Skip to main content
Version: Fegg 5.x

Moving a Fegg 3 / 4 project

Fegg 5 keeps no compatibility with Fegg 3 / 4 code: there is no getClass(), no Fegg 4 class names (MyApplication, Model, DB_pdo, LH_FW ...), and controllers without a namespace are not dispatched. A project is not upgraded in place: start a new project from the Fegg 5 skeleton and bring over what belongs to the project, rewriting its PHP in the Fegg 5 style. The database, the uploaded files, the templates and the front-end files carry over. Once rebuilt, the project is updated with fegg-cli core:update like any Fegg 5 project.

This page is a summary. The full steps, with the commands and the complete tables, are in docs/migration-v3-v4-to-v5.md of the skeleton repository.

Work on a new branch of the project repository (the old code stays on the old branch) and test against a copy of the production database.

1. List what the old project has of its own​

Find the skeleton version the project started from (version in package.json, or @version in fegg/Application.php). Check out the skeleton at that tag, copy the project's core files over it (fegg/, code/lib/, code/application/cms/, code/template/cms/, htdocs/cms/, htdocs/index.php, htdocs/.htaccess) and look at git diff. Write down:

  • Changes to the core: Fegg 5 rewrote most of the core, so decide for each whether the project still needs it. What is still needed is written again as an override in site/ (see Controller).
  • The project's own code: controllers (public pages and post types), project libraries in code/lib/, code/lib/Modifire.php, processing added to MyApplication.
  • The project's own files: templates, htdocs/data/ (SCSS, JS, images), table definitions, config values, code/data/, uploads.

2. Start from the Fegg 5 skeleton​

  1. Replace the branch's contents with the Fegg 5 skeleton (everything except .git) and rename it as for any new project (the package name in package.json, the local URL in e2e/playwright.config.ts).
  2. Copy site/config/env.php.dist to site/config/env.php on each development or staging server and set 'FEGG_ENV' => 'development': without it the site runs as production and shows no error details (see Settings).
  3. Set the values the project changed in the old fegg/settings.php (developer_ip, run_mode, maintenance_page_url, Basic authentication, languages) in site/config/settings.php.
  4. Add the project's own rules of the old htdocs/.htaccess (redirects, headers) to the new one. If the project changed the paths in index.php, set the three constants (FEGG_HTML_DIR, FEGG_CORE_DIR, FEGG_SITE_DIR) to match (see Directory structure).

3. Bring over the files that carry over​

v3 / v4Fegg 5
htdocs/data/ (SCSS, JS, images)htdocs/_fegg/site/template/main/ (scss/, js/, img/; npm run build:scss)
htdocs/cms/scss/unique.scss (the project's CMS styles)htdocs/_fegg/site/template/cms/scss/unique.scss
code/template/ except cms/htdocs/_fegg/site/template/main/tpl/ (check with ./fegg-cli template:lint)
code/template/cms/<post type>/htdocs/_fegg/site/template/cms/tpl/<post type>/
code/config/database/ (project tables)htdocs/_fegg/site/config/database/
Project values in code/config/Merged into the skeleton's files in htdocs/_fegg/site/config/
code/data/htdocs/_fegg/site/data/
htdocs/up_dir/htdocs/_fegg/site/up_dir/ (served at /_fegg/site/up_dir/)
The post types in the old CMS menuhtdocs/_fegg/site/config/cms_menu.php, one block each

fegg/, the core's libraries in code/lib/, the core's CMS screens and templates, bin/ and htdocs/cms/ are not brought over: the skeleton has their Fegg 5 versions.

Template paths are relative to main/tpl/ (see Sites). In the templates, replace {{ base }}/data/ with {{ $site.assets }}/ ({{ $site.assets }}/css/style.css, {{ $site.assets }}/img/...).

The uploaded files' URL becomes /_fegg/site/up_dir/.... Rich text saved in the database still links to /up_dir/: replace it in every column that holds rich text, for example:

UPDATE cms_news SET content = REPLACE(content, '/up_dir/', '/_fegg/site/up_dir/');

The database is used as it is: point the project at a copy of the production database and run ./fegg-cli migration, which only adds the new core tables (such as rate_limit).

cms_news.category holds the keys of $category_info['news'] (info, recruit). In Fegg 5 the column is CHAR; in the v3 / v4 skeleton it was INTEGER. Change it in the cms_news.yaml you bring over (and in other post types whose category keys are text), and ./fegg-cli migration changes the column and keeps the values. On SQLite the keys were stored as text all along. On MySQL they were not: the connection runs without strict mode, so every key was saved as 0. Check with SELECT category, COUNT(*) FROM cms_news GROUP BY category; a category saved as 0 cannot be recovered and has to be set again.

4. Rewrite the PHP​

Write each controller again as a namespaced class in htdocs/_fegg/site/src/Controller/, replace the Fegg 4 classes with their Fegg 5 names, and add $this->requirePost() to every CMS action that changes data. Then go through the behaviour changes: Fegg 5 fails loudly where Fegg 4 was silent.

5. Check​

  • ./fegg-cli template:lint prints OK
  • php -l reports no syntax errors for the PHP files under htdocs/_fegg (excluding vendor/ and data/)
  • ./fegg-cli migration against a copy of the production database only adds new core tables such as rate_limit (no project table definition is missing, and every YAML file is read: an error names the file and the line)
  • ./fegg-cli core:status prints No changes to core files.
  • The browser console of every CMS screen shows no errors ($ is not defined means a template still uses jQuery), and dates (with the time), rich text and gallery ordering are saved
  • Public pages, the contact form (through to sending), CMS login, create / edit / delete for each post type, and media and image uploads work, with the data and uploads of the old site
  • Every post type appears in the CMS side menu and on the dashboard
  • Every saving action in site/src/Controller/Cms/ calls $this->requirePost(): opening its URL in the browser (a GET, e.g. /cms/news/update/) answers 405
  • No page links to an action named like a method of Fegg\Application (mail, in, redirect ...) or defined only in a base controller (both are 404 now)
  • The PHP error log has no warnings
  • After deploying, ./fegg-cli doctor https://<production URL> prints OK (/_fegg/assets/js/base.js is served; the rest of /_fegg/, the sites' SCSS sources included, is not) and the CMS dashboard shows no protection warnings

To roll back, redeploy the old branch. The table definitions are compatible, so the same database works with both.