public function delete($useWhere = FALSE) { list($fileID, $entityID, $fieldID) = func_get_args(); // get the table and column name list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID); $entityFileDAO = new CRM_Core_DAO_EntityFile(); $entityFileDAO->file_id = $fileID; $entityFileDAO->entity_id = $entityID; $entityFileDAO->entity_table = $tableName; if ($entityFileDAO->find(TRUE)) { $entityFileDAO->delete(); } else { CRM_Core_Error::fatal(); } $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $fileID; if ($fileDAO->find(TRUE)) { $fileDAO->delete(); } else { CRM_Core_Error::fatal(); } // also set the value to null of the table and column $query = "UPDATE {$tableName} SET {$columnName} = null WHERE {$columnName} = %1"; $params = array(1 => array($fileID, 'Integer')); CRM_Core_DAO::executeQuery($query, $params); }
/** * Delete an existing File. * * @param array $params * Array per getfields metadata. * * @return array * API result array */ function civicrm_api3_file_delete($params) { civicrm_api3_verify_mandatory($params, NULL, array('id')); $check = FALSE; $entityFileDAO = new CRM_Core_DAO_EntityFile(); $entityFileDAO->file_id = $params['id']; if ($entityFileDAO->find()) { $check = $entityFileDAO->delete(); } $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $params['id']; if ($fileDAO->find(TRUE)) { $check = $fileDAO->delete(); } return $check ? NULL : civicrm_api3_create_error('Error while deleting a file.'); }
/** * Process the form submission. */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_BAO_MessageTemplate::del($this->_id); } elseif ($this->_action & CRM_Core_Action::VIEW) { // currently, the above action is used solely for previewing default workflow templates CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1')); } else { $params = array(); // store the submitted values in an array $params = $this->controller->exportValues($this->_name); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } if (!empty($params['file_type'])) { unset($params['msg_html']); unset($params['msg_text']); CRM_Utils_File::formatFile($params, 'file_id'); } elseif (!empty($this->_id)) { $entityFileDAO = new CRM_Core_DAO_EntityFile(); $entityFileDAO->entity_id = $this->_id; $entityFileDAO->entity_table = 'civicrm_msg_template'; if ($entityFileDAO->find(TRUE)) { $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $entityFileDAO->file_id; $fileDAO->find(TRUE); $entityFileDAO->delete(); $fileDAO->delete(); } } if ($this->_workflow_id) { $params['workflow_id'] = $this->_workflow_id; $params['is_active'] = TRUE; } $messageTemplate = CRM_Core_BAO_MessageTemplate::add($params); CRM_Core_Session::setStatus(ts('The Message Template \'%1\' has been saved.', array(1 => $messageTemplate->msg_title)), ts('Saved'), 'success'); if ($this->_workflow_id) { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1')); } else { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1')); } } }
public function delete($fileID, $entityID, $fieldID) { // get the table and column name require_once 'CRM/Core/BAO/CustomField.php'; list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID); require_once "CRM/Core/DAO/EntityFile.php"; $entityFileDAO = new CRM_Core_DAO_EntityFile(); $entityFileDAO->file_id = $fileID; $entityFileDAO->entity_id = $entityID; $entityFileDAO->entity_table = $tableName; if ($entityFileDAO->find(true)) { $entityFileDAO->delete(); } else { CRM_Core_Error::fatal(); } require_once "CRM/Core/DAO/File.php"; $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $fileID; if ($fileDAO->find(true)) { $fileDAO->delete(); } else { CRM_Core_Error::fatal(); } // also set the value to null of the table and column $query = "UPDATE {$tableName} SET {$columnName} = null WHERE {$columnName} = %1"; $params = array(1 => array($fileID, 'Integer')); CRM_Core_DAO::executeQuery($query, $params); }
/** * Deletes an existing file * * This API is used for deleting a file * Required parameters : id of a file * * @param Int $fileId Id of the file to be deleted * * @return null if successfull, object of CRM_Core_Error otherwise * @access public */ function &civicrm_file_delete($fileId) { if (empty($fileId)) { return civicrm_create_error('Required parameter missing'); } $check = FALSE; require_once 'CRM/Core/DAO/EntityFile.php'; $entityFileDAO = new CRM_Core_DAO_EntityFile(); $entityFileDAO->file_id = $fileId; if ($entityFileDAO->find()) { $check = $entityFileDAO->delete(); } require_once 'CRM/Core/DAO/File.php'; $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $fileId; if ($fileDAO->find(TRUE)) { $check = $fileDAO->delete(); } return $check ? NULL : civicrm_create_error('Error while deleting a file.'); }