Scan for and clean up orphaned post meta
This commit is contained in:
parent
b799633f99
commit
f175b499d9
@ -128,8 +128,8 @@ if ( ! defined( 'FICTIONEER_ADMIN_SETTINGS_NOTICES' ) ) {
|
||||
'fictioneer-not-renamed-role' => __( 'Error. Role could not be renamed.', 'fictioneer' ),
|
||||
'fictioneer-removed-role' => __( 'Role removed.', 'fictioneer' ),
|
||||
'fictioneer-not-removed-role' => __( 'Error. Role could not be removed.', 'fictioneer' ),
|
||||
'fictioneer-db-optimization-preview' => __( '%s superfluous post meta rows found. %s superfluous comment meta rows found. %s superfluous option rows found. Please backup your database before performing any optimization.', 'fictioneer' ),
|
||||
'fictioneer-db-optimization' => __( '%s superfluous rows have been deleted.', 'fictioneer' ),
|
||||
'fictioneer-db-optimization-preview' => __( '%s superfluous and %s orphaned post meta rows found. %s superfluous comment meta rows found. %s superfluous option rows found. Please backup your database before performing any optimization.', 'fictioneer' ),
|
||||
'fictioneer-db-optimization' => __( '%s superfluous or orphaned rows have been deleted.', 'fictioneer' ),
|
||||
'fictioneer-add-story-hidden' => __( 'The "fictioneer_story_hidden" meta field has been appended with value 0.', 'fictioneer' ),
|
||||
'fictioneer-add-story-sticky' => __( 'The "fictioneer_story_sticky" meta field has been appended with value 0.', 'fictioneer' ),
|
||||
'fictioneer-add-chapter-hidden' => __( 'The "fictioneer_chapter_hidden" meta field has been appended with value 0.', 'fictioneer' ),
|
||||
@ -1291,6 +1291,13 @@ function fictioneer_tools_optimize_database() {
|
||||
OR meta_key IN ('_edit_last', '_edit_lock')
|
||||
");
|
||||
|
||||
$orphaned_post_meta_count = $wpdb->query("
|
||||
DELETE pm
|
||||
FROM $wpdb->postmeta pm
|
||||
LEFT JOIN $wpdb->posts p ON pm.post_id = p.ID
|
||||
WHERE p.ID IS NULL
|
||||
");
|
||||
|
||||
// Delete comment meta
|
||||
$comment_meta_count = $wpdb->query("
|
||||
DELETE FROM $wpdb->commentmeta
|
||||
@ -1312,12 +1319,12 @@ function fictioneer_tools_optimize_database() {
|
||||
");
|
||||
|
||||
// Total rows
|
||||
$total = $post_meta_count + $comment_meta_count + $options_meta_count;
|
||||
$total = $post_meta_count + $orphaned_post_meta_count + $comment_meta_count + $options_meta_count;
|
||||
|
||||
// Log
|
||||
fictioneer_log(
|
||||
sprintf(
|
||||
__( 'Optimized database and removed %s superfluous rows.', 'fictioneer' ),
|
||||
__( 'Optimized database and removed %s superfluous or orphaned rows.', 'fictioneer' ),
|
||||
$total
|
||||
)
|
||||
);
|
||||
@ -1376,6 +1383,13 @@ function fictioneer_tools_optimize_database_preview() {
|
||||
OR meta_key IN ('_edit_last', '_edit_lock')
|
||||
");
|
||||
|
||||
$orphaned_post_meta_count = $wpdb->get_var("
|
||||
SELECT COUNT(*)
|
||||
FROM $wpdb->postmeta pm
|
||||
LEFT JOIN $wpdb->posts p ON pm.post_id = p.ID
|
||||
WHERE p.ID IS NULL
|
||||
");
|
||||
|
||||
// Comment meta
|
||||
$comment_meta_count = $wpdb->get_var("
|
||||
SELECT COUNT(*) FROM $wpdb->commentmeta
|
||||
@ -1401,7 +1415,7 @@ function fictioneer_tools_optimize_database_preview() {
|
||||
add_query_arg(
|
||||
array(
|
||||
'info' => 'fictioneer-db-optimization-preview',
|
||||
'data' => "{$post_meta_count},{$comment_meta_count},{$options_meta_count}"
|
||||
'data' => "{$post_meta_count},{$orphaned_post_meta_count},{$comment_meta_count},{$options_meta_count}"
|
||||
),
|
||||
wp_get_referer()
|
||||
)
|
||||
|
@ -3,7 +3,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Fictioneer\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-09-17 16:49+0000\n"
|
||||
"POT-Creation-Date: 2024-09-17 17:02+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: \n"
|
||||
@ -106,14 +106,14 @@ msgstr ""
|
||||
#: includes/functions/settings/_settings_actions.php:131
|
||||
#, php-format
|
||||
msgid ""
|
||||
"%s superfluous post meta rows found. %s superfluous comment meta rows found. "
|
||||
"%s superfluous option rows found. Please backup your database before "
|
||||
"performing any optimization."
|
||||
"%s superfluous and %s orphaned post meta rows found. %s superfluous comment "
|
||||
"meta rows found. %s superfluous option rows found. Please backup your "
|
||||
"database before performing any optimization."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:132
|
||||
#, php-format
|
||||
msgid "%s superfluous rows have been deleted."
|
||||
msgid "%s superfluous or orphaned rows have been deleted."
|
||||
msgstr ""
|
||||
|
||||
#: partials/_card-recommendation.php:75 partials/_card-recommendation.php:102
|
||||
@ -242,7 +242,7 @@ msgid ""
|
||||
"your nickname later.</p>"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1638
|
||||
#: includes/functions/settings/_settings_actions.php:1652
|
||||
#, php-format
|
||||
msgid ""
|
||||
"<p>No associated published chapters found.</p><p style=\"margin-top: -10px;"
|
||||
@ -1599,20 +1599,20 @@ msgstr ""
|
||||
msgid "Append to Comment"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1488
|
||||
#: includes/functions/settings/_settings_actions.php:1502
|
||||
msgid ""
|
||||
"Appended missing \"fictioneer_chapter_hidden\" meta fields with value 0."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1428
|
||||
#: includes/functions/settings/_settings_actions.php:1442
|
||||
msgid "Appended missing \"fictioneer_story_hidden\" meta fields with value 0."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1458
|
||||
#: includes/functions/settings/_settings_actions.php:1472
|
||||
msgid "Appended missing \"fictioneer_story_sticky\" meta fields with value 0."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1578
|
||||
#: includes/functions/settings/_settings_actions.php:1592
|
||||
msgid "Appending Preview"
|
||||
msgstr ""
|
||||
|
||||
@ -2852,7 +2852,7 @@ msgstr ""
|
||||
|
||||
#: includes/functions/_setup-types-and-terms.php:186
|
||||
#: includes/functions/_setup-types-and-terms.php:212
|
||||
#: includes/functions/settings/_settings_actions.php:1571
|
||||
#: includes/functions/settings/_settings_actions.php:1585
|
||||
#: includes/functions/hooks/_story_hooks.php:310
|
||||
#: includes/functions/users/_admin-profile.php:1436
|
||||
msgid "Chapter"
|
||||
@ -4726,7 +4726,7 @@ msgctxt "Date in Follows update list."
|
||||
msgid "%1$s \\a\\t %2$s"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1571
|
||||
#: includes/functions/settings/_settings_actions.php:1585
|
||||
msgid "Datetime"
|
||||
msgstr ""
|
||||
|
||||
@ -4841,7 +4841,7 @@ msgstr ""
|
||||
msgid "Deleted comments cannot be sticky."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1734
|
||||
#: includes/functions/settings/_settings_actions.php:1748
|
||||
msgid "Deleted global Patreon tiers."
|
||||
msgstr ""
|
||||
|
||||
@ -5098,7 +5098,7 @@ msgstr ""
|
||||
msgid "Disabled font key \"%s\"."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1864
|
||||
#: includes/functions/settings/_settings_actions.php:1878
|
||||
#, php-format
|
||||
msgid "Disabled mu-plugin: %s"
|
||||
msgstr ""
|
||||
@ -5745,7 +5745,7 @@ msgstr ""
|
||||
msgid "Enabled font key \"%s\"."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1820
|
||||
#: includes/functions/settings/_settings_actions.php:1834
|
||||
#, php-format
|
||||
msgid "Enabled mu-plugin: %s"
|
||||
msgstr ""
|
||||
@ -6034,8 +6034,8 @@ msgstr ""
|
||||
msgid "File not found or not readable."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1810
|
||||
#: includes/functions/settings/_settings_actions.php:1854
|
||||
#: includes/functions/settings/_settings_actions.php:1824
|
||||
#: includes/functions/settings/_settings_actions.php:1868
|
||||
msgid "File not found."
|
||||
msgstr ""
|
||||
|
||||
@ -6679,7 +6679,7 @@ msgctxt "Human readable list joining two items."
|
||||
msgid " or "
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1570
|
||||
#: includes/functions/settings/_settings_actions.php:1584
|
||||
msgid "ID"
|
||||
msgstr ""
|
||||
|
||||
@ -7586,7 +7586,7 @@ msgctxt "Migration tools chapter preview button."
|
||||
msgid "Preview"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1529
|
||||
#: includes/functions/settings/_settings_actions.php:1543
|
||||
#, php-format
|
||||
msgctxt "Migration tools invalid story ID."
|
||||
msgid ""
|
||||
@ -8232,9 +8232,9 @@ msgstr ""
|
||||
msgid "Optimize"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1320
|
||||
#: includes/functions/settings/_settings_actions.php:1327
|
||||
#, php-format
|
||||
msgid "Optimized database and removed %s superfluous rows."
|
||||
msgid "Optimized database and removed %s superfluous or orphaned rows."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/_setup-meta-fields.php:2638
|
||||
@ -8844,7 +8844,7 @@ msgstr ""
|
||||
msgid "Prevents users from ending up on the login page."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1580
|
||||
#: includes/functions/settings/_settings_actions.php:1594
|
||||
msgid "Preview"
|
||||
msgstr ""
|
||||
|
||||
@ -11164,7 +11164,7 @@ msgid ""
|
||||
"match internal paths."
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1805
|
||||
#: includes/functions/settings/_settings_actions.php:1819
|
||||
msgid "The mu-plugins subdirectory is missing in the theme directory."
|
||||
msgstr ""
|
||||
|
||||
@ -12499,6 +12499,6 @@ msgstr ""
|
||||
msgid "— Unset —"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions/settings/_settings_actions.php:1523
|
||||
#: includes/functions/settings/_settings_actions.php:1537
|
||||
msgid "← Back to tools"
|
||||
msgstr ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user