WordPress.org

Make WordPress Core

Opened 16 months ago

Last modified 16 months ago

#22884 new enhancement

What if I delete wp_posts table from database.

Reported by: mukkundthanki Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.5
Component: Database Keywords: dev-feedback
Focuses: Cc:

Description

I am not a experienced or mature programmer but I have seen it While I was playing with database of WordPress.

I have deleted wp_posts table in database in WordPress - 3.5(beta).

It looks normal on other pages at admin side but when i open single post it shows post-new.php and when hit save, it shows "wp_error" with this message "You are not allowed to edit this post."

That's OK. I was expecting error but not this type of error.

It seems WordPress doesn't know that its most important table has gone away and that's why admin may not know( well for a while). I think its not good. well I don't know its issue or it is way it behaves with database and its normal but I think WordPress should know what exactly happened.

when I have updated WordPress with stable 3.5 it has updated but database is still same which is normal.

Should we( can we )track tables( some of tables which are important ) by PHP ?

Change History (5)

comment:1 knutsp16 months ago

  • Cc knut@… added
  • Keywords close added

Joking here? If not ...

And if you have the posts table, but have removed a column or two from it? I guess it's quite unpredictable and I wouldn't expect it to be otherwise.

I guess that when WordPress is updated, and there are schema changes, this could be detected and the table created and/or fixed.

I think that id you drop the options table, then WordPress will think it's not installed. Try that, and WordPress will recreate the posts table.

To check if someone has tampered with your database schema since installed, I guess a plugin could be handy.

comment:2 nacin16 months ago

  • Keywords close removed
  • Type changed from defect (bug) to enhancement

What if I delete wp_posts table from database.

I found that unintentionally hilarious. Beyond that, though, you have a good enhancement request.

WordPress currently checks for the options table on startup. See is_blog_installed(). If the options table is missing, it checks to see if any other tables are missing. If they are *all* missing, it assumes you haven't installed WordPres yet. If only some are missing, it assumes things are "insane" and issues a repair warning and dies with dead_db().

We *could* do similar checks throughout the admin. Check posts and postmeta on edit.php/post.php, etc. I don't think it is truly necessary, but it's a good thought.

Version 0, edited 16 months ago by nacin (next)

comment:3 markjaquith16 months ago

Shouldn't WPDB throw an error if you try to query a table that does not exist?

comment:4 Ipstenu16 months ago

Mark, maybe that actually is the first time you try to query that table? The only place I would think it might otherwise show up is on the post lists page, or the main dashboard when it queries post numbers (though that may default to 0 if none are found).

How much would running this check impact performance? We don't want to slow WP Admin down even more.

comment:5 mukkundthanki16 months ago

yes mark. I think it should. I have found that when I hit save it checks if this post exists or not with "get_post" and "get_instance" and at last "get_row" method of WPDB class. so "get_instance" returns false to "get_post" and it returns null and finally die with capability check with user and thats why we get "You are not allowed to edit this post." error. well I think it should be died earlier while checking with db. can we alter only db methods with this type of checks like table exists or what actually returns and then taking further actions with specific results.

Thanks nacin. I have seen what you have stated and its really useful. well My thought is about making WordPress realize what actually happened out there, may be it gives more load to admin and affect performance.

Last edited 16 months ago by mukkundthanki (previous) (diff)
Note: See TracTickets for help on using tickets.