zephir / kirby-contentsync
Kirby contentsync plugin
Package info
github.com/zephir/kirby-contentsync
Type:kirby-plugin
pkg:composer/zephir/kirby-contentsync
Requires
- php: >=8.1
- ext-curl: *
- getkirby/composer-installer: ^1.2
Requires (Dev)
- getkirby/cli: ^2.0
- getkirby/cms: ^4.0 || ^5.0 || ^6.0
Suggests
- getkirby/cli: Runs the content:sync command. Install it globally or in your project.
Provides
None
Conflicts
None
Replaces
None
README
Important
Looking for a maintainer: we're looking for someone to take over this repository. If you're interested, please open an issue.
Note
Claude (an AI assistant) was used to optimize the code of this plugin. All changes were validated by a human.
Tired of manual and cumbersome methods like git push/pull, scp, rsync, or sftp to synchronize content between your server and local development environment?
Embrace a seamless and efficient syncing solution with Contentsync.
This plugin requires Kirby 4, 5 or 6, the Kirby CLI, PHP 8.1 or higher (as far as your Kirby version supports it) and the PHP
curlextension.Kirby 3 is no longer supported: it doesn't get security updates anymore. Use version 2.x of this plugin for Kirby 3.
Table of Contents
1. Installation
The recommended way of installing is by using Composer.
1.1 Composer
composer require zephir/kirby-contentsync
1.2 Download
Download and copy this repository to /site/plugins/kirby-contentsync.
1.3 Git submodule
git submodule add https://github.com/zephir/kirby-contentsync.git site/plugins/kirby-contentsync
The plugin has no Composer dependencies, so all three ways work without running composer install for it.
1.4 Kirby CLI
The sync runs as a Kirby CLI command, so the machine you sync to needs the CLI. Install it globally or in your project:
composer global require getkirby/cli
# or
composer require getkirby/cli --dev
2. Setup
After installation, you simply have to configure the Options, deploy the updated site to the server, and use the Kirby command.
3. Options
| Option | Type | Default | Required | Description |
|---|---|---|---|---|
| source | string | null | ✅ | Source of the content, normally the staging/prod server. URL of the host (e.g. https://getkirby.com) |
| token | string | null | ✅ | The authentication token, make sure this token is not accessible by the public. Either use an env file/variable or use a private git repository. |
| enabledRoots | array | see below | ❌ | Which roots should be synchronized by the plugin. You can see all available roots here. |
| verifySSL | bool | true | ❌ | Verify the SSL certificate of the source server. Only set this to false for a source with a self-signed certificate you trust, as it exposes the token to man-in-the-middle attacks. |
3.1 enabledRoots
To support different types of folder structures we use the kirby()->roots() function (hence the name of the option).
The plugin supports synchronizing all Kirby root paths.
By default, the plugin is configured to sync the accounts and content roots.
[
'accounts' => true,
'content' => true
]
3.2 Example config entry
'zephir.contentsync' => [ 'source' => 'https://getkirby.com', 'token' => 'abc123', 'enabledRoots' => [ 'license' => true // also sync license ] ]
4. Usage
Kirby CLI Command:
kirby content:sync
With verbose logging:
kirby content:sync -v
In non-interactive mode (accepts changes automatically):
kirby content:sync -n
5. How does it work?
The plugin creates 2 endpoints (routes):
/contentsync/files: Returns a list of all files in the enabled roots./contentsync/file/:fileId: Returns the contents of the requested file.
If you don't set up a token the endpoints won't work. Requests must send it as
Authorization: Bearer <token>.
Each file returned by files has an ID (sha1 hash of root name + path), a path (relative to Kirby root), a Kirby root name, and a checksum of the file contents.
The plugin compares the retrieved file list with a file list of local files. It automatically deletes local files that aren't in the server list, creates the ones that aren't local but in the server list, and updates the ones with different checksums.
It doesn't sync files that haven't changed. Each file is downloaded to a temporary file first, so a failed download leaves the local file untouched. File paths from the server that would point outside a Kirby root are refused.
6. Caveats
- Since we download each file individually, it is possible that a WAF / Firewall will block the requests. You can add an exception for the endpoints.
- Generating the checksum can put a bit of load on the server, especially for large files. But for "normal" websites it should be fine - even if you have several gigabytes of data / many files.
- Because we serve all files through PHP and a web endpoint, downloads of large files (200MB+) may be stopped by the server hoster (especially with shared hosting).
License
MIT
