/**
  * Set or update the category of the mailing.
  *
  * A mailing category is simply a mailing group of type 'Mailing Category', in addition to being of type 'Mailing
  * List'.
  *
  * A mailing can only ever be associated with one category (i.e. mailing group of type 'Mailing Category')
  *
  * @param $params
  *
  * @return $this
  */
 protected static function setMailingCategory($params)
 {
     if (!empty($params['category_id'])) {
         $group = new CRM_Mailing_DAO_MailingGroup();
         $group->reset();
         $group->selectAdd('*');
         $group->mailing_id = $params['crm_mailing_id'];
         $group->group_type = static::MAILING_GROUP_TYPE_BASE;
         $group->entity_table = 'civicrm_group';
         if ($group->find(TRUE)) {
             $group->entity_id = $params['category_id'];
             return $group->save();
         }
         $group->entity_id = $params['category_id'];
         return $group->save();
     }
 }