# Updates, data feeds and releases

Rules and reasons: `_docs/DISTRIBUTION.md` (sections 3–5).

## The update check

`syncshop:check-updates` (daily, in the scheduler) asks `GET {server}/api/v1/updates?installed=<version>` with the
licence key as a bearer token, and stores the answer in `UpdateSettings` (Settings → Updates). The answer the package
server sends:

```json
{"latest": "1.5.0", "allowed": "1.4.2", "entitlement_ends_at": "2027-11-24", "security": false, "changelog_url": "https://syncshop.ro/lansari"}
```

`{server}` is `https://repo.syncshop.ro` (`config('syncshop.updates.server')` overrides it). 401/403 is recorded as
*refused*; the shop keeps working whatever the answer.

## syncshop:update

`php artisan syncshop:update [--yes] [--force] [--maintenance]`, on the server:

1. `syncshop:check` (stops on a blocking problem), then the update check.
2. `composer update "syncshop/*" -W --dry-run`: an extension whose `syncshop/core` constraint refuses the new version
   stops it here, before anything changes.
3. Backup into `storage/app/syncshop-update/<time>/` (folders 0700, files 0600: it holds `.env` and the whole
   database): `composer.json`, `composer.lock`, `.env` and a `pg_dump`. After a successful update only the newest three
   backups are kept.
4. Maintenance mode with `--maintenance`.
5. `composer update "syncshop/*" -W` (with `--no-dev` in production), then, each as a new process on the new code:
   `migrate --force`, `permissions:sync`, `syncshop:assets`, `optimize:clear` (and `optimize` in production),
   `queue:restart`, `horizon:terminate`.
6. Smoke test: the home page and the admin sign-in answer without a server error.

Any failure after the backup restores `composer.json` and `composer.lock`, runs `composer install`, restores the
database with `pg_restore --clean`, and leaves maintenance mode. The licence key reaches Composer only as
`COMPOSER_AUTH` for that process (username the key, password the shop's domain); it is never written to disk.

`syncshop:assets` copies the compiled assets shipped in `syncshop/core` (`dist/build`) to `public/build`; in this
repository, where Vite builds them, it does nothing. A shop's own theme builds into a directory of its own.

## Data feeds

`syncshop:feeds:sync` (hourly) fetches `GET {server}/feeds/<name>.json` with the licence key and applies a newer
version. The server answers:

```json
{"payload": "<base64 of the JSON below>", "signature": "<base64 Ed25519 signature of the payload string>"}
```

```json
{"feed": "vat-rates", "version": 3, "published_at": "2026-12-01T09:00:00+02:00", "data": {"rates": [{"class": "standard", "percent": "21.00", "valid_from": "2025-08-01"}]}}
```

- The signature is checked against `FeedVerifier::RELEASE_KEYS` (base64 public keys, newest first). The key pair was
  generated on the package server (repo.syncshop.ro), whose admin signs and publishes each feed version; its secret
  never leaves that server. Without a key (`syncshop.feeds.public_keys` emptied) the feeds are not followed
  (*not configured*).
- 401, 402 or 403 means the Updates & Compliance subscription has lapsed: the feed is marked *lapsed*, the Updates
  page and the dashboard warn, and the values are edited by hand (Settings → VAT rates, Settings → SGR deposit).
- A module owns its feed: a class implementing `Platform\Contracts\DataFeed`, added with `DataFeeds::add()` in its
  provider. `apply()` runs in a transaction; every applied version is recorded in `data_feed_versions` with what it
  changed. Dated values are added; one already in force is never rewritten (counted as a conflict).

| Feed | Module | `data` |
| --- | --- | --- |
| `vat-rates` | Pricing | `{"rates": [{"class": "<vat class key>", "percent": "21.00", "valid_from": "Y-m-d"}]}` |
| `sgr` | Cart | `{"values": [{"valid_from": "Y-m-d", "unit_amount": 50}]}` (bani per container) |

## Releasing

`composer release -- 1.4.2 [--skip-check]` runs the checklist up to the zips:

1. A clean working tree, a `## [1.4.2]` section in `CHANGELOG.md`, and `UPGRADE.md`.
2. `composer check`, which includes the extension API tests on the sample extension.
3. The upgrade test: database snapshots of the two previous minors in `build/snapshots/*.dump`, each migrated and
   tested (none before the first release).
4. `npm run build`, the compiled assets into `packages/core/dist/build`, then one zip per package (`syncshop-core`,
   `syncshop-theme-default`, `syncshop-skeleton`) with its version in `composer.json`, and `SHA256SUMS`, in
   `build/release/<version>/`.

Tagging, uploading the zips to the package server and publishing the changelog are done by hand.

## Updating from the admin

Settings → Updates has **Actualizează acum** for the shop's owner (password plus a fresh authenticator code; Fortify
takes each code once). `UpdateLauncher` starts `php artisan syncshop:update --yes --report` detached from the request
(`nohup … &`; under PHP-FPM the PHP command line is found with Symfony's `PhpExecutableFinder`, or set
`PHP_CLI_BINARY`). Not on the queue: a worker's timeout would cut it short, and the update restarts Horizon itself.
With `--report` the command records its state and every step in `storage/app/syncshop-update/run.json`
(`UpdateRun`), which the page shows and reloads every 5 seconds while it runs; a run unfinished after 3 hours counts as
dead. The PHP-FPM user must own the project files (it does on Hestia, where PHP-FPM runs as the site's user).

