Update of /cvsroot/mantisbt/mantisbt/core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3232/core
Modified Files:
tokens_api.php
Log Message:
Fixed some standard issues + new lines.
Index: tokens_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/tokens_api.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- tokens_api.php 11 Dec 2004 20:12:00 -0000 1.1
+++ tokens_api.php 12 Dec 2004 00:30:44 -0000 1.2
@@ -9,9 +9,11 @@
# $Id$
# --------------------------------------------------------
+ ### TOKENS API ###
+
# This implements temporary storage of strings.
# DB schema: id, type, owner, timestamp, value
-
+
# TODO
# 1. add constant for user token types TOKEN_USER. users can define
token_my_type = token_user, token_other = token_user + 1 etc
# TOKEN_USER = 1000
@@ -23,9 +25,9 @@
# 7. add an 'expiry' param to token_add
# 8. rework ts_purge_expired not to be called on every get. Maybe call
it if token is found to be expired.
# 9. return 'default param' from token_add is token not found
-
- function token_ensure_owner( $p_token_id, $p_owner_id )
- {
+
+ # --------------------
+ function token_ensure_owner( $p_token_id, $p_owner_id ) {
$c_token_id = db_prepare_int( $p_token_id );
$t_tokens_table = config_get( 'mantis_tokens_table' );
@@ -36,18 +38,17 @@
if( db_result( $result ) != $p_owner_id ) {
trigger_error( ERROR_GENERIC, ERROR );
- }
-
+ }
+
return true;
}
-
- function token_touch( $p_token_id, $p_expiry_delay )
- {
+ # --------------------
+ function token_touch( $p_token_id, $p_expiry_delay ) {
}
- function token_delete_by_owner( $p_owner_owner )
- {
+ # --------------------
+ function token_delete_by_owner( $p_owner_owner ) {
$c_token_owner = db_prepare_int( $p_token_owner );
$t_tokens_table = config_get( 'mantis_tokens_table' );
@@ -57,11 +58,11 @@
WHERE owner='$c_token_owner'";
db_query( $query );
- return true;
+ return true;
}
- function token_delete_by_type( $p_token_type )
- {
+ # --------------------
+ function token_delete_by_type( $p_token_type ) {
$c_token_type = db_prepare_int( $p_token_type );
$t_tokens_table = config_get( 'mantis_tokens_table' );
@@ -73,9 +74,9 @@
return true;
}
-
- function token_exists( $p_token_id )
- {
+
+ # --------------------
+ function token_exists( $p_token_id ) {
$c_token_id = db_prepare_int( $p_token_id );
$t_tokens_table = config_get( 'mantis_tokens_table' );
@@ -86,88 +87,41 @@
return( 1 == db_result( $result ) );
}
-
- function token_ensure_exists( $p_token_id )
- {
+
+ # --------------------
+ function token_ensure_exists( $p_token_id ) {
if ( !token_exists( $p_token_id ) ) {
trigger_error( ERROR_GENERIC, ERROR );
}
-
+
return true;
}
- function token_add( $p_token_value, $p_token_type = TOKEN_UNKNOWN,
$p_token_owner = null )
- {
+ # --------------------
+ function token_add( $p_token_value, $p_token_type = TOKEN_UNKNOWN,
$p_token_owner = null ) {
$c_token_type = db_prepare_int( $p_token_type );
$c_token_value = db_prepare_string ( $p_token_value );
-
- if( $p_token_owner == null ) {
- $c_token_owner = auth_get_current_user_id();
- } else {
- $c_token_owner = db_prepare_int( $p_token_owner );
- }
-
+
+ if( $p_token_owner == null ) {
$c_token_owner = auth_get_current_user_id();
} else {
$c_token_owner = db_prepare_int( $p_token_owner );
}
$t_tokens_table = config_get( 'mantis_tokens_table' );
-
- # insert
- $query = "INSERT INTO $t_tokens_table
- ( type, owner, timestamp, value )
- VALUES
- ( $c_token_type, $c_token_owner, " .
db_now(). ",'$c_token_value' )";
+ # insert
$query = "INSERT INTO $t_tokens_table
( type, owner, timestamp, value )
VALUES
( $c_token_type, $c_token_owner, " .
db_now(). ",'$c_token_value' )";
db_query( $query );
-
- return db_insert_id( $t_tokens_table );
- }
-
- # This method does not generate an error if the token does not exist,
- # e.g. if we try to delete an expired token
- function token_delete( $p_token_id )
- {
- $c_token_id = db_prepare_int( $p_token_id );
-
- $t_tokens_table = config_get( 'mantis_tokens_table' );
-
- # Remove
- $query = "DELETE FROM $t_tokens_table
- WHERE id='$c_token_id'";
- db_query( $query, 1 );
-
- return true;
- }
-
- function token_get_value( $p_token_id )
- {
- $c_token_id = db_prepare_int( $p_token_id );
- $c_token_owner = auth_get_current_user_id();
-
+ return db_insert_id( $t_tokens_table );
}
+ # --------------------
+ # This method does not generate an error if the token does not exist,
# e.g. if we try to delete an expired token
function token_delete( $p_token_id ) {
$c_token_id = db_prepare_int( $p_token_id );
$t_tokens_table = config_get( 'mantis_tokens_table' );
+ # Remove
$query = "DELETE FROM $t_tokens_table
WHERE id='$c_token_id'";
db_query( $query, 1 );
+ return true;
}
+ # --------------------
+ function token_get_value( $p_token_id ) {
$c_token_id = db_prepare_int( $p_token_id );
$c_token_owner = auth_get_current_user_id();
$t_tokens_table = config_get( 'mantis_tokens_table' );
-
token_purge_expired();
token_ensure_owner( $c_token_id, $c_token_owner ) ;
-
- $query = "SELECT value
- FROM $t_tokens_table
- WHERE id='$c_token_id'";
+ $query = "SELECT value
FROM $t_tokens_table
WHERE id='$c_token_id'";
$result = db_query( $query );
-
- return db_result( $result );
- }
-
- function token_purge_expired( $p_token_type = NULL )
- {
-
- $t_tokens_table = config_get( 'mantis_tokens_table' );
-
- # Remove
- $query = "DELETE FROM $t_tokens_table WHERE ";
- if ( !is_null( $p_token_type ) ) {
- $c_token_type = db_prepare_int( $p_token_type );
- $query .= " type='$c_token_type' AND ";
- }
- $query .= db_helper_compare_days( db_now(), 'timestamp', ">=
'1'" );
+ return db_result( $result );
}
+ # --------------------
+ function token_purge_expired( $p_token_type = NULL ) {
$t_tokens_table = config_get( 'mantis_tokens_table' );
+ # Remove
$query = "DELETE FROM $t_tokens_table WHERE ";
if ( !is_null( $p_token_type ) ) {
$c_token_type = db_prepare_int( $p_token_type );
$query .= " type='$c_token_type' AND ";
}
+ $query .= db_helper_compare_days( db_now(), 'timestamp', ">=
'1'" );
db_query( $query );
-
- return true;
- }
-
-?>
\ No newline at end of file
+ return true;
}
?>
\ No newline at end of file
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
|