Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/network-.../componen.../db
File: NetsPostsTemporaryTableManager.php
<?php
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
namespace NetworkPosts\Components\DB;
[3] Fix | Delete
[4] Fix | Delete
[5] Fix | Delete
class NetsPostsTemporaryTableManager {
[6] Fix | Delete
[7] Fix | Delete
private const TEMP_RESULTS_TABLE = "network_posts_results";
[8] Fix | Delete
[9] Fix | Delete
/** @var \WPDB */
[10] Fix | Delete
private $db;
[11] Fix | Delete
private $temp_tables = array();
[12] Fix | Delete
[13] Fix | Delete
public function __construct( \WPDB $db ) {
[14] Fix | Delete
$this->db = $db;
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* @param string $query
[19] Fix | Delete
*
[20] Fix | Delete
* @return string Returns temporary table name
[21] Fix | Delete
* @throws \Exception
[22] Fix | Delete
*/
[23] Fix | Delete
public function create_new( string $query ): string {
[24] Fix | Delete
$table = $this->generate_table_name();
[25] Fix | Delete
$result = $this->db->query( "CREATE TEMPORARY TABLE $table $query" );
[26] Fix | Delete
if( $result ) {
[27] Fix | Delete
$this->temp_tables[] = $table;
[28] Fix | Delete
return $table;
[29] Fix | Delete
}
[30] Fix | Delete
throw new \Exception( $this->db->last_error );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
protected function generate_table_name(): string {
[34] Fix | Delete
$table = $this->db->prefix . self::TEMP_RESULTS_TABLE;
[35] Fix | Delete
$table .= random_int(1, 1000);
[36] Fix | Delete
return $table;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
public function create_empty( array $schema ): string {
[40] Fix | Delete
$columns = array();
[41] Fix | Delete
foreach( $schema as $column => $props ){
[42] Fix | Delete
$columns[] = $column . ' ' . $props;
[43] Fix | Delete
}
[44] Fix | Delete
$table_schema_query = '(' . implode( ',', $columns ) . ')';
[45] Fix | Delete
return $this->create_new( $table_schema_query );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* @param string $table
[50] Fix | Delete
* @param array $column_names
[51] Fix | Delete
* @param string $query
[52] Fix | Delete
*
[53] Fix | Delete
* @throws \Exception Throws exception in case of bad query or incomparable data schema
[54] Fix | Delete
*/
[55] Fix | Delete
public function insert_data( string $table, array $column_names, string $query ): void {
[56] Fix | Delete
$columns = '(' . implode( ',', $column_names ) . ')';
[57] Fix | Delete
$result = $this->db->query( 'INSERT INTO ' . $table . ' ' . $columns . ' ' . $query );
[58] Fix | Delete
if( ! $result && $this->db->last_error ) throw new \Exception( $this->db->last_error );
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* @param string $source_table
[63] Fix | Delete
* @param string $target_table
[64] Fix | Delete
* @param array $column_names
[65] Fix | Delete
*
[66] Fix | Delete
* @throws \Exception
[67] Fix | Delete
*/
[68] Fix | Delete
public function copy_from_table( string $source_table, string $target_table,
[69] Fix | Delete
array $column_names = array() ): void {
[70] Fix | Delete
$query = 'INSERT INTO ' . $target_table;
[71] Fix | Delete
if( $column_names ){
[72] Fix | Delete
$columns = implode( ',', $column_names );
[73] Fix | Delete
$query .= '(' . $columns . ')';
[74] Fix | Delete
$query .= ' SELECT ' . $columns;
[75] Fix | Delete
} else {
[76] Fix | Delete
$query .= ' SELECT *';
[77] Fix | Delete
}
[78] Fix | Delete
$query .= ' FROM ' . $source_table;
[79] Fix | Delete
$result = $this->db->query( $query );
[80] Fix | Delete
if( ! $result && $this->db->last_error ) throw new \Exception( $this->db->last_error );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* We need to destroy all temporary tables to prevent collisions
[85] Fix | Delete
* because there can be multiple shortcodes during 1 session
[86] Fix | Delete
*/
[87] Fix | Delete
public function destroy() {
[88] Fix | Delete
foreach ( $this->temp_tables as $table ){
[89] Fix | Delete
$this->drop_table( $table );
[90] Fix | Delete
}
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
protected function drop_table( string $table ): void {
[94] Fix | Delete
$this->db->query( 'DROP TEMPORARY TABLE IF EXISTS ' . $table );
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function