Try our conversational search powered by Generative AI!

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
Vote:
 

Since the regular deletion process through the user interface is failing, and the page is not going to the trash, you're seeking a way to delete it directly from the database.

Given that you're using Episerver version 11 and are locally hosted, it's important to approach this task carefully. As an experienced SQL developer, you're already familiar with the basics, such as the Page ID and Language ID.

To delete the page and clean up any stuck status partials in the cache, you can try the following steps:

  1. Begin by taking a backup of your database. This ensures that you have a safe copy before making any changes.

  2. Use your SQL expertise to identify the relevant elements of the page in the database. Start by locating the table(s) that store page data. In Episerver, it could be something like "tblContent."

  3. Once you've identified the appropriate table(s), construct a SQL script that targets the specific Page ID and Language ID associated with the page you want to delete. Make sure to include any other necessary identifiers you mentioned.

  4. The SQL script should contain DELETE statements that remove the corresponding records from the identified table(s). Be cautious and double-check your script to ensure you're targeting the correct page and not inadvertently deleting unrelated data.

  5. After executing the SQL script, verify that the page has been successfully removed from the database.

  6. To clean up any stuck status partials in the cache, you may need to locate the cache storage mechanism used by your Episerver installation. This could involve finding relevant cache files or tables. Clearing or deleting these files/records should help remove any remnants of the problematic page.

#303034
Jun 06, 2023 11:20
* 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.