/** * A static function wrapper that deletes the various objects that are * connected to a file object (i.e. file, entityFile and customValue */ public static function deleteFileReferences($fileID, $entityID, $fieldID) { $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $fileID; if (!$fileDAO->find(TRUE)) { CRM_Core_Error::fatal(); } // lets call a pre hook before the delete, so attachments hooks can get the info before things // disappear CRM_Utils_Hook::pre('delete', 'File', $fileID, $fileDAO); // 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)) { CRM_Core_Error::fatal(); } $entityFileDAO->delete(); $fileDAO->delete(); // 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); }
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.'); }
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); }
/** * 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')); } } }
/** * Deletes an existing entity file assignment. * Required parameters : 1. id of an entity-file * 2. entity_id and entity_table of an entity-file * * @param array $params an associative array of name/value property values of civicrm_entity_file. * * @return null if successfull, object of CRM_Core_Error otherwise * @access public */ function civicrm_entity_file_delete(&$params) { require_once 'CRM/Core/DAO/EntityFile.php'; //if ( ! isset($params['id']) && ( !isset($params['entity_id']) || !isset($params['entity_file']) ) ) { if (!isset($params['id']) && (!isset($params['entity_id']) || !isset($params['entity_table']))) { return civicrm_create_error('Required parameters missing'); } $entityFileDAO = new CRM_Core_DAO_EntityFile(); $properties = array('id', 'entity_id', 'entity_table', 'file_id'); foreach ($properties as $name) { if (array_key_exists($name, $params)) { $entityFileDAO->{$name} = $params[$name]; } } return $entityFileDAO->delete() ? NULL : civicrm_create_error('Error while deleting'); }