table_name WHERE assigned_user_id = '$user_id'"; $this->db->query($query,true,"Error marking last imported records deleted: "); } /** * Undo a single record * * @param string $id specific users_last_import id to undo */ public function undoById($id) { global $current_user; $query1 = "SELECT bean_id, bean_type FROM users_last_import WHERE assigned_user_id = '$current_user->id' AND id = '$id' AND deleted=0"; $result1 = $this->db->query($query1); if ( !$result1 ) return false; while ( $row1 = $this->db->fetchByAssoc($result1)) $this->_deleteRecord($row1['bean_id'],$row1['bean_type']); return true; } /** * Undo an import * * @param string $module module being imported into */ public function undo($module) { global $current_user; $query1 = "SELECT bean_id, bean_type FROM users_last_import WHERE assigned_user_id = '$current_user->id' AND import_module = '$module' AND deleted=0"; $result1 = $this->db->query($query1); if ( !$result1 ) return false; while ( $row1 = $this->db->fetchByAssoc($result1)) $this->_deleteRecord($row1['bean_id'],$row1['bean_type']); return true; } /** * Deletes a record in a bean * * @param $bean_id * @param $module */ protected function _deleteRecord($bean_id,$module) { static $focus; // load bean if ( !( $focus instanceof $module) ) { require_once($GLOBALS['beanFiles'][$module]); $focus = new $module; } $result = $this->db->query( "DELETE FROM {$focus->table_name} WHERE id = '{$bean_id}'" ); if (!$result) return false; // Bug 26318: Remove all created e-mail addresses ( from jchi ) $result2 = $this->db->query( "SELECT email_address_id FROM email_addr_bean_rel WHERE email_addr_bean_rel.bean_id='{$bean_id}' AND email_addr_bean_rel.bean_module='{$focus->module_dir}'"); $this->db->query( "DELETE FROM email_addr_bean_rel WHERE email_addr_bean_rel.bean_id='{$bean_id}' AND email_addr_bean_rel.bean_module='{$focus->module_dir}'" ); while ( $row2 = $this->db->fetchByAssoc($result2)) { if ( !$this->db->getOne( "SELECT email_address_id FROM email_addr_bean_rel WHERE email_address_id = '{$row2['email_address_id']}'") ) $this->db->query( "DELETE FROM email_addresses WHERE id = '{$row2['email_address_id']}'"); } if ($focus->hasCustomFields()) $this->db->query( "DELETE FROM {$focus->table_name}_cstm WHERE id_c = '{$bean_id}'"); } /** * Get a list of bean types created in the import * * @param string $module module being imported into */ public static function getBeansByImport($module) { global $current_user; $query1 = "SELECT DISTINCT bean_type FROM users_last_import WHERE assigned_user_id = '$current_user->id' AND import_module = '$module' AND deleted=0"; $result1 = $GLOBALS['db']->query($query1); if ( !$result1 ) return array($module); $returnarray = array(); while ( $row1 = $GLOBALS['db']->fetchByAssoc($result1)) $returnarray[] = $row1['bean_type']; return $returnarray; } } ?>