0 AND gti.local_graph_id = ? ) GROUP BY dtr.local_data_id HAVING graphs = 1', [$a]); $orphans = array_rekey($orphans_results, 'local_data_id', 'local_data_id'); if (cacti_sizeof($orphans)) { cacti_log('Found ' . cacti_sizeof($orphans) . ' orphaned Data Source(s) in Aggregate Graph ' . $a . ' with Local Data IDs of ' . implode(', ', $orphans), false, 'UPGRADE'); db_execute_prepared('DELETE FROM graph_templates_item WHERE local_graph_id = ? AND task_item_id IN( SELECT dtr.id FROM data_template_rrd AS dtr WHERE local_data_id IN (' . implode(', ', $orphans) . ') )', [$a]); } } } }