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

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/ninja-fo.../includes/Updates
File: CacheCollateFields.php
[500] Fix | Delete
/*
[501] Fix | Delete
* Keep track of old field ids we've used.
[502] Fix | Delete
* Initially, we set our record array to our current submission updates array.
[503] Fix | Delete
* When we finish updating an old field, we remove it from the record array.
[504] Fix | Delete
* When we're done with all fields, we set the submission updates array to the record array.
[505] Fix | Delete
*/
[506] Fix | Delete
$submission_updates_record = $this->submission_updates;
[507] Fix | Delete
// Meta key update limit; How many meta keys do we want to update at a time?
[508] Fix | Delete
$meta_key_limit = 200;
[509] Fix | Delete
// Loop through submission updates and query the postmeta table for any meta_key values of _field_{old_id}.
[510] Fix | Delete
foreach ( $this->submission_updates as $old_id => $new_id ) {
[511] Fix | Delete
// Make sure that we haven't reached our query limit.
[512] Fix | Delete
if ( 1 > $this->limit ) {
[513] Fix | Delete
// Lock processing.
[514] Fix | Delete
$this->lock_process = true;
[515] Fix | Delete
// Exit the loop.
[516] Fix | Delete
break;
[517] Fix | Delete
}
[518] Fix | Delete
[519] Fix | Delete
// This sql is designed to grab our old _field_X post meta keys so that we can replace them with new _field_X meta keys.
[520] Fix | Delete
$sql = "SELECT
[521] Fix | Delete
old_field_id.meta_id
[522] Fix | Delete
FROM
[523] Fix | Delete
`{$this->db->prefix}posts` p
[524] Fix | Delete
INNER JOIN `{$this->db->prefix}postmeta` old_field_id ON old_field_id.post_id = p.ID
[525] Fix | Delete
AND old_field_id.meta_key = '_field_{$old_id}'
[526] Fix | Delete
INNER JOIN `{$this->db->prefix}postmeta` form_id ON form_id.post_id = p.ID
[527] Fix | Delete
AND form_id.meta_key = '_form_id'
[528] Fix | Delete
[529] Fix | Delete
WHERE old_field_id.meta_key = '_field_{$old_id}'
[530] Fix | Delete
AND form_id.meta_value = {$this->form[ 'ID' ]}
[531] Fix | Delete
AND p.post_type = 'nf_sub'
[532] Fix | Delete
LIMIT {$meta_key_limit}";
[533] Fix | Delete
// Fetch our sql results.
[534] Fix | Delete
$meta_ids = $this->db->get_results( $sql, 'ARRAY_N' );
[535] Fix | Delete
if ( ! empty( $meta_ids ) ) {
[536] Fix | Delete
// Implode our meta ids so that we can use the result in our update sql.
[537] Fix | Delete
$imploded_ids = implode( ',', call_user_func_array( 'array_merge', $meta_ids ) );
[538] Fix | Delete
// Update all our fetched meta ids with the new _field_ meta key.
[539] Fix | Delete
$sql = "UPDATE `{$this->db->prefix}postmeta`
[540] Fix | Delete
SET meta_key = '_field_{$new_id}'
[541] Fix | Delete
WHERE meta_id IN ( {$imploded_ids} )";
[542] Fix | Delete
[543] Fix | Delete
$this->query( $sql );
[544] Fix | Delete
}
[545] Fix | Delete
[546] Fix | Delete
/*
[547] Fix | Delete
* Let's make sure that we're done processing all post meta for this old field ID.
[548] Fix | Delete
*
[549] Fix | Delete
* If the number of meta rows retrieved equals our limit:
[550] Fix | Delete
* lock processing
[551] Fix | Delete
* break out of this loop
[552] Fix | Delete
* Else
[553] Fix | Delete
* we're done with this old field, remove it from our list
[554] Fix | Delete
* subtract from our $this->limit var
[555] Fix | Delete
*/
[556] Fix | Delete
if ( $meta_key_limit === count( $meta_ids ) ) {
[557] Fix | Delete
// Keep anything else from processing.
[558] Fix | Delete
$this->lock_process = true;
[559] Fix | Delete
// Exit this foreach loop.
[560] Fix | Delete
break;
[561] Fix | Delete
} else { // We're done with this old field.
[562] Fix | Delete
// Remove the field ID from our submission array.
[563] Fix | Delete
unset( $submission_updates_record[ $old_id ] );
[564] Fix | Delete
// Decrement our query limit.
[565] Fix | Delete
$this->limit--;
[566] Fix | Delete
}
[567] Fix | Delete
[568] Fix | Delete
} // End foreach
[569] Fix | Delete
// Set our submission updates array to our record array so that we remove any completed old ids.
[570] Fix | Delete
$this->submission_updates = $submission_updates_record;
[571] Fix | Delete
}
[572] Fix | Delete
[573] Fix | Delete
/**
[574] Fix | Delete
* If we still have field_ids in our class var, then we need to update the field table.
[575] Fix | Delete
*
[576] Fix | Delete
* If lock_process is true or we have no field_ids, we bail early.
[577] Fix | Delete
*
[578] Fix | Delete
* @since 3.4.0
[579] Fix | Delete
* @return void
[580] Fix | Delete
*/
[581] Fix | Delete
private function maybe_update_fields()
[582] Fix | Delete
{
[583] Fix | Delete
// If we have no fields to insert OR lock_process is true, bail early.
[584] Fix | Delete
if ( empty ( $this->field_ids ) || $this->lock_process ) {
[585] Fix | Delete
return false;
[586] Fix | Delete
}
[587] Fix | Delete
[588] Fix | Delete
// Store the meta items outside the loop for faster insertion.
[589] Fix | Delete
$meta_items = array();
[590] Fix | Delete
$flush_ids = array();
[591] Fix | Delete
// While we still have items to update...
[592] Fix | Delete
while ( 0 < count( $this->field_ids ) ) {
[593] Fix | Delete
// If we have hit our limit...
[594] Fix | Delete
if ( 1 > $this->limit ) {
[595] Fix | Delete
// Lock processing.
[596] Fix | Delete
$this->lock_process = true;
[597] Fix | Delete
// Exit the loop.
[598] Fix | Delete
break;
[599] Fix | Delete
}
[600] Fix | Delete
// Get our item to be updated.
[601] Fix | Delete
$updating = array_pop( $this->field_ids );
[602] Fix | Delete
array_push( $flush_ids, $updating );
[603] Fix | Delete
$settings = $this->fields_by_id[ $updating ];
[604] Fix | Delete
// Update the fields table.
[605] Fix | Delete
$sql = "UPDATE `{$this->table}` SET label = '"
[606] Fix | Delete
. $this->prepare( $settings[ 'label' ] )
[607] Fix | Delete
. "', `key` = '" . $this->prepare( $settings[ 'key' ] )
[608] Fix | Delete
. "', `type` = '" . $this->prepare( $settings[ 'type' ] )
[609] Fix | Delete
. "', field_label = '" . $this->prepare( $settings[ 'label' ] )
[610] Fix | Delete
. "', field_key = '" . $this->prepare( $settings[ 'key' ] )
[611] Fix | Delete
. "', `order` = " . intval( $settings[ 'order' ] );
[612] Fix | Delete
[613] Fix | Delete
if( isset( $settings[ 'required' ] ) ) {
[614] Fix | Delete
$sql .= ", required = " . intval( $settings[ 'required' ] );
[615] Fix | Delete
} else {
[616] Fix | Delete
$sql .= ", required = 0";
[617] Fix | Delete
}
[618] Fix | Delete
[619] Fix | Delete
if ( isset( $settings[ 'default_value' ] ) ) {
[620] Fix | Delete
$sql .= ", default_value = '" . $this->prepare( $settings[ 'default_value' ] ) . "'";
[621] Fix | Delete
} else {
[622] Fix | Delete
$sql .= ", default_value = ''";
[623] Fix | Delete
}
[624] Fix | Delete
[625] Fix | Delete
if ( isset( $settings[ 'label_pos' ] ) ) {
[626] Fix | Delete
$sql .= ", label_pos = '" . $this->prepare( $settings[ 'label_pos' ] ) . "'";
[627] Fix | Delete
} else {
[628] Fix | Delete
$sql .= ", label_pos = ''";
[629] Fix | Delete
}
[630] Fix | Delete
[631] Fix | Delete
if ( isset( $settings[ 'personally_identifiable' ] ) ) {
[632] Fix | Delete
$sql .= ", personally_identifiable = " . intval( $settings[ 'personally_identifiable' ] );
[633] Fix | Delete
} else {
[634] Fix | Delete
$sql .= ", personally_identifiable = 0";;
[635] Fix | Delete
}
[636] Fix | Delete
$sql .= " WHERE id = " . intval( $updating );
[637] Fix | Delete
$this->query( $sql );
[638] Fix | Delete
// For each meta of the field...
[639] Fix | Delete
foreach ( $settings as $meta => $value ) {
[640] Fix | Delete
// If it's not empty...
[641] Fix | Delete
if ( ( ! empty( $value ) || '0' == $value ) ) {
[642] Fix | Delete
// Add the data to the list.
[643] Fix | Delete
array_push( $meta_items, "( " . intval( $updating ) . ", '" . $meta . "', '" . $this->prepare( $value ) . "', '" . $meta . "', '" . $this->prepare( $value ) . "' )" );
[644] Fix | Delete
}
[645] Fix | Delete
}
[646] Fix | Delete
// Remove the item from the list of fields.
[647] Fix | Delete
unset( $this->fields_by_id[ $updating ] );
[648] Fix | Delete
// Reduce the limit.
[649] Fix | Delete
$this->limit--;
[650] Fix | Delete
}
[651] Fix | Delete
if ( ! empty ( $flush_ids ) ) {
[652] Fix | Delete
// Flush our existing meta.
[653] Fix | Delete
$sql = "DELETE FROM `{$this->meta_table}` WHERE parent_id IN(" . implode( ', ', $flush_ids ) . ")";
[654] Fix | Delete
$this->query( $sql );
[655] Fix | Delete
}
[656] Fix | Delete
[657] Fix | Delete
// Insert our updated meta.
[658] Fix | Delete
$sql = "INSERT INTO `{$this->meta_table}` ( parent_id, `key`, value, meta_key, meta_value ) VALUES " . implode( ', ', $meta_items );
[659] Fix | Delete
$this->query( $sql );
[660] Fix | Delete
}
[661] Fix | Delete
[662] Fix | Delete
/**
[663] Fix | Delete
* If we've inserted any fields that have changed ids, we want to update those ids in our cache.
[664] Fix | Delete
* This method grabs the cache, updates any field ids, then updates the cache.
[665] Fix | Delete
*
[666] Fix | Delete
* @since 3.4.0
[667] Fix | Delete
* @return void
[668] Fix | Delete
*/
[669] Fix | Delete
private function update_form_cache()
[670] Fix | Delete
{
[671] Fix | Delete
// Get a copy of the cache.
[672] Fix | Delete
$cache = WPN_Helper::get_nf_cache($this->form[ 'ID' ] );
[673] Fix | Delete
// For each field in the cache...
[674] Fix | Delete
foreach( $cache[ 'fields' ] as &$field ) {
[675] Fix | Delete
// If we have a new ID for this field...
[676] Fix | Delete
if ( isset( $this->insert_ids[ $field[ 'id' ] ] ) ) {
[677] Fix | Delete
// Update it.
[678] Fix | Delete
$field[ 'id' ] = intval( $this->insert_ids[ $field[ 'id' ] ] );
[679] Fix | Delete
}
[680] Fix | Delete
// TODO: Might also need to append some new settings here (Label)?
[681] Fix | Delete
}
[682] Fix | Delete
// Save the cache, passing 3 as the current stage.
[683] Fix | Delete
WPN_Helper::update_nf_cache( $this->form[ 'ID' ], $cache, 3 );
[684] Fix | Delete
}
[685] Fix | Delete
[686] Fix | Delete
/**
[687] Fix | Delete
* After we've done our processing, but before we get to step cleanup, we need to store process information.
[688] Fix | Delete
*
[689] Fix | Delete
* This method updates our form class var so that it can be passed to the next step.
[690] Fix | Delete
* If we've completed this step, it calls the cleanup method.
[691] Fix | Delete
*
[692] Fix | Delete
* @since 3.4.0
[693] Fix | Delete
* @return void
[694] Fix | Delete
*/
[695] Fix | Delete
private function end_of_step()
[696] Fix | Delete
{
[697] Fix | Delete
// If we have locked processing...
[698] Fix | Delete
if ( $this->lock_process ) {
[699] Fix | Delete
// If we're continuing a process...
[700] Fix | Delete
if ( isset( $this->form[ 'field_ids' ] ) ) {
[701] Fix | Delete
// Reset the field_ids array.
[702] Fix | Delete
$this->field_ids = array();
[703] Fix | Delete
// For each field left to process...
[704] Fix | Delete
foreach ( $this->fields_by_id as $id => $field ) {
[705] Fix | Delete
// If we've not already processed this field...
[706] Fix | Delete
if ( in_array( $id, $this->form[ 'field_ids' ] ) ) {
[707] Fix | Delete
// Save a reference to its ID.
[708] Fix | Delete
array_push( $this->field_ids, $id );
[709] Fix | Delete
}
[710] Fix | Delete
}
[711] Fix | Delete
}
[712] Fix | Delete
// Store our current data location.
[713] Fix | Delete
$this->form[ 'insert' ] = $this->insert;
[714] Fix | Delete
$this->form[ 'field_ids' ] = $this->field_ids;
[715] Fix | Delete
$this->form[ 'submission_updates' ] = $this->submission_updates;
[716] Fix | Delete
array_push( $this->running[ 0 ][ 'forms' ], $this->form );
[717] Fix | Delete
} else { // Otherwise... (The step is complete.)
[718] Fix | Delete
// Increment our step count.
[719] Fix | Delete
$this->running[ 0 ][ 'current' ] = intval( $this->running[ 0 ][ 'current' ] ) + 1;
[720] Fix | Delete
// Disable maintenance mode on the front end of the site.
[721] Fix | Delete
$this->disable_maintenance_mode( $this->db->prefix, $this->form[ 'ID' ] );
[722] Fix | Delete
}
[723] Fix | Delete
[724] Fix | Delete
// Prepare to output our number of steps and current step.
[725] Fix | Delete
$this->response[ 'stepsTotal' ] = $this->running[ 0 ][ 'steps' ];
[726] Fix | Delete
$this->response[ 'currentStep' ] = $this->running[ 0 ][ 'current' ];
[727] Fix | Delete
[728] Fix | Delete
// If all steps have been completed...
[729] Fix | Delete
if ( empty( $this->running[ 0 ][ 'forms' ] ) ) {
[730] Fix | Delete
// Run our cleanup method.
[731] Fix | Delete
$this->cleanup();
[732] Fix | Delete
}
[733] Fix | Delete
[734] Fix | Delete
// Record our current location in the process.
[735] Fix | Delete
update_option( 'ninja_forms_doing_required_updates', $this->running );
[736] Fix | Delete
// Prepare to output the number of updates remaining.
[737] Fix | Delete
$this->response[ 'updatesRemaining' ] = count( $this->running );
[738] Fix | Delete
}
[739] Fix | Delete
[740] Fix | Delete
}
[741] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function