function getFeedId($cli, MMDB $db, $clusterIdentifier, $typeId) { $sql = sprintf("SELECT na.feed_id FROM mm_feed f INNER JOIN mm_newsletter_application na on na.feed_id = f.id INNER JOIN mm_newsletter_type nt on nt.id = f.newsletter_type_id INNER JOIN mm_application_localized al on al.id = na.application_localized_id WHERE al.cluster_identifier = '%s' AND newsletter_type_id = %d", $clusterIdentifier, $typeId); $rows = $db->arrayQuery($sql); if(!$rows) { $db->beginQuery(); $db->query(sprintf("INSERT INTO mm_feed (newsletter_type_id, cluster_identifier) VALUES (%d, '%s')", $typeId, $clusterIdentifier)); $feedId = $db->lastSerialID("mm_feed"); $db->commitQuery(); $cli->output( "New feed {$feedId}" ); return $feedId; } return $rows[0]["feed_id"]; }