Search by

sutunam / module-cms-data-sync

sutunam

This extension will allow to sync CMS pages or blocks from one website to other.

Package info

github.com/sutunam/module-cms-data-sync

Type:magento2-module

pkg:composer/sutunam/module-cms-data-sync

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.0 2026-01-23 07:46 UTC

This package is auto-updated.

Last update: 2026-11-27 08:46:36 UTC


README

This extension streamlines the process of copying CMS contents between two enviroments. It works seamlessly with any number of configurations, media files, styles, or blocks, reducing the need for manual work.

Features

- Bi-directional CMS synchronization (push & pull)

- Supports CMS blocks, pages, and widgets

- Batch and single-entity synchronization

- REST API–driven, environment-agnostic architecture

Installation

Requires Magento Open Source / Adobe Commerce 2.4.x and PHP 8.1 or later. Install the same version on both hosts: widget sync needs version 1.2.0 or later on both of them (an older host that pushes a widget to a widget instance of "All Store Views" creates a second instance).

Composer

Require the package:

composer require sutunam/module-cms-data-sync

Then, execute the following Magento commands:

bin/magento module:enable Sutunam_CmsDataSync
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:flush

Configurations:

Go to Stores > Configuration > Sutunam > Cms Data Sync Go to Stores > Configuration > Sutunam > Cms Data Sync

Descriptions of configurations:

  • Enable – Turn the extension on or off.

  • Website Name – Name of the remote site you want to copy content from.

  • Website URL – The web address of the remote site, used to connect to its API.

  • Username – Admin login name for the remote site. Its role on the remote site needs these resources: "Stores > Settings > Configuration" (Magento_Config::config, read by /V1/sync/configs before every push), "Stores > Settings > All Stores" (Magento_Backend::store, store views), "Content > Elements > Pages / Blocks / Widgets" (Magento_Cms::page, Magento_Cms::block, Magento_Cms::save, Magento_Widget::widget_instance), and "CMS Data Sync" (Sutunam_CmsDataSync::cms_data_sync) to push content with a <script> tag. Without the configuration resource every push fails with "Fail to retrieve configuration from remote host ...: Error: 401 ...".

  • Password – Admin password for the remote site.

  • Sync Media – Turn this on if you also want to copy images and other media files.

  • Root Directory / Subdirectory – The folder location on the remote site where its media files are stored (used only if Sync Media is on).

  • Overwrite Content (recommended: keep off) – If on, it will replace existing content on your site with the remote site’s content.

  • Maximum Items per Bulk Operation (default 30) – The Mass Action and "Push All" are queued as a bulk action of operations of this number of items at most. Lower it if one operation takes too long (large pages, media); raise it to have fewer operations. A retry syncs the failed items of an operation again.

  • Skip Unchanged Items (default Yes) – "Pull All", "Push All" and the Mass Action do not sync the pages, blocks and widgets that have the same content on both hosts; they are counted as skipped (Skip - Unchanged) and their media files are not synced again. The Sync button of the edit screen always syncs its item. See "Skip unchanged items" below.

  • Debug Log – If on, the API request and response bodies are written to var/log/cms-sync.log (passwords and tokens are never logged). Keep it off outside debugging: each request is already logged on one line with its status and duration, a failed request with the first 1000 characters of the response, and each failed item with its reason (Sync failed: ...).

  • Sync History Versions per Item (default 3) – Number of versions kept per page, block or widget in the sync history (see below). 0 disables the history.

Usage:

Note:

You can sync CMS data using any of the three available options:

  • Primary “Sync All” button in the UI listing.

  • Mass Action option in the CMS listing view.

  • Sync button on the CMS block/page edit screen.

The CMS block or page is matched and synced based on its Identifier and Store Views. Simply click the desired sync option, and the CMS data will be transferred automatically.

Store views matching:

  • An item is synced with the remote items of the same Identifier that share at least one of its store views. "All Store Views" only matches "All Store Views".
  • When the remote host has no item for these store views but has one for "All Store Views", that item is used: only its content is synced, each item keeps its own store views. It is matched by its Identifier: a push updates it also when other local items of this Identifier exist (one page per store view, for example), so with "Push All" the remote item gets the content of the last of them.
  • An item of "All Store Views" covers every store view: when the remote host has no item of "All Store Views", its item of a store view is used. With "Overwrite Existing Data", the pulled item then gets the store views of the remote item, unless another local item already uses them.
  • When the remote host splits an item by store view (one page per store view, for example), "Pull All" updates each local item from the remote item it matches. The Sync button of one item pulls only when one remote item has exactly the same store views; otherwise use "Pull All".
  • "Pull All" with remote items of store views and a local item of "All Store Views" (no local item of these store views): the local item gets the content of the first remote item and keeps "All Store Views", so it stays in the local store views that the remote host does not have. No item is created next to it. Without "Overwrite Existing Data" the local item is skipped.
  • "Pull All" with a remote item of "All Store Views", when the local items of this Identifier are all of store views: the local items that have no remote item of their own store views get its content and keep their store views, as with the Sync button. No local item of "All Store Views" is created: a new item gets the store views of the remote host that have no local item of this Identifier. A local item of store views that the remote host does not have is skipped.
  • A "CMS Static Block" widget instance points to the block of the same Identifier and store views on the other host (else its block of "All Store Views"): sync the blocks before the widgets.

Content with a <script> tag (a review widget, for example): the Magento Web API refuses it, so the content of pages and blocks and the parameters of widgets are encoded during the push. Both hosts need this module version or newer to push it; pulling it works with any version. A script tag in another field (title, meta data...) cannot be pushed. The remote admin user set in the configuration needs the "CMS Data Sync" permission (Sutunam_CmsDataSync::cms_data_sync) on the remote host to push such content: the remote host decodes it only for that permission, and logs every decoded value in var/log/cms-sync.log.

Sync history (restore a version)

Before a pull, or a push received from the remote host, changes a page, block or widget instance, its current version is kept in the sync history (table sutunam_cms_sync_history). Only the pull and push of this module are tracked: a save in the admin form is not.

  • A version is kept only when the sync really changes the item: pulling the same content again keeps the older versions. A new item (created by the sync) has no version. A run (Pull All, Mass Action) keeps one version per item at most: the one before the run, also when several remote items update the same item.
  • Pull: the version is kept on this host. Push: the version is kept on the remote host, which needs this module version or newer.
  • The edit screen of an item with versions shows a "Sync History (n)" button. It opens the list of the versions, loaded when it opens: date, origin (pull from the remote host, push received from the remote host, restore), admin user, title, store views and content. A received push names the host that sent it (its name in the settings when it is the configured remote host) and the admin user who pushed, followed by the API user of the request, e.g. john (API: sync-user). A sender of an older version, or an API user without the "CMS Data Sync" permission, is shown as the API user only.
  • "Restore" puts the version back (content, title, status, store views and the other fields; the page groups of a widget). The current version is kept in the history first, in the same transaction, so a restore can be undone: when it cannot be kept (history disabled, database error), the item is not changed. Store views deleted since the version are left out; a version none of whose store views still exists cannot be restored.
  • Only "Sync History Versions per Item" versions are kept per item (default 3): the oldest are deleted. Lowering the number deletes the extra versions at once; 0 disables the history, deletes every version and hides the button.
  • The versions of a deleted page, block or widget instance are deleted.
  • Restoring needs the "CMS Data Sync" ACL resource and the right to save the item (block, page or widget), and "Edit Page Design" when the version changes the design of a page (layout, theme, layout update).

Warning "Temporarily allowed to save HTML value that contains restricted elements"

The Sync button of the edit screen and "Restore" save the item as the admin form does, so Magento checks its content against its HTML allowlist (Magento\Cms\Model\Wysiwyg\Validator). Content with elements outside that list (a <script> tag, an <img> whose src is a {{media url=...}} directive...) is saved with this Magento warning, the same as when the admin saves this content in the form. It does not come from the sync and the item is saved. When the restriction is enforced (bin/magento cms:wysiwyg:restrict y, config cms/wysiwyg/force_valid), Magento refuses such content instead, and the sync reports the item as failed with the reason.

Background processing (Sync All and Mass Action)

"Sync All" and the Mass Action do not run in the admin request: they are queued and processed in the background by the sutunam.cms_data_sync message queue consumer (MySQL queue), so a large sync no longer ends with a gateway timeout (504). The Sync button of the edit screen still runs immediately.

  • Each request is a bulk action, shown in System > Action Logs > Bulk Actions with the result of each operation (created, updated, skipped, failed items and the errors). Details are in var/log/cms-sync.log.
  • The Mass Action and "Push All" are split into operations of at most "Maximum Items per Bulk Operation" items (default 30); "Pull All" is one operation.
  • A failed operation can be retried from the bulk action details: an operation with failed items keeps only them, so the retry syncs only them. An operation that could not run (remote host unreachable, another sync of the same CMS type running) is retried as a whole. Only the admin who started a bulk action sees it.
  • The items already queued or running are not queued again: the same "Sync All" is refused, and a Mass Action selection is queued without them. An operation still open after 3 hours (its consumer was stopped) no longer blocks a new request. Only one sync per CMS type (pages, blocks, widgets) runs at a time.
  • The consumer must be running. By default Magento's cron starts all consumers (cron_consumers_runner in app/etc/env.php). If cron_run is false, or if consumers lists only some consumers, add sutunam.cms_data_sync or start it yourself:
bin/magento queue:consumers:start sutunam.cms_data_sync
  • After a deploy, restart the running consumers so they load the new code: bin/magento queue:consumers:restart. Saving the CMS Data Sync settings in the admin restarts them, so the queued syncs use the new settings; after bin/magento config:set or a deploy of app/etc/config.php/env.php, restart them yourself.

  • Requires the core modules Magento_MysqlMq (queue on the database) and Magento_AsynchronousOperations (bulk actions).

Skip unchanged items

With "Skip Unchanged Items" on, "Pull All", "Push All" and the Mass Action compare each item with the remote item of the same identifier before syncing it, and skip it when both have the same content hash.

  • The hash is computed at sync time from the synced fields only, so that the same content gives the same hash on both hosts: the base URL of each host, store view IDs (compared by code) and CMS block IDs (compared by identifier and store views, in Page Builder blocks and CMS Static Block widgets) do not count. Nothing is stored, so a database import needs no extra step.
  • The remote host returns its hashes in its list APIs (sync_hash). A remote host of an older version returns none: every item is synced, as before. An item whose hash cannot be computed is always synced too.
  • Items whose store views differ between the hosts are never skipped, they are synced as before: store views that only one host has, a remote "All Store Views" item matched to items per store view, and CMS blocks that are referenced with different store views on the two hosts.
  • An item is skipped only when every remote item that its sync would change has its content: a remote item of the same identifier whose store views overlap with other content (widget instances can overlap) makes it synced.
  • In one operation, an item is synced again after another item of the same identifier was synced, since that push may have changed their shared remote item of "All Store Views".
  • An identifier with a comma is not compared (logged in var/log/cms-sync.log): its item is always synced.
  • A skipped item gets no sync history version and its media files are not synced again: use the Sync button of the edit screen to sync one item anyway (for example to download a media file again).

Some common cases:

  1. “Sync Media” Setting
  • On – Media files are synced along with CMS content.

  • Off – Media files are skipped during syncing.

  1. “Overwrite Content” Setting

Enabled

  • All CMS blocks/pages are replaced with the remote host’s content.

  • Media files are not replaced: a file that this site already has is kept and not downloaded again. To sync an image changed on the other site, give it a new name. Each file is downloaded once per sync run, with a 30-second timeout.

  • Two scenarios:

  • Block/Page exists → Content is updated with the remote host’s version.

  • Block/Page does not exist → A new block/page is created using the remote host’s data.

Disabled

  • Existing CMS blocks/pages on the target site are skipped by "Pull All", "Push All" and the Mass Action ("Skip - Overwrite disabled"). The setting of the site that receives the data counts: this site for a pull, the remote host for a push.

  • The Sync button of the edit screen is an explicit request for this one item: its pull still updates the item. Only the store views of the item then do not change.

  • Any CMS block/page that does not exist on the target site is created using the remote host’s data.

Screenshot:

  1. In listing page:

  2. In each page:

Note: The cms page management is the same as the block ui listing page

Layouts

This module introduces the following layouts and layout handles in the src/view/adminhtml/layout directory:

  • adminhtml_widget_instance_block
  • adminhtml_widget_instance_edit
  • adminhtml_widget_instance_index

Tests

The module code is in src/. Run the unit tests (src/Test/Unit) from the Magento root with the Magento unit test configuration:

vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist vendor/sutunam/module-cms-data-sync/src/Test/Unit

Development by Sutunam

We are an Open Source Software Development Company, specialized in Magento 2 and Hyva Silver Partner

Contact us