$sOperation, 'temp_id' => $sTempId, 'expiration_date' => time() + TemporaryObjectConfig::GetInstance()->GetConfigTemporaryLifetime(), 'item_class' => $sObjectClass, 'item_id' => $sObjectKey, ]); $oTemporaryObjectDescriptor->DBInsert(); return $oTemporaryObjectDescriptor; } catch (Exception $e) { ExceptionLog::LogException($e); return null; } } /** * SearchByTempId. * * @param string $sTempId temporary id * @param bool $bReverseOrder reverse order of result * * @return \DBObjectSet * @throws \MySQLException * @throws \OQLException */ public function SearchByTempId(string $sTempId, bool $bReverseOrder = false): DBObjectSet { // Prepare OQL $sOQL = sprintf('SELECT `%s` WHERE temp_id=:temp_id', TemporaryObjectDescriptor::class); // Create db search $oDbObjectSearch = DBSearch::FromOQL($sOQL); // Create db set from db search $oDbObjectSet = new DBObjectSet($oDbObjectSearch, [], [ 'temp_id' => $sTempId, ]); // Reverse order if ($bReverseOrder) { $oDbObjectSet->SetOrderBy([ 'id' => false, ]); } return $oDbObjectSet; } /** * SearchByItem. * * @param string $sItemClass * @param string $sItemId * @param bool $bReverseOrder reverse order of result * * @return \DBObjectSet * @throws \MySQLException * @throws \OQLException */ public function SearchByItem(string $sItemClass, string $sItemId, bool $bReverseOrder = false): DBObjectSet { // Prepare OQL $sOQL = sprintf('SELECT `%s` WHERE item_class=:item_class AND item_id=:item_id', TemporaryObjectDescriptor::class); // Create db search $oDbObjectSearch = DBSearch::FromOQL($sOQL); // Create db set from db search $oDbObjectSet = new DBObjectSet($oDbObjectSearch, [], [ 'item_class' => $sItemClass, 'item_id' => $sItemId, ]); // Reverse order if ($bReverseOrder) { $oDbObjectSet->SetOrderBy([ 'id' => false, ]); } return $oDbObjectSet; } /** * CountTemporaryObjectsByTempId. * * @param string $sTempId * * @return int */ public function CountTemporaryObjectsByTempId(string $sTempId): int { try { $oDbObjectSet = $this->SearchByTempId($sTempId); // return operation success return $oDbObjectSet->count(); } catch (Exception $e) { ExceptionLog::LogException($e); return -1; } } /** * SearchByExpired. * * @return DBObjectSet * @throws \OQLException */ public function SearchByExpired(): DBObjectSet { // Prepare OQL $sOQL = sprintf('SELECT `%s` WHERE expiration_date<:now', TemporaryObjectDescriptor::class); // Create db search $oDbObjectSearch = DBSearch::FromOQL($sOQL); // Create db set from db search $sDateNow = date(AttributeDateTime::GetSQLFormat(), time()); return new DBObjectSet($oDbObjectSearch, ['id' => false], ['now' => $sDateNow]); } }