コード例 #1
0
 /**
  * Revert a message template to its default subject+text+HTML state.
  *
  * @param int $id id of the template
  */
 public static function revert($id)
 {
     $diverted = new CRM_Core_BAO_MessageTemplate();
     $diverted->id = (int) $id;
     $diverted->find(1);
     if ($diverted->N != 1) {
         CRM_Core_Error::fatal(ts('Did not find a message template with id of %1.', array(1 => $id)));
     }
     $orig = new CRM_Core_BAO_MessageTemplate();
     $orig->workflow_id = $diverted->workflow_id;
     $orig->is_reserved = 1;
     $orig->find(1);
     if ($orig->N != 1) {
         CRM_Core_Error::fatal(ts('Message template with id of %1 does not have a default to revert to.', array(1 => $id)));
     }
     $diverted->msg_subject = $orig->msg_subject;
     $diverted->msg_text = $orig->msg_text;
     $diverted->msg_html = $orig->msg_html;
     $diverted->pdf_format_id = is_null($orig->pdf_format_id) ? 'null' : $orig->pdf_format_id;
     $diverted->save();
 }