Merge pull request #11746 from woothemes/crud-meta-id

Swaps meta_id for id across crud and api
This commit is contained in:
Claudio Sanches 2016-08-22 16:43:57 -03:00 committed by GitHub
commit 0da91bb7d7
6 changed files with 31 additions and 31 deletions

View File

@ -163,11 +163,11 @@ abstract class WC_Data {
if ( ! empty( $data ) && is_array( $data ) ) {
foreach ( $data as $meta ) {
$meta = (array) $meta;
if ( isset( $meta['key'], $meta['value'], $meta['meta_id'] ) ) {
if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
$this->_meta_data[] = (object) array(
'key' => $meta['key'],
'value' => $meta['value'],
'meta_id' => $meta['meta_id'],
'key' => $meta['key'],
'value' => $meta['value'],
'id' => $meta['id'],
);
}
}
@ -202,13 +202,13 @@ abstract class WC_Data {
public function update_meta_data( $key, $value, $meta_id = '' ) {
$array_key = '';
if ( $meta_id ) {
$array_key = array_keys( wp_list_pluck( $this->_meta_data, 'meta_id' ), $meta_id );
$array_key = array_keys( wp_list_pluck( $this->_meta_data, 'id' ), $meta_id );
}
if ( $array_key ) {
$this->_meta_data[ current( $array_key ) ] = (object) array(
'key' => $key,
'value' => $value,
'meta_id' => $meta_id,
'key' => $key,
'value' => $value,
'id' => $meta_id,
);
} else {
$this->add_meta_data( $key, $value, true );
@ -231,7 +231,7 @@ abstract class WC_Data {
* @param int $mid Meta ID
*/
public function delete_meta_data_by_mid( $mid ) {
$array_keys = array_keys( wp_list_pluck( $this->_meta_data, 'meta_id' ), $mid );
$array_keys = array_keys( wp_list_pluck( $this->_meta_data, 'id' ), $mid );
$this->_meta_data = array_diff_key( $this->_meta_data, array_fill_keys( $array_keys, '' ) );
}
@ -272,9 +272,9 @@ abstract class WC_Data {
continue;
}
$this->_meta_data[] = (object) array(
'key' => $meta->meta_key,
'value' => maybe_unserialize( $meta->meta_value ),
'meta_id' => $meta->{ $db_info['meta_id_field'] },
'key' => $meta->meta_key,
'value' => maybe_unserialize( $meta->meta_value ),
'id' => $meta->{ $db_info['meta_id_field'] },
);
}
}
@ -301,13 +301,13 @@ abstract class WC_Data {
$set_meta_ids = array();
foreach ( $this->_meta_data as $array_key => $meta ) {
if ( empty( $meta->meta_id ) ) {
if ( empty( $meta->id ) ) {
$new_meta_id = add_metadata( $this->_meta_type, $this->get_id(), $meta->key, $meta->value, false );
$set_meta_ids[] = $new_meta_id;
$this->_meta_data[ $array_key ]->meta_id = $new_meta_id;
$this->_meta_data[ $array_key ]->id = $new_meta_id;
} else {
update_metadata_by_mid( $this->_meta_type, $meta->meta_id, $meta->value, $meta->key );
$set_meta_ids[] = absint( $meta->meta_id );
update_metadata_by_mid( $this->_meta_type, $meta->id, $meta->value, $meta->key );
$set_meta_ids[] = absint( $meta->id );
}
}

View File

@ -548,7 +548,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
$item_meta_array = array();
foreach ( $meta_data as $meta ) {
$item_meta_array[ $meta->meta_id ] = $meta;
$item_meta_array[ $meta->id ] = $meta;
}
return $item_meta_array;

View File

@ -344,7 +344,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'meta_id' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
@ -448,7 +448,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'meta_id' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),

View File

@ -365,7 +365,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
case 'meta_data' :
if ( is_array( $value ) ) {
foreach ( $value as $meta ) {
$order->update_meta_data( $meta['key'], $meta['value'], $meta['meta_id'] );
$order->update_meta_data( $meta['key'], $meta['value'], $meta['id'] );
}
}
break;
@ -1071,7 +1071,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'meta_id' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
@ -1175,7 +1175,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'meta_id' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
@ -1286,7 +1286,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'meta_id' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
@ -1363,7 +1363,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'meta_id' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
@ -1452,7 +1452,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'meta_id' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
@ -1504,7 +1504,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'meta_id' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),

View File

@ -311,7 +311,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
}
}
$formatted_meta[ $meta->meta_id ] = (object) array(
$formatted_meta[ $meta->id ] = (object) array(
'key' => $meta->key,
'value' => $meta->value,
'display_key' => apply_filters( 'woocommerce_order_item_display_meta_key', $display_key ),
@ -390,7 +390,7 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
$return = array();
foreach ( $this->_meta_data as $meta ) {
$return[ $meta->meta_id ] = $meta;
$return[ $meta->id ] = $meta;
}
return $return;

View File

@ -94,9 +94,9 @@ class WC_Tests_CRUD_Meta extends WC_Unit_Test_Case {
foreach ( $raw_metadata as $meta ) {
$metadata[] = (object) array(
'key' => $meta->meta_key,
'value' => $meta->meta_value,
'meta_id' => $meta->meta_id,
'key' => $meta->meta_key,
'value' => $meta->meta_value,
'id' => $meta->meta_id,
);
}