예제 #1
0
파일: File.php 프로젝트: hguru/224Civi
 static function filePostProcess($data, $fileTypeID, $entityTable, $entityID, $entitySubtype, $overwrite = TRUE, $fileParams = NULL, $uploadName = 'uploadFile', $mimeType = null)
 {
     if (!$mimeType) {
         CRM_Core_Error::fatal(ts('Mime Type is now a required parameter'));
     }
     $config = CRM_Core_Config::singleton();
     $path = explode('/', $data);
     $filename = $path[count($path) - 1];
     // rename this file to go into the secure directory
     if ($entitySubtype) {
         $directoryName = $config->customFileUploadDir . $entitySubtype . DIRECTORY_SEPARATOR . $entityID;
     } else {
         $directoryName = $config->customFileUploadDir;
     }
     CRM_Utils_File::createDir($directoryName);
     if (!rename($data, $directoryName . DIRECTORY_SEPARATOR . $filename)) {
         CRM_Core_Error::fatal(ts('Could not move custom file to custom upload directory'));
         break;
     }
     // to get id's
     if ($overwrite && $fileTypeID) {
         list($sql, $params) = self::sql($entityTable, $entityID, $fileTypeID);
     } else {
         list($sql, $params) = self::sql($entityTable, $entityID, 0);
     }
     $dao = CRM_Core_DAO::executeQuery($sql, $params);
     $dao->fetch();
     $fileDAO = new CRM_Core_DAO_File();
     $op = 'create';
     if (isset($dao->cfID) && $dao->cfID) {
         $op = 'edit';
         $fileDAO->id = $dao->cfID;
         unlink($directoryName . DIRECTORY_SEPARATOR . $dao->uri);
     }
     if (!empty($fileParams)) {
         $fileDAO->copyValues($fileParams);
     }
     $fileDAO->uri = $filename;
     $fileDAO->mime_type = $mimeType;
     $fileDAO->file_type_id = $fileTypeID;
     $fileDAO->upload_date = date('Ymdhis');
     $fileDAO->save();
     // need to add/update civicrm_entity_file
     $entityFileDAO = new CRM_Core_DAO_EntityFile();
     if (isset($dao->cefID) && $dao->cefID) {
         $entityFileDAO->id = $dao->cefID;
     }
     $entityFileDAO->entity_table = $entityTable;
     $entityFileDAO->entity_id = $entityID;
     $entityFileDAO->file_id = $fileDAO->id;
     $entityFileDAO->save();
     //save static tags
     if (!empty($fileParams['tag'])) {
         CRM_Core_BAO_EntityTag::create($fileParams['tag'], 'civicrm_file', $entityFileDAO->id);
     }
     //save free tags
     if (isset($fileParams['attachment_taglist']) && !empty($fileParams['attachment_taglist'])) {
         CRM_Core_Form_Tag::postProcess($fileParams['attachment_taglist'], $entityFileDAO->id, 'civicrm_file', CRM_Core_DAO::$_nullObject);
     }
     // lets call the post hook here so attachments code can do the right stuff
     CRM_Utils_Hook::post($op, 'File', $fileDAO->id, $fileDAO);
 }
예제 #2
0
파일: File.php 프로젝트: kidaa30/yes
/**
 * Update an existing File.
 *
 * @param array $params
 *   Array per getfields metadata.
 *
 * @return array
 */
function civicrm_api3_file_update($params)
{
    if (!isset($params['id'])) {
        return civicrm_api3_create_error('Required parameter missing');
    }
    $fileDAO = new CRM_Core_DAO_File();
    $fileDAO->id = $params['id'];
    if ($fileDAO->find(TRUE)) {
        $fileDAO->copyValues($params);
        if (!$params['upload_date'] && !$fileDAO->upload_date) {
            $fileDAO->upload_date = date("Ymd");
        }
        $fileDAO->save();
    }
    $file = array();
    _civicrm_api3_object_to_array(clone $fileDAO, $file);
    return $file;
}
예제 #3
0
 public function filePostProcess($data, $fileID, $entityTable, $entityID, $entitySubtype, $overwrite = TRUE, $fileParams = NULL, $uploadName = 'uploadFile', $mimeType)
 {
     $config = CRM_Core_Config::singleton();
     $path = explode('/', $data);
     $filename = $path[count($path) - 1];
     // rename this file to go into the secure directory
     if ($entitySubtype) {
         $directoryName = $config->customFileUploadDir . $entitySubtype . DIRECTORY_SEPARATOR . $entityID;
     } else {
         $directoryName = $config->customFileUploadDir;
     }
     CRM_Utils_File::createDir($directoryName);
     if (!rename($data, $directoryName . DIRECTORY_SEPARATOR . $filename)) {
         CRM_Core_Error::fatal(ts('Could not move custom file to custom upload directory'));
         break;
     }
     // to get id's
     if ($overwrite && $fileID) {
         list($sql, $params) = self::sql($entityTable, $entityID, $fileID);
     } else {
         list($sql, $params) = self::sql($entityTable, $entityID, 0);
     }
     $dao = CRM_Core_DAO::executeQuery($sql, $params);
     $dao->fetch();
     if (!$mimeType) {
         CRM_Core_Error::fatal();
     }
     $fileDAO = new CRM_Core_DAO_File();
     if (isset($dao->cfID) && $dao->cfID) {
         $fileDAO->id = $dao->cfID;
         unlink($directoryName . DIRECTORY_SEPARATOR . $dao->uri);
     }
     if (!empty($fileParams)) {
         $fileDAO->copyValues($fileParams);
     }
     $fileDAO->uri = $filename;
     $fileDAO->mime_type = $mimeType;
     $fileDAO->file_type_id = $fileID;
     $fileDAO->upload_date = date('Ymdhis');
     $fileDAO->save();
     // need to add/update civicrm_entity_file
     $entityFileDAO = new CRM_Core_DAO_EntityFile();
     if (isset($dao->cefID) && $dao->cefID) {
         $entityFileDAO->id = $dao->cefID;
     }
     $entityFileDAO->entity_table = $entityTable;
     $entityFileDAO->entity_id = $entityID;
     $entityFileDAO->file_id = $fileDAO->id;
     $entityFileDAO->save();
 }
예제 #4
0
/**
 * Update an existing file
 *
 * This api is used for updating an existing file.
 * Required parrmeters : id of a file
 *
 * @param  Array   $params  an associative array of name/value property values of civicrm_file
 *
 * @return array of updated file object property values
 * @access public
 */
function &civicrm_file_update(&$params)
{
    if (!is_array($params)) {
        return civicrm_create_error('Params is not an array');
    }
    if (!isset($params['id'])) {
        return civicrm_create_error('Required parameter missing');
    }
    require_once 'CRM/Core/DAO/File.php';
    $fileDAO = new CRM_Core_DAO_File();
    $fileDAO->id = $params['id'];
    if ($fileDAO->find(TRUE)) {
        $fileDAO->copyValues($params);
        if (!$params['upload_date'] && !$fileDAO->upload_date) {
            $fileDAO->upload_date = date("Ymd");
        }
        $fileDAO->save();
    }
    $file = array();
    _civicrm_object_to_array(clone $fileDAO, $file);
    return $file;
}