Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

Restore Unpublished and Deleted Pages


Reply


7 Posts   3592 Views

Avatar
wakes

Community Member, 7 Posts

13 May 2009 at 12:55pm

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.

Avatar
Taffy

Community Member, 119 Posts

13 May 2009 at 9:13pm

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

Avatar
PapaBear

Community Member, 26 Posts

5 May 2010 at 4:13pm

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.

Avatar
Catchgraphics

Community Member, 12 Posts

14 August 2010 at 9:47pm

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

Avatar
wakes

Community Member, 7 Posts

14 August 2010 at 9:55pm

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.

Avatar
Borgopio

Community Member, 14 Posts

11 May 2012 at 1:22am

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>

Avatar
mcs

Community Member, 1 Post

11 March 2013 at 10:32am

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();