• Resolved matthew12461

    (@matthew12461)


    Sorry I don’t know where to report bugs. The Media Cleaner wouldn’t load so I fixed it by changing two instructions in core.php in wpmc_create_database() functions in wp-content\plugins\media-cleaner\classes folder. I changed the following code in core.php in wpmc_create_database() function: From this;

    wpmc_create_database() {
        /* These two instructions crash in Media Cleaner
        ** Might be bug in WordPress in 
        ** wp-admin/includes/upgrade.php?
        */
        dbDelta( $sql );
        dbDelta($sql);
    }

    To this:

    wpmc_create_database() {
        $wpdb->query($sql);
        $wpdb->query($sql);
    }

    Here’s the whole new code for wpmc_create_database():

    function wpmc_create_database() {
    	global $wpdb;
    	$table_name = $wpdb->prefix . "mclean_scan";
    	$charset_collate = $wpdb->get_charset_collate();
    	$sql = "CREATE TABLE $table_name (
    		id BIGINT(20) NOT NULL AUTO_INCREMENT,
    		time DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL,
    		type TINYINT(1) NOT NULL,
    		postId BIGINT(20) NULL,
    		path TINYTEXT NULL,
    		size INT(9) NULL,
    		ignored TINYINT(1) NOT NULL DEFAULT 0,
    		deleted TINYINT(1) NOT NULL DEFAULT 0,
    		issue TINYTEXT NOT NULL,
    		PRIMARY KEY  (id)
    	) " . $charset_collate . ";" ;
    	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    	// error_log($sql);
    	$wpdb->query($sql); 
    	// dbDelta( $sql );
    	// error_log("after crash");
    	$sql="ALTER TABLE $table_name ADD INDEX IgnoredIndex (ignored) USING BTREE;";
    	$wpdb->query($sql);
    	$table_name = $wpdb->prefix . "mclean_refs";
    	$charset_collate = $wpdb->get_charset_collate();
    	// This key doesn't work on too many installs because of the 'Specified key was too long' issue
    	// KEY mediaLookUp (mediaId, mediaUrl)
    	$sql = "CREATE TABLE $table_name (
    		id BIGINT(20) NOT NULL AUTO_INCREMENT,
    		mediaId BIGINT(20) NULL,
    		mediaUrl TINYTEXT NULL,
    		originType TINYTEXT NOT NULL,
    		PRIMARY KEY  (id)
    	) " . $charset_collate . ";";
    	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    	$wpdb->query($sql);
    	// dbDelta( $sql );
    }

    Here’s the old code:

    function wpmc_create_database() {
    	global $wpdb;
    	$table_name = $wpdb->prefix . "mclean_scan";
    	$charset_collate = $wpdb->get_charset_collate();
    	$sql = "CREATE TABLE $table_name (
    		id BIGINT(20) NOT NULL AUTO_INCREMENT,
    		time DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL,
    		type TINYINT(1) NOT NULL,
    		postId BIGINT(20) NULL,
    		path TINYTEXT NULL,
    		size INT(9) NULL,
    		ignored TINYINT(1) NOT NULL DEFAULT 0,
    		deleted TINYINT(1) NOT NULL DEFAULT 0,
    		issue TINYTEXT NOT NULL,
    		PRIMARY KEY  (id)
    	) " . $charset_collate . ";" ;
    	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    	dbDelta( $sql );
    	$sql="ALTER TABLE $table_name ADD INDEX IgnoredIndex (ignored) USING BTREE;";
    	$wpdb->query($sql);
    	$table_name = $wpdb->prefix . "mclean_refs";
    	$charset_collate = $wpdb->get_charset_collate();
    	// This key doesn't work on too many installs because of the 'Specified key was too long' issue
    	// KEY mediaLookUp (mediaId, mediaUrl)
    	$sql = "CREATE TABLE $table_name (
    		id BIGINT(20) NOT NULL AUTO_INCREMENT,
    		mediaId BIGINT(20) NULL,
    		mediaUrl TINYTEXT NULL,
    		originType TINYTEXT NOT NULL,
    		PRIMARY KEY  (id)
    	) " . $charset_collate . ";";
    	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    	dbDelta( $sql );
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jordy Meow

    (@tigroumeow)

    Hi,

    This code shouldn’t be used – maybe it works for you, but it’s not the way it should be done 🙂

    What the issue you encountered? The original code works for thousands (ten of thousands) of users, so there might be something about your PHP configuration.

    Thread Starter matthew12461

    (@matthew12461)

    I think it might be a conflict with another plugin in WordPress because there’s many plugins installled on website. I got this error before change code incase this might help you.:

    [06-Jun-2023 06:22:55 UTC] PHP Fatal error: Uncaught mysqli_sql_exception: Table 'v4db42910933849.wp_m8wtbshhdg_mclean_scan' doesn't exist in C:\Apache24\htdocs\wp-includes\wp-db.php:2056
    Stack trace: 0 C:\Apache24\htdocs\wp-includes\wp-db.php(2056): mysqli_query(Object(mysqli), 'DESCRIBE wp_m8w…') 1 C:\Apache24\htdocs\wp-includes\wp-db.php(1945): wpdb->_do_query('DESCRIBE wp_m8w…') 2 C:\Apache24\htdocs\wp-includes\wp-db.php(2695): wpdb->query('DESCRIBE wp_m8w…') 3 C:\Apache24\htdocs\wp-admin\includes\upgrade.php(2749): wpdb->get_results('DESCRIBE wp_m8w…') 4 C:\Apache24\htdocs\wp-content\plugins\media-cleaner\classes\core.php(1391): dbDelta(Array) 5 C:\Apache24\htdocs\wp-content\plugins\media-cleaner\classes\core.php(1367): wpmc_create_database() 6 C:\Apache24\htdocs\wp-content\plugins\media-cleaner\classes\ui.php(52): wpmc_check_database() 7 C:\Apache24\htdocs\wp-includes\class-wp-hook.php(303): Meow_WPMC_UI->cleaner_dashboard('') 8 C:\Apache24\htdocs\wp-includes\class-wp-hook.php(327): WP_Hook->apply_filters('', Array) 9 C:\Apache24\htdocs\wp-includes\plugin.php(470): WP_Hook->do_action(Array) 10 C:\Apache24\htdocs\wp-admin\admin.php(259): do_action('media_page_wpmc…') 11 C:\Apache24\htdocs\wp-admin\upload.php(10): require_once('C:\Apache24\htd…') 12 {main} thrown in C:\Apache24\htdocs\wp-includes\wp-db.php on line 2056
    Plugin Author Jordy Meow

    (@tigroumeow)

    It looks like the table wasn’t created successfuly, which is a bit weird. Have you tried to reset the plugin in the settings of Media Cleaner?

    Thread Starter matthew12461

    (@matthew12461)

    No I haven’t but program working properly for me now.

    • This reply was modified 2 years, 12 months ago by matthew12461.
    • This reply was modified 2 years, 12 months ago by matthew12461.
    • This reply was modified 2 years, 12 months ago by matthew12461.
    • This reply was modified 2 years, 12 months ago by matthew12461.
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Fixed bug with WordPress 5.8.7 and PHP 8’ is closed to new replies.