Code Duplication    Length = 17-20 lines in 2 locations

caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 location

@@ 279-295 (lines=17) @@
276
277
		if ( is_array( $old_datetimes ) ) {
278
			$dtts_to_delete = array_diff( $old_datetimes, $saved_dtt_ids );
279
			foreach ( $dtts_to_delete as $id ) {
280
				$id = absint( $id );
281
				if ( empty( $id ) )
282
					continue;
283
284
				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
285
286
				//remove tkt relationships.
287
				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
288
				foreach ( $related_tickets as $tkt ) {
289
					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
290
				}
291
292
				$evt_obj->_remove_relation_to( $id, 'Datetime' );
293
				$dtt_to_remove->refresh_cache_of_related_objects();
294
295
			}
296
		}
297
298
		return $saved_dtt_objs;

admin_pages/events/Events_Admin_Page.core.php 1 location

@@ 1143-1162 (lines=20) @@
1140
		$old_tickets = isset( $old_tickets[0] ) && $old_tickets[0] == '' ? array() : $old_tickets;
1141
		$tickets_removed = array_diff( $old_tickets, array_keys( $saved_tickets ) );
1142
1143
		foreach ( $tickets_removed as $id ) {
1144
			$id = absint( $id );
1145
1146
			//get the ticket for this id
1147
			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1148
1149
			//need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1150
			$dtts = $tkt_to_remove->get_many_related('Datetime');
1151
1152
			foreach( $dtts as $dtt ) {
1153
				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1154
			}
1155
1156
			//need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1157
			$tkt_to_remove->delete_related_permanently('Price');
1158
1159
1160
			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1161
			$tkt_to_remove->delete_permanently();
1162
		}
1163
		return array( $saved_dtt, $saved_tickets );
1164
	}
1165