"gui", "key_type" => "autoincrement", "name_attcode" => "expiration_date", "state_attcode" => "", "reconc_keys" => array(), "db_table" => "priv_transaction", "db_key_field" => "id", "db_finalclass_field" => "", ); MetaModel::Init_Params($aParams); MetaModel::Init_AddAttribute(new AttributeDateTime("expiration_date", array("allowed_values"=>null, "sql"=>"expiration_date", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); MetaModel::Init_SetZListItems('details', array('expiration_date')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('list', array('expiration_date')); // Attributes to be displayed for a list } /** * Create a new transaction, store it in the database and return its id * @param void * @return int The identifier of the new transaction */ public static function GetNewTransactionId() { // First remove all the expired transactions... self::CleanupExpiredTransactions(); $oTransaction = new privUITransaction(); $sDate = date('Y-m-d H:i:s', time()+TRANSACTION_EXPIRATION_DELAY); $oTransaction->Set('expiration_date', $sDate); // 4 h delay by default $oTransaction->DBInsert(); return sprintf("%d", $oTransaction->GetKey()); } /** * Check whether a transaction is valid or not and remove the valid transaction from * the database so that another call to IsTransactionValid for the same transaction * will return false * @param int $id Identifier of the transaction, as returned by GetNewTransactionId * @return bool True if the transaction is valid, false otherwise */ public static function IsTransactionValid($id) { // First remove all the expired transactions... self::CleanupExpiredTransactions(); // TO DO put a critical section around this part to be 100% safe... // sem_acquire(...) $bResult = false; $oTransaction = MetaModel::GetObject('privUITransaction', $id, false /* MustBeFound */); if ($oTransaction) { $bResult = true; $oTransaction->DBDelete(); } // sem_release(...) return $bResult; } /** * Remove from the database all transactions that have expired */ protected static function CleanupExpiredTransactions() { $sQuery = 'SELECT privUITransaction WHERE expiration_date < NOW()'; $oSearch = DBObjectSearch::FromOQL($sQuery); $oSet = new DBObjectSet($oSearch); while($oTransaction = $oSet->Fetch()) { $oTransaction->DBDelete(); } } } ?>