How to move all Pages and DataObjects from Main Site to a Subsite

In case you want to move "Everything (tm)" from Main Site to a Subsite, there is no ready-to-use task available.

But with some SQL queries and a little bit of manual work you can of course move stuff to another subsite. That thing called "Main Site" is just another Subsite without a Subsite DataObject and the ID 0.

Knowing this we can move all Objects from Subsite 0 to Subsite 3 (if that's the ID we want to move content to...).

But... How do we get all tables that have a SubsiteID column? Why not ask your sql, MySQL in this case?

USE information_schema;
SELECT table_schema, table_name, column_name 
    FROM columns 
    WHERE table_schema = 'MYDATABASENAME' AND
          column_name = 'SubsiteID';

As we have all tables with a SubsiteID column, we can make some queries to update the tables and move all items with SubsiteID=0 to the new subsite:

UPDATE `File` SET `SubsiteID`=3 WHERE `SubsiteID`=0;
UPDATE `Group_Subsites` SET `SubsiteID`=3 WHERE `SubsiteID`=0;
UPDATE `SiteConfig` SET `SubsiteID`=3 WHERE `SubsiteID`=0;
UPDATE `SiteTree` SET `SubsiteID`=3 WHERE `SubsiteID`=0;
UPDATE `SiteTree_Live` SET `SubsiteID`=3 WHERE `SubsiteID`=0;
UPDATE `SiteTree_versions` SET `SubsiteID`=3 WHERE `SubsiteID`=0;
UPDATE `SubsiteDomain` SET `SubsiteID`=3 WHERE `SubsiteID`=0;

just be sure you update every relevant table in your setup.

Rate this post (2 rating(s))

Post your comment

Comments

  • Werner Krauss 06/04/2016 8:14am (8 years ago)

    This worked great. Thanks for sharing your knowledge, James!

RSS feed for comments on this page | RSS feed for all comments