PagesVersions::restorePageVersion() method

Restore a page version to be the live version

Note that the restored page is saved to the database, replacing the current live version. So consider whether you should backup the live version (by using addPageVersion) before restoring a version to it.

Example

// restore version 2 to live page
$page = $pages->get(1234);
$pagesVersions->restore($page, 2); // restore version 2

// this does the same as the above
$pageV2 = $pagesVersions->getPageVersion($page, 2);
$pagesVersions->restore($pageV2);

Usage

// basic usage
$page = $pagesVersions->restorePageVersion(Page $page);

// usage with all arguments
$page = $pagesVersions->restorePageVersion(Page $page, int $version = 0, array $options = []);

Arguments

NameType(s)Description
pagePage

Page to restore version to or a page that was loaded as a version.

version (optional)int

Version number to restore. Can be omitted if given $page is already a version.

options (optional)array
  • names (array): Names of fields/properties to restore or omit for all (default=[])
  • useTempVersion (bool): Create a temporary version and restore from that? (default=auto-detect). This is necessary for some Fieldtypes like nested repeaters. Use of it is auto-detected so it is not necessary to specify this when using the public API.

Return value

Page bool

Returns restored version page on success or false on fail

Exceptions

Method can throw exceptions on error:

  • WireException


$pagesVersions methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #549
    In the 549th issue of ProcessWire Weekly we’re going to check out the latest core updates, highlight one older yet still very relevant third party module, and more. Read on!
    Weekly.pw / 17 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“Yesterday I sent the client a short documentation for their ProcessWire-powered website. Today all features already used with no questions. #cmsdoneright—Marc Hinse, Web designer/developer