Congratulations!

[Valid RSS] This is a valid RSS feed.

Recommendations

This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.

Source: https://core.trac.wordpress.org/ticket/55329?format=rss

  1. <?xml version="1.0"?>
  2. <rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  3.  <channel>
  4.    <title>WordPress Trac: Ticket #55329: add_clean_index function throws PHP notice error</title>
  5.    <link>https://core.trac.wordpress.org/ticket/55329</link>
  6.    <description>&lt;p&gt;
  7. When I tried to add index for newly created column my error log filled with php notice 25 times because of the function &lt;code&gt;drop_index&lt;/code&gt; which is called inside the function &lt;code&gt;add_clean_index&lt;/code&gt;.
  8. &lt;/p&gt;
  9. &lt;p&gt;
  10. Sample snippet:
  11. &lt;/p&gt;
  12. &lt;div class="wiki-code"&gt;&lt;div class="code"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
  13. &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add_country_iso_code_column&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  14.        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nb"&gt;function_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'maybe_add_column'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  15.                &lt;span class="k"&gt;require_once&lt;/span&gt; &lt;span class="nx"&gt;ABSPATH&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'wp-admin/includes/upgrade.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  16.        &lt;span class="p"&gt;}&lt;/span&gt;
  17.        &lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="nv"&gt;$wpdb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  18.        &lt;span class="nv"&gt;$table_name&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$wpdb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;base_prefix&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'defender_lockout_log'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  19.        &lt;span class="nv"&gt;$column_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'country_iso_code'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  20.        &lt;span class="nv"&gt;$create_ddl&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ALTER TABLE &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$table_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; ADD &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$column_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; CHAR(2) DEFAULT NULL"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  21.        &lt;span class="nx"&gt;maybe_add_column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$table_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$column_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$create_ddl&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  22.        &lt;span class="nx"&gt;add_clean_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$table_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$column_name&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  23. &lt;span class="p"&gt;}&lt;/span&gt;
  24. &lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;
  25. Error:
  26. &lt;/p&gt;
  27. &lt;pre class="wiki"&gt;[Mon Mar 07 18:45:40.809008 2022] [php:notice] [pid 1167] [client 127.0.0.1:48886] WordPress database error Can't DROP 'country_iso_code_1'; check that column/key exists for query ALTER TABLE `wp_defender_lockout_log` DROP INDEX `country_iso_code_1` made by require_once('wp-admin/network/admin.php'), require_once('wp-admin/admin.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('init'), WP_Hook-&amp;gt;do_action, WP_Hook-&amp;gt;apply_filters, WP_Defender\\Upgrader-&amp;gt;run, WP_Defender\\Upgrader-&amp;gt;upgrade_2_8_1, WP_Defender\\Upgrader-&amp;gt;add_country_iso_code_column, add_clean_index, drop_index, referer: http://multi.test/wp-admin/network/update.php?action=upload-plugin&amp;amp;package=55&amp;amp;overwrite=update-plugin&amp;amp;_wpnonce=c8b371f5b8
  28. &lt;/pre&gt;&lt;hr /&gt;
  29. &lt;p&gt;
  30. Error log screenshot:
  31. &lt;a class="ext-link" href="https://i.postimg.cc/2jqsb3Z4/bug-report.png"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;https://i.postimg.cc/2jqsb3Z4/bug-report.png&lt;/a&gt;
  32. &lt;/p&gt;
  33. </description>
  34.    <language>en-us</language>
  35.    <image>
  36.      <title>WordPress Trac</title>
  37.      <url>https://core.trac.wordpress.org/chrome/site/your_project_logo.png</url>
  38.      <link>https://core.trac.wordpress.org/ticket/55329</link>
  39.    </image>
  40.    <generator>Trac 1.2.2</generator>
  41.    <item>
  42.      
  43.        <dc:creator>slackbot</dc:creator>
  44.  
  45.      <pubDate>Tue, 08 Mar 2022 17:45:01 GMT</pubDate>
  46.      <title></title>
  47.      <link>https://core.trac.wordpress.org/ticket/55329#comment:1</link>
  48.      <guid isPermaLink="false">https://core.trac.wordpress.org/ticket/55329#comment:1</guid>
  49.      <description>
  50.        &lt;p&gt;
  51. &lt;em&gt;This ticket was mentioned in &lt;a class="ext-link" href="https://make.wordpress.org/chat/"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;Slack&lt;/a&gt; in #core-auto-updates by pbiron. &lt;a class="ext-link" href="https://wordpress.slack.com/archives/core-auto-updates/p1646761499125359"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;View the logs&lt;/a&gt;.&lt;/em&gt;
  52. &lt;/p&gt;
  53.      </description>
  54.      <category>Ticket</category>
  55.    </item><item>
  56.      
  57.        <dc:creator>prbot</dc:creator>
  58.  
  59.      <pubDate>Wed, 06 Nov 2024 17:25:13 GMT</pubDate>
  60.      <title>keywords set</title>
  61.      <link>https://core.trac.wordpress.org/ticket/55329#comment:2</link>
  62.      <guid isPermaLink="false">https://core.trac.wordpress.org/ticket/55329#comment:2</guid>
  63.      <description>
  64.          &lt;ul&gt;
  65.            &lt;li&gt;&lt;strong&gt;keywords&lt;/strong&gt;
  66.              &lt;em&gt;has-patch&lt;/em&gt; added
  67.            &lt;/li&gt;
  68.          &lt;/ul&gt;
  69.        &lt;p&gt;
  70. &lt;em&gt;This ticket was mentioned in &lt;a class="ext-link" href="https://github.com/WordPress/wordpress-develop/pull/7737"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;PR #7737&lt;/a&gt; on &lt;a class="ext-link" href="https://github.com/WordPress/wordpress-develop/"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;WordPress/wordpress-develop&lt;/a&gt; by &lt;a class="ext-link" href="https://profiles.wordpress.org/debarghyabanerjee/"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;@debarghyabanerjee&lt;/a&gt;.&lt;/em&gt;
  71. Trac Ticket: Core-55329
  72. &lt;/p&gt;
  73. &lt;p&gt;
  74. ## Summary
  75. &lt;/p&gt;
  76. &lt;p&gt;
  77. This pull request introduces a new utility function, has_index(), which checks if an index exists for a specific column in a given database table. Additionally, the add_clean_index() function has been refactored to use this new helper function, ensuring that indexes are only added when they don't already exist and preventing unnecessary index drops or duplicate indexes.
  78. &lt;/p&gt;
  79. &lt;p&gt;
  80. ## Changes
  81. &lt;/p&gt;
  82. &lt;ul&gt;&lt;li&gt;Added &lt;code&gt;has_index()&lt;/code&gt; Function
  83. &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;This function checks if an index exists for a specified column in a table.
  84. &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;It performs a database query using the SHOW INDEX command to determine if an index is associated with the given column.
  85. &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Returns true if an index exists for the column, otherwise returns false.
  86. &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Refactored &lt;code&gt;add_clean_index()&lt;/code&gt; Function
  87. &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;The &lt;code&gt;add_clean_index()&lt;/code&gt; function now uses has_index() to verify whether an index already exists on the specified column before attempting to add it.
  88. &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;If the index exists, the function returns early and skips adding the index, avoiding redundant operations.
  89. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;
  90. ## Benefits:
  91. &lt;/p&gt;
  92. &lt;ul&gt;&lt;li&gt;Improved Performance: By ensuring that indexes are only added if they don't already exist, we avoid unnecessary database operations, reducing execution time and resource usage.
  93. &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Increased Code Reusability: The &lt;code&gt;has_index()&lt;/code&gt; function is a reusable utility, simplifying future database operations that involve index checks.
  94. &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Cleaner Logic: The logic for adding indexes is now more streamlined and easier to understand, with the check for existing indexes encapsulated in a dedicated function.
  95. &lt;/li&gt;&lt;/ul&gt;
  96.      </description>
  97.      <category>Ticket</category>
  98.    </item><item>
  99.      
  100.        <dc:creator>prbot</dc:creator>
  101.  
  102.      <pubDate>Fri, 08 Nov 2024 01:25:13 GMT</pubDate>
  103.      <title></title>
  104.      <link>https://core.trac.wordpress.org/ticket/55329#comment:3</link>
  105.      <guid isPermaLink="false">https://core.trac.wordpress.org/ticket/55329#comment:3</guid>
  106.      <description>
  107.        &lt;p&gt;
  108. &lt;a class="ext-link" href="https://profiles.wordpress.org/hemak/"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;@hemak&lt;/a&gt; commented on &lt;a class="ext-link" href="https://github.com/WordPress/wordpress-develop/pull/7737#issuecomment-2463568612"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;PR #7737&lt;/a&gt;:
  109. &lt;/p&gt;
  110. &lt;p&gt;
  111. Thank you !
  112. &lt;/p&gt;
  113.      </description>
  114.      <category>Ticket</category>
  115.    </item>
  116. </channel>
  117. </rss>

If you would like to create a banner that links to this page (i.e. this validation result), do the following:

  1. Download the "valid RSS" banner.

  2. Upload the image to your own server. (This step is important. Please do not link directly to the image on this server.)

  3. Add this HTML to your page (change the image src attribute if necessary):

If you would like to create a text link instead, here is the URL you can use:

http://www.feedvalidator.org/check.cgi?url=https%3A//core.trac.wordpress.org/ticket/55329%3Fformat%3Drss

Copyright © 2002-9 Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda