/**
  * If any src_org is deleted, the entire cache for that source needs to
  * be refreshed.
  *
  * @param Doctrine_Event $event
  */
 public function postDelete($event)
 {
     parent::postDelete($event);
     SrcOrgCache::refresh_cache($this->Source);
     $this->Source->set_and_save_src_status();
 }
 /**
  * Create/update src_orgs for a Source.  Also forces a source to be
  * opted-into APMG.
  *
  * @param Source  $src
  */
 public function process_orgs(Source $src)
 {
     $has_apmg_org = false;
     $processed = 0;
     foreach ($this->TankOrg as $to) {
         $to->process_source($src);
         $processed++;
     }
     $processed += SrcOrg::force_apmg($src->src_id);
     if ($processed > 0) {
         SrcOrgCache::refresh_cache($src);
     }
 }
 /**
  * Combine src_orgs for the sources, picking the highest level of opt-in
  * for any conflicting orgs.
  *
  * @param Source  $prime the record to merge into (will be preserved)
  * @param Source  $merge the record to merge from (will be deleted)
  */
 protected static function combine_orgs($prime, $merge)
 {
     // priority of src_org status
     $priority = array(SrcOrg::$STATUS_OPTED_IN => 4, SrcOrg::$STATUS_EDITORIAL_DEACTV => 3, SrcOrg::$STATUS_OPTED_OUT => 2, SrcOrg::$STATUS_DELETED => 1);
     // index by org_id
     $prime_orgs = array();
     foreach ($prime->SrcOrg as $so) {
         $prime_orgs[$so->so_org_id] = $so;
     }
     // add/update from merge
     foreach ($merge->SrcOrg as $so) {
         $orgid = $so->so_org_id;
         $stat = $so->so_status;
         // update or insert
         if (isset($prime_orgs[$orgid])) {
             $current = $prime_orgs[$orgid]->so_status;
             if ($priority[$stat] > $priority[$current]) {
                 $prime_orgs[$orgid]->so_status = $stat;
                 $prime_orgs[$orgid]->save();
             }
             if (!isset(self::$MERGE_RESULT['skipped']['SrcOrg'])) {
                 self::$MERGE_RESULT['skipped']['SrcOrg'] = 1;
             } else {
                 self::$MERGE_RESULT['skipped']['SrcOrg']++;
             }
         } else {
             $so->so_src_id = $prime->src_id;
             $so->save();
             if (!isset(self::$MERGE_RESULT['moved']['SrcOrg'])) {
                 self::$MERGE_RESULT['moved']['SrcOrg'] = 1;
             } else {
                 self::$MERGE_RESULT['moved']['SrcOrg']++;
             }
         }
     }
     // clear loaded
     $prime->clearRelated('SrcOrg');
     $merge->clearRelated('SrcOrg');
     // recalculate prime SrcOrgCache
     SrcOrgCache::refresh_cache($prime->src_id);
 }