# Buzzour migration

This project is a work in progress, not a replacement ready for deployment.
The legacy application remains in `html/`. The new application uses PHP 8.5
and CodeIgniter 4.7.6, with `public/` as its document root.

The migrated homepage, category and type listings, load-more endpoint, and
informational pages do not yet cover the full legacy site. Normal personality,
poll, and video quizzes and lists can be played through their legacy display-ID
and username/slug routes;
follow/unfollow endpoints and legacy email sign-in use the current CI4 session.
The homepage shows its initial quiz listing without infinite scroll. Category
and type listings that use the shared listing template still load more on scroll.
Outside production, the homepage, News menu listings, and quiz category, type, and search listings
skip legacy ad and sponsored-search scripts that block rendering of Trending
Today and Latest Buzzes. The Trending Today
Search and Popular Topics widget loads in its own iframe without sending the
development URL to the provider.
Legacy `/log/impression` and `/log/completion` requests use the current
installation's URLs and return an empty response, matching the old controller
with its Redis writes disabled.
Search accepts the legacy `search` parameter and the `q` alias on clean and
development `?/` URLs. On mobile, quiz search is visible without opening the
navigation menu. The sponsored search feed is not yet migrated.
The News menu and `/articles` use the existing `cms_new` connection (`cms`).
News uses legacy site ID 208; the blog uses site ID 320. Article details
use PHP's DOM extension to preserve basic formatting without legacy scripts, raw
embeds, or advertising inserts. News cards show the legacy relative byline and
crop original CMS images to the 126 × 83 listing thumbnail slot because the legacy `_small`
variant tested in production returned HTTP 403. News listings and details show
Trending Today and Latest Buzzes using public quizzes, without the legacy paid
sidebar scripts. News details show the reporter byline and link
to the next published, approved article in the same category when available.
Blog search uses the legacy quoted full-text phrase query and requires the
existing CMS FULLTEXT index on `title`, `content`, and `keywords`. Shared
development currently has no published, approved blog posts to display.
The blog shows the total number of matching articles and preserves the search
term across numbered pagination links. Cards use a local placeholder image
when no usable article image exists.
The static `/buzzarticle` example uses local placeholder images. It has no
additional pages or share action in the legacy source. The `/article` sample
has no backing article in the legacy controller, so it displays a notice and a
link to the blog instead of blank fields or an invalid date. Exact article
layout parity remains pending.
Gallery slideshows use their legacy username/slug routes. The cover and last slide
send impression and completion requests to the local no-op endpoints; these do
not record analytics, matching the old controller's disabled Redis writes.
Image quizzes and arbitrage personality and video quizzes use paginated routes
and CI4 sessions for answers, including the legacy display-ID routes.
Personality quizzes can also be played in the legacy embedded layout. Affiliate
widget selection currently selects only personality quizzes. The embed sends
impression and completion requests to the same local no-op endpoints as galleries.
The creation landing page and basic authoring for all six formats are implemented.
The editor shows a copyable player link for saved public and link-only content.
Drafts, private content, and unsaved previews do not show a share link.
The poll editor supports drafts, categories, choices, preview, and publishing.
Intro and choice images accept files, image links, or copies of remote images.
The list editor supports drafts, ordered items with
descriptions, image links and uploads, categories, preview, and publishing.
The BuzzGallery editor uses the same legacy question and answer tables for
its ordered, paginated slideshows. The existing landing page visibility rule for
BuzzGallery remains unchanged.
The video quiz editor supports ordered questions, a dialog for YouTube and legacy
Colo links, YouTube start times in seconds, `M:SS`, or `H:MM:SS`, question images,
and multiple-choice answers with one
correct answer per published question.
The personality and interactive gallery editors support multiple outcomes with
descriptions and images. Authors select named results from a dropdown that updates
as outcomes are added or renamed. Each answer on a published quiz must map to an outcome
owned by that quiz. Interactive gallery answers also require images. Writes
require transactional copies of both the question/answer tables and
`rep_survey_results`.
The editors share an image picker for selecting files, setting image links,
and optionally copying up to three public image URLs into quiz storage per
save, where image links are supported. URL copies require PHP cURL; the same
image processing and access rules apply as for uploads. Selections are applied
only on Save or Publish. The image picker edits the existing attribution
fields for intro images, poll choices, questions, slides, list items, and
outcomes. The personality embed displays intro and question credits.
Copying an intro image defaults a blank attribution to the source domain.
The editors use the legacy responsive step labels,
numbered items, collapsible content panels, and side-by-side image and text
layout on larger screens. The options sidebar groups the Facebook image,
categories, voting or order, and privacy into separate panels. After a
rejected save or preview, all panels open so submitted fields remain visible.
The exact layouts and media dialogs are not yet reproduced. Poll writes
require transactional copies of the existing `rep_surveys`,
`rep_survey_results`, and `rep_survey_survCat` tables. The current shared
development copies use MyISAM, so the app blocks those writes rather than risk
a partial save. Published choices cannot be removed through this editor
because they may already have votes.
List, BuzzGallery, and video quiz writes also require transactional copies of `rep_survey_ques`,
`rep_survey_survQues`, `rep_survey_ans`, and `rep_survey_quesAns` in place of
the poll result table. Those tables are also MyISAM on shared development.
On a temporary socket-only Percona 5.7 instance with synthetic fixtures,
poll publishing and the MyISAM write guard passed. Registration model writes
also committed and rolled back together with their confirmation records.
These checks do not replace verification against a deployment-like copy
of the legacy tables or an end-to-end confirmation email test.
Editor uploads accept JPG, PNG, and GIF files up to 8 MB each (24 MB per save)
and require PHP GD. Use PHP and web server upload limits that match these
limits. Files are stored under `writable/uploads/poll-images` by default
(`pollimages.directory`) and served through an access-checked route. Configure
persistent storage that is **not directly served over HTTP** before enabling
poll writes; otherwise drafts and private images could be exposed. Back up
that storage together with the legacy database.
Legacy email passwords are still verified against the existing MD5 field and need
a secure password-hash migration before deployment. New email registrations store
bcrypt hashes in the existing `rep_survey_users.pwd_md5` column; the old CI2
application cannot authenticate these new hashes. Registration requires that column
to hold at least 60 characters, transactional legacy user and email-confirmation
tables, and a configured `Email` sender and transport. Publisher registration
is unavailable because the existing user schema has no company or phone fields.
If sending the confirmation fails, registration rolls back both the account
and its confirmation record. The automated test follows the activation link
generated in the email body; production email delivery still needs verification.
The account lifecycle also passes against schema-only copies of the actual
legacy account tables on an isolated MySQL instance using InnoDB and a
loopback-only SMTP capture: signup, activation, bcrypt and existing MD5 login,
logout, and rollback after SMTP rejection. No shared accounts or external mail
were used. The shared development account tables still use MyISAM, so signup
remains unavailable there until an approved InnoDB conversion. Configured SMTP
credentials alone do not establish real inbox delivery.
`/login` and `/sign-in` show the email sign-in form; `/register` shows signup.
The email forms use native submit buttons and browser validation, without
depending on jQuery or the obsolete Google+ SDK. Signup configuration failures
keep the branded form visible with HTTP 503 and a support message.
Social sign-in buttons are disabled with an explicit email-login alternative;
social sign-in
and existing CI2 sessions are not yet migrated. Existing email-confirmation and
unsubscribe links are supported. Other quiz layouts are still pending. Other authentication features,
other quiz play and result routes, content creation, integrations,
legacy session compatibility, and Redis caching still need migration.
The `buzz-admin` sign-in, user dashboard, quiz filters, and moderation use the
existing `rep_hoe_admin`, `rep_survey_users`, and `rep_surveys` tables. Moderation
requires an admin session and CSRF-protected POST requests. Production admin
sign-in requires password hashes in the existing admin password column; rotate
legacy plaintext passwords before cutover. For an isolated development
installation only, `BUZZ_ADMIN_ALLOW_LEGACY_PASSWORDS=true` can enable temporary
compatibility. Admin sign-in also requires a working rate-limit cache.
Unpublished, removed, and private quizzes are no longer playable by direct
link. Published link-only quizzes remain playable by direct link but do not
appear in public listings or trending.
Member profiles, profile editing, the member directory, and SEO-profile pages
are also available where their legacy tables exist. The member directory needs
`Admin.rep_survey_users_spokeo`, which is absent from shared development.
`drest Admin rep_survey_users_spokeo` returned `Table "rep_survey_users_spokeo"
not exist`; restoring the directory requires an approved backup that contains
that table. Until then, the directory returns HTTP 503 with a friendly notice
in the normal site layout, without pagination or data from another table.
Profile images can be uploaded from a file or imported from a public image URL.

The default database configuration can load the shared legacy settings described
below; override them to point to an approved isolated copy when testing. Do not
put credentials in any location accessible over HTTP. The homepage returns HTTP
503 when no database is configured. Until OpenResty is configured, use the
development URL format `.../public/?/about` (and `.../public/?/search?search=weather`
for a route with query parameters). For clean URLs, have the server admin point
the application document root at `public/`, configure OpenResty to pass routes
that are not public files to `index.php` while retaining the query string (for a
dedicated virtual host: `try_files $uri $uri/ /index.php?$query_string;` in its
application location), and set `app.indexPage = ''`. For a subpath deployment the
fallback must use the mounted path. Ensure the project root and `.env` are not
HTTP-accessible before using deployment credentials. Apache's `.htaccess` rules
do not configure OpenResty.
The development debug toolbar supports the legacy `?/` route setup. Disable
the toolbar and detailed error output in production.
Affiliate-selected widgets use the `default` database group (`Admin`) by default.
Set `affiliate.databaseGroup` to another configured group if the affiliate tables
are hosted elsewhere.
Profile image uploads require PHP GD (and cURL for URL imports) and a persistent writable
`writable/uploads/profile-images` directory (configurable via
`profileimages.directory`). Back up and share this directory across application
instances; unlike the legacy image service, these files are served locally.

### Legacy database, Redis, and email settings

Outside PHPUnit, when present, the shared
`/opt/msacommon_ci/html/application/config/database.php` is loaded as trusted
PHP and its database groups are mapped to CI4. `default` uses `admin_db`, and
the original group names (including `cms`) remain available. The file loads
the legacy `dbConstants.php` using `/opt/msa` on the PHP include path. It may
contain shared-service credentials: **normal application requests can access
those databases**, including writes. Use CI4 `database.<group>.*` settings to
point every used group at an isolated database when appropriate. The loader
defines the legacy `BASEPATH` guard for compatibility and restores the
original include path afterward.

Set `BUZZOUR_LEGACY_DATABASE_CONFIG_FILE` to select another trusted PHP file;
an explicitly selected missing or unreadable file is an error. When the shared
file is absent, CI4 groups must be configured separately. PHPUnit does not
automatically load the shared file.

The database groups accept the legacy `MSACOMMON_DB_HOST_ADMIN`,
`MSACOMMON_DB_USER_ADMIN`, `MSACOMMON_DB_PASS_ADMIN` and corresponding
`MSACOMMON_DB_HOST_LIVE`, `MSACOMMON_DB_USER_LIVE`, `MSACOMMON_DB_PASS_LIVE`
environment variables, along with the corresponding `LOCALPAGES`, `WHALE`,
`CMS`, and `STATS39` names for the other constant-backed groups. Alternatively,
set `MSACOMMON_DB_CONSTANTS_FILE` to an absolute, readable PHP constants file
outside the public document root. This file is executed as trusted PHP.
Selecting a constants file disables automatic loading of the shared database
file; explicitly select a compatible database file too if its other groups
are needed.
Environment variables override constants; individual CI4 `database.<group>.*`
settings take precedence. Incomplete legacy credentials fail explicitly.

`REDIS_CACHE_IP`, `REDIS_CACHE_PORT`, and `REDIS_CACHE_PREFIX` configure the
legacy quiz Redis connection. `legacyredis.quiz.*`, `legacyredis.default.*`,
`legacyredis.slave.*`, `legacyredis.cmsRead.*`, and `legacyredis.cmsWrite.*`
override each connection's `host`, `port`, `password`, `database`, and `timeout`.
The default/slave groups correspond to the old Redis library; the CMS groups
correspond to the shared article CMS's read and write Redis endpoints.
Connections are lazy and available through
`service('legacyRedis')->connect('quiz')` (or the other group names).
They require the PHP Redis extension. If `cache.handler` is explicitly set to
`redis`, the CI4 cache uses the quiz connection unless `cache.redis.*` overrides
it, and prefixes its own keys with `REDIS_CACHE_PREFIX` plus `ci4:`. The
default cache remains file-based. Configuring Redis does not yet migrate the
legacy quiz-cache or tracking behavior.

When present outside PHPUnit, `html/application/config/email.php` supplies the
legacy SMTP settings and sender to CI4's email service. This can enable real
email delivery from registration and sharing; use `email.*` environment
overrides for an isolated SMTP server and sender in testing. Set
`BUZZOUR_LEGACY_EMAIL_CONFIG_FILE` to select a different trusted PHP config;
an explicitly selected missing or unreadable file is an error. CI4 sends the
mail rather than the old PHPMailer wrapper and retains RFC-compliant CRLF
line endings. SMTP debug and PHPMailer-specific options are not migrated.

Legacy site, file-mode and stream constants are available in CI4. The
environment-dependent legacy constants follow `CI_ENVIRONMENT` instead of
inferring the environment from the request host. Redis settings can still be
overridden as described above.

Set secrets through protected process/server environment configuration, not
the root `.env`: that file is HTTP-accessible in the current shared web-server
configuration. Restart the appropriate application processes after changing
their environment; do not reload shared services without approval.

Use only the existing legacy tables; no new credential or publisher tables are
created. Override the CI4 `Email` sender and transport outside any
HTTP-accessible directory as needed. The registration transaction requires
transactional legacy user and confirmation tables; it is unavailable while
either table is missing or uses MyISAM. If earlier versions of this migration
were deployed with separate credential or publisher tables, those records need
an explicit data migration before switching to this version.
Registration is limited to five attempts per IP per hour and requires a working
cache; configure a shared cache when running multiple application instances.
Quiz-by-email sharing also requires that mail configuration and cache, honors
unsubscribe requests, and is limited to five messages per IP per hour.

The focused regression tests use an in-memory SQLite database. With PHPUnit 11
available as an official manual distribution, run:

```sh
php8.5 /path/to/phpunit-11.phar --no-coverage \
  tests/database/HomePageTest.php tests/database/QuizModelTest.php tests/database/QuizPageTest.php \
  tests/database/PersonalityResultsTest.php tests/database/FollowActionsTest.php tests/database/AuthenticationTest.php \
  tests/database/DirectoryPageTest.php tests/database/ProfilePageTest.php \
  tests/unit/StaticPagesTest.php tests/unit/LegacyStringHelperTest.php \
  tests/unit/LegacyLibHelperTest.php tests/unit/LegacyConnectionsTest.php
```

## CodeIgniter 4 Framework

## What is CodeIgniter?

CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure.
More information can be found at the [official site](https://codeigniter.com).

This repository holds the distributable version of the framework.
It has been built from the
[development repository](https://github.com/codeigniter4/CodeIgniter4).

More information about the plans for version 4 can be found in [CodeIgniter 4](https://forum.codeigniter.com/forumdisplay.php?fid=28) on the forums.

You can read the [user guide](https://codeigniter.com/user_guide/)
corresponding to the latest version of the framework.

## Important Change with index.php

`index.php` is no longer in the root of the project! It has been moved inside the *public* folder,
for better security and separation of components.

This means that you should configure your web server to "point" to your project's *public* folder, and
not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter *public/...*, as the rest of your logic and the
framework are exposed.

**Please** read the user guide for a better explanation of how CI4 works!

## Repository Management

We use GitHub issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages.
We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss
FEATURE REQUESTS.

This repository is a "distribution" one, built by our release preparation script.
Problems with it can be raised on our forum, or as issues in the main repository.

## Contributing

We welcome contributions from the community.

Please read the [*Contributing to CodeIgniter*](https://github.com/codeigniter4/CodeIgniter4/blob/develop/CONTRIBUTING.md) section in the development repository.

## Server Requirements

PHP version 8.2 or higher is required, with the following extensions installed:

- [intl](http://php.net/manual/en/intl.requirements.php)
- [mbstring](http://php.net/manual/en/mbstring.installation.php)

> [!WARNING]
> - The end of life date for PHP 7.4 was November 28, 2022.
> - The end of life date for PHP 8.0 was November 26, 2023.
> - The end of life date for PHP 8.1 was December 31, 2025.
> - If you are still using below PHP 8.2, you should upgrade immediately.
> - The end of life date for PHP 8.2 will be December 31, 2026.

Additionally, make sure that the following extensions are enabled in your PHP:

- json (enabled by default - don't turn it off)
- [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) if you plan to use MySQL
- [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library
