Exemplo n.º 1
0
 /**
  * @param CRM_Core_DAO $dao
  * @param $xml
  * @param bool $save
  * @param null $keyName
  *
  * @return bool
  */
 public function copyData(&$dao, &$xml, $save = FALSE, $keyName = NULL)
 {
     if ($keyName) {
         if (isset($xml->{$keyName})) {
             $dao->{$keyName} = (string) $xml->{$keyName};
             if ($dao->find(TRUE)) {
                 CRM_Core_Session::setStatus(ts("Found %1, %2, %3", array(1 => $keyName, 2 => $dao->{$keyName}, 3 => $dao->__table)), '', 'info');
                 return FALSE;
             }
         }
     }
     $fields =& $dao->fields();
     foreach ($fields as $name => $dontCare) {
         if (isset($xml->{$name})) {
             $value = (string) $xml->{$name};
             $value = str_replace(CRM_Utils_Migrate_Export::XML_VALUE_SEPARATOR, CRM_Core_DAO::VALUE_SEPARATOR, $value);
             $dao->{$name} = $value;
         }
     }
     if ($save) {
         $dao->save();
     }
     return TRUE;
 }