protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $this->db = Doctrine_Manager::connection();
     if ($options['house_senate'] == 'house') {
         $sql = 'select e1.id,e2.id from entity e1 left join political_candidate pc on pc.entity_id = e1.id left join political_candidate pc2 on pc2.house_fec_id = pc.house_fec_id left join entity e2 on e2.id = pc2.entity_id where e1.is_deleted = 0 and e2.is_deleted = 0 and e1.id <> e2.id and pc.id is not null and pc2.id is not null and pc.id <> pc2.id and pc.house_fec_id is not null and pc.house_fec_id <> "" and e1.id < e2.id group by e1.id,e2.id';
     } else {
         if ($options['house_senate'] == 'senate') {
             $sql = 'select e1.id,e2.id from entity e1 left join political_candidate pc on pc.entity_id = e1.id left join political_candidate pc2 on pc2.senate_fec_id = pc.senate_fec_id left join entity e2 on e2.id = pc2.entity_id where e1.is_deleted = 0 and e2.is_deleted = 0 and e1.id <> e2.id and pc.id is not null and pc2.id is not null and pc.id <> pc2.id and pc.senate_fec_id is not null and pc.senate_fec_id <> "" and e1.id < e2.id group by e1.id,e2.id';
         } else {
             echo 'House or Senate not selected...ending script' . "\n";
             die;
         }
     }
     $stmt = $this->db->execute($sql);
     $rows = $stmt->fetchAll();
     foreach ($rows as $row) {
         $e1 = Doctrine::getTable('Entity')->find($row[0]);
         $e2 = Doctrine::getTable('Entity')->find($row[1]);
         $mergedEntity = EntityTable::mergeAll($e1, $e2);
         $e2->setMerge(true);
         $e2->clearRelated();
         $e2->delete();
         echo '  Successfully merged ' . $e2->name . "\n";
         if ($options['test_mode']) {
             die;
         }
     }
 }
Ejemplo n.º 2
0
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     $entities = LsDoctrineQuery::create()->from('Entity e')->where('CHAR_LENGTH(e.name) = 100')->groupBy('e.name')->execute();
     foreach ($entities as $e) {
         echo $e->id . ' :: ' . $e->name;
         echo "\n";
         $duplicates = LsDoctrineQuery::create()->from('Entity e')->where('e.id != ? and e.name = ?', array($e->id, $e->name))->execute();
         foreach ($duplicates as $e2) {
             $mergedEntity = EntityTable::mergeAll($e, $e2);
             $e2->setMerge(true);
             $e2->clearRelated();
             $e2->delete();
             echo '  Successfully merged ' . $e2->name . "\n";
         }
     }
     /*$id = 0;
       $industry = LsDoctrineQuery::create()
                                 ->from('Industry i')
                                 ->where('id > ?',$id)
                                 ->fetchOne();
       while ($industry)
       {
         $matches = LsDoctrineQuery::create()
                                     ->from('Industry i')
                                     ->where('i.name = ? and i.id != ?', array($industry->name,$industry->id))
                                     ->execute();
         echo $matches->count() . '...';
         foreach($matches as $match)
         {
           $bis = LsDoctrineQuery::create()
                                     ->from('BusinessIndustry bi')
                                     ->where('bi.industry_id = ?', $match->id)
                                     ->execute();
           foreach($bis as $b)
           {
             $b->industry_id = $industry->id;
             $b->save();
             $match->delete();
           }
           
         }
         $id = $industry->id;
         $industry = LsDoctrineQuery::create()
                                 ->from('Industry i')
                                 ->where('id > ?',$id)
                                 ->fetchOne();
       }
       
       $images = LsQuery::getByModelAndFieldsQuery('Image',array('caption' => 'Array'));
       foreach($images as $image)
       {
         $image->caption = 'From the Biographical Directory of the United States Congress';
         $image->save();
       }*/
 }
Ejemplo n.º 3
0
 protected function merge($sql, $ask_user = true)
 {
     $stmt = $this->db->execute($sql);
     $rows = $stmt->fetchAll();
     foreach ($rows as $row) {
         $e1 = Doctrine::getTable('Entity')->find($row[0]);
         $e2 = Doctrine::getTable('Entity')->find($row[1]);
         $response = 'y';
         if ($ask_user) {
             $prompt = "\n\n*********\n\nDo you want to merge these entities?\n";
             $prompt .= $this->getEntityString($e1) . "\n**********\n" . $this->getEntityString($e2);
             $response = $this->readline($prompt);
         }
         if ($response == 'y') {
             $mergedEntity = EntityTable::mergeAll($e1, $e2);
             $e2->setMerge(true);
             $e2->clearRelated();
             $e2->delete();
             echo '  Successfully merged ' . $e2->name . "\n";
         }
     }
 }
 protected function matchInDatabase($member)
 {
     $match = LsDoctrineQuery::create()->from('Entity e')->leftJoin('e.PoliticalCandidate pc')->where('(pc.house_fec_id = ? and pc.house_fec_id is not null and pc.house_fec_id <> ?) or (pc.senate_fec_id = ? and pc.senate_fec_id is not null and pc.senate_fec_id <> ?) or (pc.pres_fec_id is not null and pc.pres_fec_id = ? and pc.pres_fec_id <> ?)', array($member->house_fec_id, "", $member->senate_fec_id, "", $member->pres_fec_id, ""))->fetchOne();
     /*
         if (!$match)
         {
           $matches = EntityTable::getByExtensionQuery('Person')
           ->addWhere('person.name_last = ? AND person.name_first LIKE CONCAT(?, \'%\')', array($member->name_last, substr($member->name_first, 0, 1)))
           ->execute();
     
           foreach ($matches as $m)
           {
             if (PersonTable::areSame($member, $m))
             {
               $le = new LsListEntity;
               $le->entity_id = $member->id;
               $le->list_id = $this->_duplicateListId;
               $le->save();
               break;
             }    
           }
         }*/
     if ($match) {
         //merge entities
         $this->printDebug("\n\n\t\t\tMERGING MERGING\n\n");
         $this->printDebug("Member found in database with name " . $match->name . " and entity ID " . $match->id);
         $merged_member = EntityTable::mergeAll($match, $member);
         //reassign relationships created during import
         $relVarNames = array('senate', 'house', 'school', 'committee');
         foreach ($relVarNames as $relVarName) {
             $fullRelVarName = '_' . $relVarName . 'Relationships';
             foreach ($this->{$fullRelVarName} as $rel) {
                 $rel->Entity1 = $merged_member;
             }
         }
         foreach ($this->_officeStafferRelationships as $rel) {
             $rel->Entity2 = $merged_member;
         }
         return $merged_member;
     }
     return $member;
 }
Ejemplo n.º 5
0
 public function executeMerge($request)
 {
     $this->checkEntity($request, false, false);
     //user has clicked the merge buttom
     if ($request->isMethod('post')) {
         $entityToKeep = Doctrine::getTable('Entity')->find($request->getParameter('keep_id'));
         $this->forward404Unless($entityToKeep);
         //get related entities for cache clearing
         $relatedEntities = EntityApi::getRelated($this->entity['id']);
         $mergedEntity = EntityTable::mergeAll($entityToKeep, $this->entity);
         $this->entity->setMerge(true);
         //clear relations so merged relations aren't deleted
         $this->entity->clearRelated();
         $this->entity->delete();
         $this->clearCache($this->entity);
         $this->clearCache($mergedEntity);
         foreach (array_keys($relatedEntities) as $relatedId) {
             LsCache::clearEntityCacheById($relatedId);
         }
         $this->getUser()->setFlash('alert', 'Succesfully merged.');
         $this->redirect($mergedEntity->getInternalUrl());
     }
     $this->similar_entities = $this->entity->getSimilarEntitiesQuery($looseMatch = true)->execute();
     if ($request->hasParameter('q')) {
         $num = $request->getParameter('num', 10);
         $page = $request->getParameter('page', 1);
         //form submission, display matching persons
         if (!($terms = $request->getParameter('q'))) {
             $this->match_pager = new LsDoctrinePager(array(), $page, $num);
         } else {
             switch (sfConfig::get('app_search_engine')) {
                 case 'sphinx':
                     $this->match_pager = EntityTable::getSphinxPager($terms, $page, $num);
                     break;
                 case 'lucene':
                     $ary = EntityTable::getLuceneArray($terms, null);
                     $this->match_pager = new LsDoctrinePager($ary, $page, $num);
                     break;
                 case 'mysql':
                 default:
                     $terms = explode(' ', $terms);
                     $q = EntityTable::getSimpleSearchQuery($terms);
                     $this->match_pager = new Doctrine_Pager($q, $page, $num);
                     break;
             }
         }
     }
 }