Behaviour changes
Fegg 5 fails loudly where Fegg 4 was silent. The full list is in the 5.0.0 section of htdocs/_fegg/core/UPGRADE.md. The ones most likely to affect code brought over:
Database and models
- Database errors throw
Fegg\Database\QueryException(the message includes the SQL and its parameters) instead of printing and callingexit. Uncaught, it is a logged HTTP 500. updateWhere(),deleteWhere()anderaseWhere()with an empty condition throw instead of affecting every row. Pass'1 = 1'where every row was really meant.Model::order(),join()and thetable/id/visibleoptions accept only plain names. Move expressions toorderRaw().- MySQL is strict outside production: on the develop server
''or text in anINTcolumn, more than 255 characters in aCHARor an impossible date throw instead of being stored as0, a cut text or a zero date (production stays lenient; see Configuration). Bind the models' number and date columns ('image_id' => 'INTEGER'): a field the form leaves out is then saved as0/NULL.nullgiven toinsert()/update()is saved asNULL(it was''). ORin conditions is bracketed:where('category = ?', 1)->where('a = ? OR b = ?', ...)iscategory = 1 AND (a = ? OR b = ?), and the visible flag andvalid = 1are added outside the brackets. In Fegg 4 such conditions matched rows of every category, andwhere('a = ?', 1)->where('b = ?', 2, 'OR')also returned unpublished and deleted rows matchingb; such lists can get shorter.
Templates
- Missing templates,
includetargets andtranscludeparents throwFegg\Template\TemplateException(HTTP 500) instead of printing "Can't Read" into the page../fegg-cli template:lintlists them all. - Template blocks are checked: an unclosed block or an extra
{{ end }}throws with the line number. - Sections are passed to the parent template as closures. Code that called the global
section_<name>()functions directly must be rewritten. {{ options }}escapes labels and values, and{{ hidden }}escapes values.- Arrays reach modifiers:
{{ $tags|feggImplode:', ' }}now prints the joined tags (it printed nothing).
Requests, sessions and security
- Actions: only a controller's own public methods can be called from a URL (see Controller). An action defined in
MyApplicationor a base controller is a 404: write it in each controller that uses it. An action named like a method ofFegg\Application(mail,in,redirect...) is a 404: rename it, or map the old URL with a route. - Basic authentication with
basic_auth_scope = 1is checked before the controller's__init()and action, so redirects, downloads and direct output are protected too. - No more
exit: Fegg ends responses by throwingFegg\Http\Halt; rethrow it from acatch (\Throwable $e)and replace your ownexitwith$this->halt()(see Ending a response). - Sessions and cookies: a session starts only when something is written to it (see Session).
setCookie()takes SameSite as its own argument (not'/; SameSite=Lax'in the path), andunsetCookie()really deletes the cookie (Fegg 4 set an empty cookie for 7 days; see setCookie). - Security headers are sent with every response; a page framed by another site calls
$this->allowFraming()(see Security). - HTTPS is detected from more server variables and proxy headers, and
redirect()no longer sends HTTPS pages to HTTP when the detection fails (see Security). - Route-only controllers: controllers that implement
Fegg\Http\RouteOnly(such as the skeleton'sSite\Controller\Page) are only reached throughsite/config/route.php. Add a route such as$route['about/'] = 'page/render/about';for each static page that was reached as/page/render/...(see URL). htdocs/.htaccess: remove the<IfModule mod_php5.c>block and the Apache 2.2Order/Deny from alllines (500 on Apache 2.4), and add the dotfile rules and the_feggexceptions (the CMS's files, the site folders, the uploads) ofcore/dist/htaccess.dist. On nginx, use the rules of Directory structure.fegg-cli doctorwarns about the old lines.- Captcha keys and the database DSN move to
env.php: the skeleton'sdatabase_config.phpandcontact/contact_config.phpread them withfeggEnv(). Put the project's keys there, not in committed files.
CMS
- CMS sessions need the session's user to still exist in
cms_user: deleting a user ends their sessions. - CMS login: logout is a POST. Copied CMS frame templates in
site/template/cms/tpl/add the classjs-cms-logoutto the logout link. Runfegg-cli migrationfor the login throttling tablerate_limit./cms/login/create/...is gone: usefegg-cli user:create(see fegg-cli). - The CMS's files are in
htdocs/_fegg/assets/, read at/_fegg/assets/. Copies of CMS templates insite/template/cms/tpl/load them with{{ $site.cms_assets }}instead of{{ $site.cms_dir }}(css/,js/,img/,vendor/)._fegg/can no longer be outside the document root. See CMS screens and the editor. - No jQuery in the CMS (nor jQuery UI, Select2 or the datetimepicker). Rewrite
$(...)in the project's CMS templates (site/template/cms/tpl/*/html_head.tpl) with plain JavaScript and theFeggCmshelpers, or load a jQuery of your own there. Date fields becomedatetime-localinputs and drag & drop ordering uses SortableJS (see Dates and Drag and drop ordering). - CKEditor 4 is removed. Rich text fields use FeggEditor: replace
CKEDITOR.replace(...)andckeditor/ckeditor.jswithdata-fegg-editor="full"on the textarea andjs/editor.js, and clean the saved HTML withFegg\Cms\HtmlSanitizer::clean(). Text written with CKEditor opens in FeggEditor. Copiedcms/image/andcms/media/templates use the new picker scripts (js/modal/image_picker.js,file_picker.js; parametersfrom=wysiwyg&picker=<id>). - Font Awesome 4.3 is removed. Icons are Tabler Icons: replace
fa fa-…withti ti-…:search→search,angle-right→chevron-right,image/picture-o→photo,times→x,cog→settings(pencil,trash,plus,link,check,download,uploadkeep their names; others: tabler.io/icons). An icon the core does not use needs a line inunique.scss(see Icons). Copies ofcms/frame/sitewire.tplandpopframe.tplloadvendor/tabler-icons/icons.cssinstead offonts/font-awesome.min.css.
Libraries
- Uploads check the content against the extension; add the
@contentmessage to a copiedsite/config/file_error_message.php(see Upload). - Spyc is removed. YAML is read by
Fegg\Tool\Yaml(see Yaml): replacespyc_load_file()/Spyc::YAMLLoad()in project code withFegg\Tool\Yaml::parseFile(). Table definitions read as before;yes/noand numbers with a leading zero are now text, and anchors or tags are refused with the file and the line. getDatetime()/convertDatetime()no longer change the process-wide time zone, andconvertDatetime()returns''for a date it cannot read (it returned1970-01-01 ...).- Images in other sizes (
getImageUrl) are limited byimage_maxandimage_cache_maxinsite/config/upload_dir.php, and the positionslbandrbnow keep the bottom left and the bottom right (see Trim). Fegg\Tool\Trimthrows a\RuntimeExceptionfor a missing file, a file that is not a JPEG, PNG or GIF, or another output type (it calledexit).Fegg\Tool\Filemethods returntrue/false.removeDirectory()removes symbolic links, never what they point to.Fegg\Tool\Upload::upload()for a field the form does not have is@empty(or OK when not required), and several files (name="file[]") are@failed, without PHP warnings.Fegg\Tool\Mail: the debug log ismail.login the log directory (it was/tmp/sendmaillog).send()without a sender uses$settings['mail']['from']/['from_name'], or throws an\InvalidArgumentException.Fegg\Tool\RSSthrows a\RuntimeExceptionfor a feed it cannot fetch or read, and keeps posts whose title contains "PR:": passarray('skip_pr' => true)to leave them out as before.
Additional work for v3 projects
- Mail (
Fegg\Tool\Mail) uses PHPMailer.sendWithFile(),setInputCharset()andsetSendCharset()were removed: add attachments withpushAttached()and callsend(). A failed send throwsPHPMailer\PHPMailer\Exception. - Trailing slash: URLs without an extension are redirected (301) to the same URL with a trailing
/. Check the keys inroute.phpand the links in templates. - PHP 8: fix deprecation warnings in the project code (for example passing
nullto string functions).