Jump to:

23451 Posts in 18899 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Restore Unpublished and Deleted Pages

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 3366 Views
  • wakes
    Avatar
    Community Member
    7 Posts

    Restore Unpublished and Deleted Pages Link to this post

    Hi, just a quick tip on how to restore an unpublished/deleted Page which no longer shows in the SiteTree:

    In your DB client of choice (e.g. phpMyAdmin) locate the previous to last version of the page in the SiteTree_versions table (e.g. by Title, ClassName, URLSegment etc) and note down the ID of that record. It will probably have a status of 'Published' or 'Saved' (not the last record for that page which will probably have a status of 'Unpublished'). e.g.

    select * from SiteTree_versions where Title = '<page title>' and ClassName = '<page class>' order by ID desc limit 1, 1;

    Execute the following in the SQL client, providing the ID of the record above:

    insert into SiteTree (ID, Version, ClassName, Created, LastEdited, URLSegment, Title, Content, MetaTitle, ShowInMenus, ShowInSearch, Sort, Status, Priority, Viewers, Editors, ViewersGroup, EditorsGroup, ParentID)
    select RecordID, Version, ClassName, now(), now(), URLSegment, Title, Content, MetaTitle, ShowInMenus, ShowInSearch, Sort, Status, Priority, Viewers, Editors, ViewersGroup, EditorsGroup, ParentID
    from SiteTree_versions where ID = <id of the record>;

    This will restore the page (and all children!) to the SiteTree in the CMS, from where you can then re-publish it.

  • Taffy
    Avatar
    Community Member
    119 Posts

    Re: Restore Unpublished and Deleted Pages Link to this post

    Nice one. It would be good if you put it on Aram's http://ssbits.com/ site

  • PapaBear
    Avatar
    Community Member
    26 Posts

    Re: Restore Unpublished and Deleted Pages Link to this post

    I have just had the panicked call from a client who had discovered their staff member had made some huge changes to important pages and then accidentally erased the entire sub-tree (half a dozen pages or so). Using this technique I was able to roll back to the previous delivered version of the pages without damaging the rest of the site and have their site restored in under an hour. Very happy client. Very happy web-developer.

    Thank you!

    James.

  • Catchgraphics
    Avatar
    Community Member
    12 Posts

    Re: Restore Unpublished and Deleted Pages Link to this post

    Hi I followed the instructions but I get the following error:

    Error

    SQL query: Documentation

    INSERT INTO SiteTree( ID, Version, ClassName, Created, LastEdited, URLSegment, Title, Content, MetaTitle, ShowInMenus, ShowInSearch, Sort,
    STATUS , Priority, Viewers, Editors, ViewersGroup, EditorsGroup, ParentID )
    SELECT RecordID, Version, ClassName, now( ) , now( ) , URLSegment, Title, Content, MetaTitle, ShowInMenus, ShowInSearch, Sort,
    STATUS , Priority, Viewers, Editors, ViewersGroup, EditorsGroup, ParentID
    FROM SiteTree_versions
    WHERE ID =3

    MySQL said: Documentation
    #1054 - Unknown column 'Priority' in 'field list'

    There seems to be a problem with the " now(), now()," part. As I don't really know any sql I am not sure if I have done anything wrong. Help would be much appreciated.

    Many thanks

    Michael

  • wakes
    Avatar
    Community Member
    7 Posts

    Re: Restore Unpublished and Deleted Pages Link to this post

    The actual column names may vary some due to different versions/modules etc installed. If you do a 'show columns from SiteTree_versions;' in mysql administrator tool (e.g. phpmyadmin, command line) then it will give you a list of columns which you'll need to use for your particular setup.

    If you have problems please post the output of the 'show columns from SiteTree_versions;' command and I'll have a look.

  • Borgopio
    Avatar
    Community Member
    14 Posts

    Re: Restore Unpublished and Deleted Pages Link to this post

    Wow! It works for me, with column name changed, here's my SQL:

    INSERT INTO SiteTree (ID,Version,ClassName,Created,LastEdited,URLSegment,Title,Content,MetaTitle,ShowInMenus,ShowInSearch,Sort,Status,Priority,CanViewType ,CanEditType ,ParentID,MetaDescription ,MetaKeywords ,ExtraMeta ,HomepageForDomain ,ProvideComments ,HasBrokenFile ,HasBrokenLink ,ReportClass ,ToDo ,Locale)
    SELECT RecordID,Version,ClassName,now(),now(),URLSegment,Title,Content,MetaTitle,ShowInMenus,ShowInSearch,Sort,Status,Priority,CanViewType ,CanEditType ,ParentID,MetaDescription ,MetaKeywords ,ExtraMeta ,HomepageForDomain ,ProvideComments ,HasBrokenFile ,HasBrokenLink ,ReportClass ,ToDo ,Locale
    FROM SiteTree_versions where ID = <ID to restore from SiteTree_versions>

  • mcs
    Avatar
    Community Member
    1 Post

    Re: Restore Unpublished and Deleted Pages Link to this post

    Your post was a great help. As I had to undelete hundreds of pages I had to write a stored procedure. As I had added an own ArticlePage they had to be undeleted as well. Here is what I did:

    DELIMITER $$
    DROP PROCEDURE IF EXISTS UnDelete$$
    CREATE PROCEDURE UnDelete()
    BEGIN
    DECLARE x int(11);
    DECLARE rID int(11);
    DECLARE nID int(11);
    SET x = 23027;
    WHILE x >= 1132 DO
    SET rID = (SELECT RecordID from SiteTree_versions WHERE ID = x AND ClassName LIKE 'ArticlePage' AND Title NOT LIKE 'NeuArticlePage');
    SET nID = (select ID from SiteTree WHERE ID = rID);
    IF nID IS NULL AND rID IS NOT NULL THEN
    SELECT x, rID, nID;
    INSERT INTO SiteTree (ID, Version, ClassName, Created, LastEdited, URLSegment, Title, Content, MenuTitle, MetaTitle, ShowInMenus, ShowInSearch, Sort, Status, Priority, ParentID, ToDo, CanEditType, CanViewType, ReportClass, HasBrokenLink, HasBrokenFile, LegacyURL, ProvideComments, HomepageForDomain, ExtraMeta, MetaKeywords, MetaDescription) select RecordID, Version, ClassName, Created, LastEdited, URLSegment, Title, Content, MenuTitle, MetaTitle, ShowInMenus, ShowInSearch, Sort, Status, Priority, ParentID, ToDo, CanEditType, CanViewType, ReportClass, HasBrokenLink, HasBrokenFile, LegacyURL, ProvideComments, HomepageForDomain, ExtraMeta, MetaKeywords, MetaDescription from SiteTree_versions where ID = x;
    END IF;
    SET x = x - 1;
    END WHILE;
    SET x = 23027;
    WHILE x >= 1132 DO
    SET rID = (SELECT RecordID from ArticlePage_versions WHERE ID = x);
    SET nID = (select ID from ArticlePage WHERE ID = rID);
    IF nID IS NULL AND rID IS NOT NULL THEN
    SELECT x, rID, nID;
    INSERT INTO ArticlePage (ID, Date, Author, Teaser, Tag) select RecordID, Date, Author, Teaser, Tag from ArticlePage_versions where ID = x;
    END IF;
    SET x = x - 1;
    END WHILE;
    END$$
    DELIMITER ;
    CALL UnDelete();

    3366 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.