PHPackages                             sifuen/module-upgradable-content - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sifuen/module-upgradable-content

AbandonedArchivedMagento2-module[Utility &amp; Helpers](/categories/utility)

sifuen/module-upgradable-content
================================

Upgrade your CMS content using UpgradeData scripts

1.0.0(6y ago)01MITPHP

Since Jul 4Pushed 6y agoCompare

[ Source](https://github.com/jsifuentes/module-upgradable-content)[ Packagist](https://packagist.org/packages/sifuen/module-upgradable-content)[ RSS](/packages/sifuen-module-upgradable-content/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Sifuen\_UpgradableContent
=========================

[](#sifuen_upgradablecontent)

This Magento 2 module allows you to upgrade your CMS blocks and pages using UpgradeData scripts.

Installation
------------

[](#installation)

You can install this module using composer

```
composer require sifuen/module-upgradable-content

```

Or you can clone this repository and place it into `app/code/Sifuen/UpgradableContent/`.

```
php bin/magento module:enable Sifuen_UpgradableContent

```

How To Use
----------

[](#how-to-use)

Your `UpgradeData` script should inject `Sifuen\UpgradableContent\Model\ContentUpgrader`. In your constructor, you should initialize the ContentUpgrader using `$this->contentUpgrader->setContentModule([your module name])`. This is used to find your CMS content files.

### Initializing

[](#initializing)

Assuming the module you create your UpgradeData file in is called `Sifuen_CmsTest`, you would invoke `setContentModule('Sifuen_CmsTest')` to tell the ContentUpgrader that this module is where you can find your CMS content files.

By default, CMS content files are read from `[your module directory]/Setup/content/[version]/[pages/blocks]/[identifier].html`. To change this, see [Advanced Initialization](#advanced-initialization)

See [Advanced Initialization](#advanced-initialization) for other ways to initialize the ContentUpgrader.

```
use Sifuen\UpgradableContent\Model\ContentUpgrader;

class UpgradeData implements UpgradeDataInterface
{
    /**
     * @var ContentUpgrader
     */
    private $contentUpgrader;

    /**
     * UpgradeData constructor.
     * @param ContentUpgrader $contentUpgrader
     */
    public function __construct(
        ContentUpgrader $contentUpgrader
    )
    {
        $this->contentUpgrader = $contentUpgrader;
        // Set the current module we are in so the content upgrader
        // can find our content files
        $this->contentUpgrader->setContentModule('Sifuen_CmsTest');
    }
```

### Upgrading Content

[](#upgrading-content)

You are given access to two main methods on the ContentUpgrader instance.

`$this->upgradeCmsPages($version, $identifiers)`

`$this->upgradeCmsBlocks($version, $identifiers)`

`$version` is the module version you are upgrading to.

`$identifiers` can be two things:

- An array of page/block identifiers
- An array of arrays, where the index of each element is the identifier of the page/block being updated/created and the value is the page/block data, minus the content.

You usually use the second version of `$identifiers` if you are **creating** CMS content, while you will use the first if you are **updating** CMS content.

#### Example

[](#example)

```
/**
 * @param ModuleDataSetupInterface $setup
 * @param ModuleContextInterface $context
 * @throws \Magento\Framework\Exception\LocalizedException
 */
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    if (version_compare($context->getVersion(), '1.0.1', 'contentUpgrader->upgradePages('1.0.2', ['examplepage-test']);
    }

    if (version_compare($context->getVersion(), '1.0.3', '
