Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../includes/Abstract...
File: Migration.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
[2] Fix | Delete
[3] Fix | Delete
abstract class NF_Abstracts_Migration
[4] Fix | Delete
{
[5] Fix | Delete
public $table_name = '';
[6] Fix | Delete
[7] Fix | Delete
public $charset_collate = '';
[8] Fix | Delete
[9] Fix | Delete
public $flag = '';
[10] Fix | Delete
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Constructor method for the NF_Abstracts_Migration class.
[14] Fix | Delete
*
[15] Fix | Delete
* @param $table_name (String) The database table name managed by the extension.
[16] Fix | Delete
* @param $flag (String) The wp option set to determine if this migration has already been run.
[17] Fix | Delete
*
[18] Fix | Delete
* @since 3.0.0
[19] Fix | Delete
*/
[20] Fix | Delete
public function __construct( $table_name, $flag )
[21] Fix | Delete
{
[22] Fix | Delete
$this->table_name = $table_name;
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Function to retrieve the full table name of the extension.
[28] Fix | Delete
*
[29] Fix | Delete
* @return (String) The full table name, including database prefix.
[30] Fix | Delete
*
[31] Fix | Delete
* @since 3.0.28
[32] Fix | Delete
*/
[33] Fix | Delete
public function table_name()
[34] Fix | Delete
{
[35] Fix | Delete
global $wpdb;
[36] Fix | Delete
return $wpdb->prefix . $this->table_name;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Function to check for the existence of a column in the extension's table.
[42] Fix | Delete
*
[43] Fix | Delete
* @param $column (String) The name of the column to search for.
[44] Fix | Delete
*
[45] Fix | Delete
* @return (Boolean) Whether or not the column exists.
[46] Fix | Delete
*
[47] Fix | Delete
* @since 3.4.0
[48] Fix | Delete
*/
[49] Fix | Delete
public function column_exists( $column )
[50] Fix | Delete
{
[51] Fix | Delete
global $wpdb;
[52] Fix | Delete
$response = false;
[53] Fix | Delete
// Fetch any records of the target column.
[54] Fix | Delete
$sql = $wpdb->prepare( "SHOW COLUMNS FROM `{$this->table_name()}` WHERE `Field` = '%s';", $column );
[55] Fix | Delete
$result = $wpdb->query( $sql );
[56] Fix | Delete
// If we got anything back, say so.
[57] Fix | Delete
if ( ! empty( $result ) ) $response = true;
[58] Fix | Delete
return $response;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Funciton to get the charset and collate for migrations.
[64] Fix | Delete
*
[65] Fix | Delete
* @param $use_default (Boolean) Whether or not to include the DEFAULT keyword in the return pattern.
[66] Fix | Delete
*
[67] Fix | Delete
* @return (String) A SQL formatted charset and collate for use by table definition.
[68] Fix | Delete
*
[69] Fix | Delete
* @since 3.0.28
[70] Fix | Delete
* @updated 3.1.14
[71] Fix | Delete
*/
[72] Fix | Delete
public function charset_collate( $use_default = false )
[73] Fix | Delete
{
[74] Fix | Delete
$response = '';
[75] Fix | Delete
global $wpdb;
[76] Fix | Delete
// If our mysql version is 5.5.3 or higher...
[77] Fix | Delete
if ( version_compare( $wpdb->db_version(), '5.5.3', '>=' ) ) {
[78] Fix | Delete
// We can use mb4.
[79] Fix | Delete
$response = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci';
[80] Fix | Delete
} // Otherwise...
[81] Fix | Delete
else {
[82] Fix | Delete
// We use standard utf8.
[83] Fix | Delete
$response = 'CHARACTER SET utf8 COLLATE utf8_general_ci';
[84] Fix | Delete
}
[85] Fix | Delete
// If we need to use default...
[86] Fix | Delete
if ( $use_default ) {
[87] Fix | Delete
// Append that to the response.
[88] Fix | Delete
$response = 'DEFAULT ' . $response;
[89] Fix | Delete
}
[90] Fix | Delete
return $response;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Function to run our required update functions.
[95] Fix | Delete
*
[96] Fix | Delete
* @param $callback (String) The function to be run by this call.
[97] Fix | Delete
*
[98] Fix | Delete
* @since 3.4.0
[99] Fix | Delete
*/
[100] Fix | Delete
public function _do_upgrade( $callback )
[101] Fix | Delete
{
[102] Fix | Delete
// If the method exists...
[103] Fix | Delete
if ( method_exists( $this, $callback ) ) {
[104] Fix | Delete
$blacklist = array(
[105] Fix | Delete
'__construct',
[106] Fix | Delete
'_do_upgrade',
[107] Fix | Delete
'_run',
[108] Fix | Delete
'run',
[109] Fix | Delete
'_drop',
[110] Fix | Delete
'drop'
[111] Fix | Delete
);
[112] Fix | Delete
// If this callback method isn't blacklisted...
[113] Fix | Delete
if ( ! in_array( $callback, $blacklist ) ) {
[114] Fix | Delete
// Run it.
[115] Fix | Delete
$this->{$callback}();
[116] Fix | Delete
}
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* Function to run our initial migration.
[123] Fix | Delete
*
[124] Fix | Delete
* @since 3.0.0
[125] Fix | Delete
*/
[126] Fix | Delete
public function _run()
[127] Fix | Delete
{
[128] Fix | Delete
// Check the flag
[129] Fix | Delete
if( get_option( $this->flag, FALSE ) ) return;
[130] Fix | Delete
[131] Fix | Delete
// Run the migration
[132] Fix | Delete
$this->run();
[133] Fix | Delete
[134] Fix | Delete
// Set the Flag
[135] Fix | Delete
update_option( $this->flag, TRUE );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Abstract protection of inherited funciton run.
[141] Fix | Delete
*
[142] Fix | Delete
* @since 3.0.0
[143] Fix | Delete
*/
[144] Fix | Delete
protected abstract function run();
[145] Fix | Delete
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* Function to drop the table managed by this migration.
[149] Fix | Delete
*
[150] Fix | Delete
* @since 3.0.28
[151] Fix | Delete
*/
[152] Fix | Delete
public function _drop()
[153] Fix | Delete
{
[154] Fix | Delete
global $wpdb;
[155] Fix | Delete
// If we don't have a table name, exit early.
[156] Fix | Delete
if( ! $this->table_name ) return;
[157] Fix | Delete
// If the table doesn't exist, exit early.
[158] Fix | Delete
if( 0 == $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $this->table_name() ) ) ) return;
[159] Fix | Delete
// Drop the table.
[160] Fix | Delete
$wpdb->query( "DROP TABLE " . $this->table_name() );
[161] Fix | Delete
return $this->drop();
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Protection of inherited function drop.
[167] Fix | Delete
*
[168] Fix | Delete
* @since 3.0.28
[169] Fix | Delete
*/
[170] Fix | Delete
protected function drop()
[171] Fix | Delete
{
[172] Fix | Delete
// This section intentionally left blank.
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function