Fast Deletion of 100 000's document Site

Anonymized User asked on February 8, 2017 12:47

Hey guys,

I have an upcomming K7 database split to do in 2 months and I was wondering if there was a faster way to delete a site than just clicking on the red X.

You have to know that the web site is actually 100 000's document.

I know, nobody needs to tell me that it's way beyond K7 document count recommendation, but for now I have to deal with ;)

So?

thanks

Recent Answers


Trevor Fayas answered on February 8, 2017 15:35 (last edited on February 8, 2017 15:36)

Two ways.

  1. Use the List View, with it you can select certain page types, and show all levels. If you can get a list of all the items you want to delete, you can just show all, check all, and delete. That being said, 100,000 may be hard for the UI to load and processes.

  2. Make a temporary .aspx page (in like /CMSPages/Custom) and put a ASP Button, set the onclick, and use Kentico's API to select your documents and foreach() through them, and delete them. I use the API when i need to do large tasks like that.

I would probably go with option #2. Sadly i have a hard time viewing the API for Kentico 7, and don't have an instance currently installed to reference, but should be something under CMS.DocumentEngine and one of the Tree Providers, Document Providers, Tree Helpers, or Document Helpers.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 8, 2017 16:03

I'd agree with Trevor's responses although I'd be careful about just deleting the documents with just the API. Sometimes there are other pieces which happen within the UI when you click a button that are needed. With documents there about a million other references to other items so using the API can be a big risk, especially in a v7 instance where there are a considerable number of bugs with the API and documents/pages in general.

I'd go for option 1 and showing the list and deleting the pages. Yes it will take time and not the quickest but will get the job done properly. Then after those are removed, you could then simply click the delete site button.

0 votesVote for this answer Mark as a Correct answer

Bill Tran answered on February 8, 2017 16:04

Using the application to delete the records may take forever. If you can use SQL queries to delete the records that'll be much faster.

If you need to delete a site because you have two sites, maybe you can export the smaller site into a new instance of Kentico and create a new database for it, then just delete the data file.

If you have to delete the records from the database, go with SQL query. Write a cursor or loop to select X number of records and delete them.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on February 8, 2017 16:52

I would caution Bill's advice. You never want to delete or modify using SQL commands unless it's a Custom Table (even then i would caution). Reason is, expecially with pages, there are often many additional tables that go along with items. If versionining is turned on there is version control, if staging is enabled then any changes made through SQL will not be tracked so you can't push to another environment.

The API handles those things. However as Brenden pointed out, v7 API was a bit buggy at times.

1 votesVote for this answer Mark as a Correct answer

Anonymized User answered on February 12, 2017 15:32

Ok thanks guys,

I'll keep you posted during the week on which solution ill use.

0 votesVote for this answer Mark as a Correct answer

Anonymized User answered on February 16, 2017 14:25

OK here is the solution that I am actually testing.

  • Selecting all tables from sys.tables that have fields ending by SiteID
  • Deleting from these tables record that match my Site ID
  • Some delete will fail due to FK constrains
    • Deleting from these child tables the records relative from my Site ID
  • Deleting the Site from the CMS Site Manager interface
  • Deleting media folder manually if needed
  • And finally, upgrading Kentico from 7 to 9 with the standard procedure.

Actually, it seems to work fine but I'll keep you posted on any issue.

Thank you for your input guys!

0 votesVote for this answer Mark as a Correct answer

Digital Team answered on February 17, 2017 12:07

Hi I'm having exactly the same issue as you.

What i'm doing right now is taking a backup of the database, enable debug mode in web.config (to avoid timeout exc) and running this code on an aspx file:

CMS.DocumentEngine.TreeProvider tree = new CMS.DocumentEngine.TreeProvider(CMS.CMSHelper.CMSContext.CurrentUser);

    DataSet documents = tree.SelectNodes(CMS.CMSHelper.CMSContext.CurrentSiteName, "/%", "en-us", true, "CWB.NewsComment", "DocumentName like '%2rand%'", null,-1,false);


    foreach (DataRow doc in documents.Tables[0].Rows)
    {
        CMS.DocumentEngine.TreeNode tn = tree.SelectSingleNode(Convert.ToInt32(doc["DocumentNodeID"]), "en-us");
        tn.Delete();           
    }

This is slow as hell, but well, i'm guessing there is no other alternative.

I would be helpful to have some sort of procedure in the database to make such kind of things.

0 votesVote for this answer Mark as a Correct answer

Pablo Alejo answered on March 3, 2017 17:51

I think this should work too and saves you an extra query.

var docs = DocumentHelper.GetDocuments("CWB.NewsComment").WhereLike("DocumentName", "%2rand%");

foreach (var doc in docs)
{
    doc.Delete();
}
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.