Page Fails to Delete, How to do this programmatically?

Vote:
 

Hello,

We have a page that is built automatically through the use of additional partials as children. This page has become extremely large, as the proces to clean up the page failed quietly some time ago. Now, when you try to delete the page through the UI, this fails to work; the activity icon flickers, but the action never completes, and the page does not go to the trash. 

We need a way to delete this page directly from the database. Most scripts I have found for this date back to the Elektron days of the site. We are still locally hosted, not using the cloud hosting, the episerver version is 11.

I need to be able to delete the page and clean up any stuck status partials in the cache. I'm an experienced SQL developer, but identifying the various elements of the page in the DB has proven difficult. I know the Page ID, the Language ID, and other identifiers, I just need a complete script, or another suggestion as to how to get rid of this page.

#301183
Edited, May 04, 2023 20:02
Vote:
 

The IContentRepository has a method on it for deleting by reference

    /// <summary>
    /// Deletes a content from the repository first ensuring that the current user meets the minimal access right requirements.
    /// </summary>
    /// <param name="contentLink">The content link.</param>
    /// <param name="forceDelete">If set to <c>true</c>, deletes the content even if it is being referenced by other content.</param>
    /// <param name="access">The required access level that the current user must have to be allowed to delete the content.</param>
    void Delete(ContentReference contentLink, bool forceDelete, AccessLevel access);

So just pass in the ContentReference and force delete true with access level of NoAccess and that should do the job. If you have problems consider looping through any children/depedants and delete first

So based on the IContentRepository being injected in the constructor and assiged to a class variable of _contentRepository

 _contentRepository.Delete(reference, true, AccessLevel.NoAccess);
#301226
Edited, May 05, 2023 8:34
Manoj Kumawat - May 10, 2023 11:22
Why not moving it to wastebasket? It is little safe than hard delete.
Vote:
 

When you try to delete the page (and of course failed), is there anything error logged in the log?

#301311
May 06, 2023 23:56
Vote:
 

Before proceeding to delete the page directly from the database, please note that it is generally not recommended to modify the database directly as it may lead to unexpected results and inconsistencies in the system. It is always advisable to have a backup of the database before performing any database operations.

With that said, here's a possible approach to deleting the page directly from the database:

Step#1

First, identify the Page ID of the page you want to delete. You can find this in the "tblPage" table in the database.

Step#2:

Check if there are any dependencies on the page. In Episerver, a page can have child pages, properties, or blocks that are linked to it. If you try to delete a page with dependencies, it will not allow you to do so. To check for dependencies, you can run the following SQL query:

SELECT COUNT(*) FROM tblProperty WHERE [fkPageID] = <page id>

If the count is greater than 0, it means that there are dependencies on the page. You need to delete these dependencies before proceeding.

Step#3:

If there are no dependencies, you can delete the page from the "tblPage" table by running the following SQL query:

DELETE FROM tblPage WHERE [PageID] = <page id>

Step#4:

Next, you need to clear the cache to ensure that the deleted page is no longer cached. You can do this by running the following SQL queries:

DELETE FROM tblCacheManager WHERE [ObjectId] = <page id>

DELETE FROM tblCacheDependency WHERE [ObjectId] = <page id>

 

Step#5:

Finally, clear the site's cache by deleting all the files in the "App_Data\EPiServer\Cache" folder.

 

After following these steps, the page should be deleted from the database, and any references to it should be cleared from the cache. However, please note that this approach may have unintended consequences and should be performed with caution.

#301413
May 09, 2023 7:01
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.