protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $this->databaseManager = new sfDatabaseManager($configuration);
     $this->databaseManager->initialize($configuration);
     $db = $this->databaseManager->getDatabase('main');
     $this->db = Doctrine_Manager::connection($db->getParameter('dsn'), 'main');
     $cycle = $options["cycle"];
     //get relationships with fec filings in the cycle
     $sql = "SELECT DISTINCT(f.relationship_id) FROM fec_filing f WHERE f.crp_cycle = ?";
     $stmt = $this->db->execute($sql, array($cycle));
     $rel_ids = $stmt->fetchAll(PDO::FETCH_COLUMN);
     //delete fec filings in the cycle
     $sql = "DELETE FROM fec_filing WHERE crp_cycle = ?";
     $stmt = $this->db->execute($sql, array($cycle));
     foreach ($rel_ids as $rel_id) {
         if (Donation::updateRelationshipFromFecFilings($rel_id)) {
             $this->printDebug("Updated relationship: " . $rel_id);
         } else {
             $this->printDebug("Deleted relationship with no fec filings: " . $rel_id);
         }
     }
 }
 public function cleanupFecFilings($entity_id, $old_donations)
 {
     foreach ($old_donations as $donation) {
         $rel_ids = array();
         $filing_ids = array();
         //get relevant relationships to update and fec filings to delete
         $sql = "SELECT r.id rel_id, f.id filing_id FROM fec_filing f LEFT JOIN relationship r ON (f.relationship_id = r.id) " . "WHERE f.crp_id = ? AND f.crp_cycle = ? AND r.is_deleted = 0 AND (r.entity1_id = ? OR r.entity2_id = ?)";
         $params = array($donation["row_id"], $donation["cycle"], $entity_id, $entity_id);
         $stmt = $this->db->execute($sql, $params);
         $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
         foreach ($rows as $row) {
             $rel_ids[] = $row["rel_id"];
             $filing_ids[] = $row["filing_id"];
         }
         $rel_ids = array_unique($rel_ids);
         $filing_ids = array_unique($filing_ids);
         //delete fec filings if there are any
         if (count($filing_ids) > 0) {
             $sql = "DELETE FROM fec_filing WHERE id IN (" . implode(",", $filing_ids) . ")";
             $this->db->execute($sql);
         }
         //upate relationships
         foreach ($rel_ids as $rel_id) {
             if (Donation::updateRelationshipFromFecFilings($rel_id)) {
                 $this->printDebug("Updated relationship after removing fec filings: " . $rel_id);
             } else {
                 $this->printDebug("- Deleted relationship after removing fec filings: " . $rel_id);
             }
         }
     }
 }