now call HOOK_{create,update,delete}_for_fulcrm_TYPE

master
Marek Isalski 7 years ago
parent 4f7be02ef6
commit ca4ce8afe6

@ -91,12 +91,22 @@ function fulcrm_webhook_createupdate_entity( $data ) {
->condition( 'fulcrm_type', $fulcrm_type ) ->condition( 'fulcrm_type', $fulcrm_type )
->condition( 'fulcrm_pk', $fulcrm_pk ); ->condition( 'fulcrm_pk', $fulcrm_pk );
$found = false;
$result = $query->execute(); $result = $query->execute();
foreach ( $result as $row ) { foreach ( $result as $row ) {
$found = true;
$return = array( 'data' => $data, 'entity' => entity_load( $row->entity_type, array( $row->entity_id ) ) ); $return = array( 'data' => $data, 'entity' => entity_load( $row->entity_type, array( $row->entity_id ) ) );
foreach ( module_implements( 'update_entity_for_fulcrm_' . $fulcrm_type ) as $module ) { foreach ( module_implements( 'update_entity_for_fulcrm_' . $fulcrm_type ) as $module ) {
$function = $module . '_' . 'update_entity_for_fulcrm_' . $fulcrm_type; $function = $module . '_update_entity_for_fulcrm_' . $fulcrm_type;
if ( function_exists( $function ) ) {
$function( $return );
}
}
}
if ( $found ) {
foreach ( module_implements( 'update_for_fulcrm_' . $fulcrm_type ) as $module ) {
$function = $module . '_update_for_fulcrm_' . $fulcrm_type;
if ( function_exists( $function ) ) { if ( function_exists( $function ) ) {
$function( $return ); $function( $return );
} }
@ -104,8 +114,15 @@ function fulcrm_webhook_createupdate_entity( $data ) {
return $return; return $return;
} }
foreach ( module_implements( 'create_for_fulcrm_' . $fulcrm_type ) as $module ) {
$function = $module . '_create_for_fulcrm_' . $fulcrm_type;
if ( function_exists( $function ) ) {
$function( $return );
}
}
foreach ( module_implements( 'create_entity_for_fulcrm_' . $fulcrm_type ) as $module ) { foreach ( module_implements( 'create_entity_for_fulcrm_' . $fulcrm_type ) as $module ) {
$function = $module . '_' . 'create_entity_for_fulcrm_' . $fulcrm_type; $function = $module . '_create_entity_for_fulcrm_' . $fulcrm_type;
if ( function_exists( $function ) ) { if ( function_exists( $function ) ) {
$function( $return ); $function( $return );
@ -116,7 +133,6 @@ function fulcrm_webhook_createupdate_entity( $data ) {
$bundle = array_key_exists( 'bundle', $return ) ? $return[ 'bundle' ] : $return[ 'entity_type' ], $bundle = array_key_exists( 'bundle', $return ) ? $return[ 'bundle' ] : $return[ 'entity_type' ],
$entity_id = $return[ 'entity_id' ] $entity_id = $return[ 'entity_id' ]
); );
return $return;
} }
} }
} }
@ -132,6 +148,8 @@ function fulcrm_webhook_delete_entity( $data ) {
$url = $data[ 'url' ]; $url = $data[ 'url' ];
$fulcrm_type = fulcrm_apiv2_url_to_type( $url ); $fulcrm_type = fulcrm_apiv2_url_to_type( $url );
$fulcrm_pk = fulcrm_apiv2_url_to_pk( $url ); $fulcrm_pk = fulcrm_apiv2_url_to_pk( $url );
$return[ 'fulcrm_type' ] = $fulcrm_type;
$return[ 'fulcrm_pk' ] = $fulcrm_pk;
$query = db_select( 'fulcrm_webhook_entity_mapping', 'fwem' ) $query = db_select( 'fulcrm_webhook_entity_mapping', 'fwem' )
->fields( 'fwem', array( 'entity_type', 'entity_id' ) ) ->fields( 'fwem', array( 'entity_type', 'entity_id' ) )
@ -143,13 +161,20 @@ function fulcrm_webhook_delete_entity( $data ) {
$return[ 'entity' ] = entity_load( $row->entity_type, array( $row->entity_id ) ); $return[ 'entity' ] = entity_load( $row->entity_type, array( $row->entity_id ) );
foreach ( module_implements( 'delete_entity_for_fulcrm_' . $fulcrm_type ) as $module ) { foreach ( module_implements( 'delete_entity_for_fulcrm_' . $fulcrm_type ) as $module ) {
$function = $module . '_' . 'delete_entity_for_fulcrm_' . $fulcrm_type; $function = $module . '_delete_entity_for_fulcrm_' . $fulcrm_type;
if ( function_exists( $function ) ) { if ( function_exists( $function ) ) {
$function( $return ); $function( $return );
} }
} }
} }
foreach ( module_implements( 'delete_for_fulcrm_' . $fulcrm_type ) as $module ) {
$function = $module . '_delete_for_fulcrm_' . $fulcrm_type;
if ( function_exists( $function ) ) {
$function( $return );
}
}
db_delete( 'fulcrm_webhook_entity_mapping', 'fwem' ) db_delete( 'fulcrm_webhook_entity_mapping', 'fwem' )
->condition( 'fulcrm_type', $fulcrm_type ) ->condition( 'fulcrm_type', $fulcrm_type )
->condition( 'fulcrm_pk', $fulcrm_pk ) ->condition( 'fulcrm_pk', $fulcrm_pk )

Loading…
Cancel
Save