Inpsyde\MultilingualPress\Database\WPDBTableReplacer::replace_table PHP Method

replace_table() public method

Replaces the content of one table with another table's content.
Since: 3.0.0
public replace_table ( string $destination, string $source ) : boolean
$destination string Name of the destination table.
$source string Name of the source table.
return boolean Whether or not the table was replaced successfully.
    public function replace_table($destination, $source)
    {
        $has_primary_key = (bool) $this->db->get_results("SHOW KEYS FROM {$destination} WHERE Key_name = 'PRIMARY'");
        if ($has_primary_key) {
            $this->db->query("ALTER TABLE {$destination} DISABLE KEYS");
        }
        $this->db->query("TRUNCATE TABLE {$destination}");
        $replaced_table = (bool) $this->db->query("INSERT INTO {$destination} SELECT * FROM {$source}");
        if ($has_primary_key) {
            $this->db->query("ALTER TABLE {$destination} ENABLE KEYS");
        }
        return $replaced_table;
    }