FOSSology  4.4.0
Open Source License Compliance by Open Source Software
Fossology\UI\Api\Helper\DbHelper Class Reference

Provides helper methods to access database for REST api. More...

Collaboration diagram for Fossology\UI\Api\Helper\DbHelper:
Collaboration graph

Public Member Functions

 __construct (DbManager $dbManager, FolderDao $folderDao, UploadDao $uploadDao)
 
 getDbManager ()
 
 getUploads ($userId, $groupId, $limit, $page=1, $uploadId=null, $options=null, $recursive=true, $apiVersion=ApiVersion::V1)
 
 getFilenameFromUploadTree ($uploadTreePk)
 
 doesIdExist ($tableName, $idRowName, $id)
 
 deleteUser ($id)
 
 getUsers ($id=null)
 
 getJobs ($id=null, $limit=0, $page=1, $uploadId=null)
 Get the recent jobs. More...
 
 getUserJobs ($id=null, $uid=null, $limit=0, $page=1, $uploadId=null)
 Get the recent jobs created by an user. More...
 
 getTokenKey ($tokenId)
 
 invalidateToken ($tokenId)
 
 insertNewTokenKey ($userId, $expire, $scope, $name, $key)
 
 addNewClient ($name, $userId, $clientId, $scope)
 
 getMaxTokenValidity ()
 
 getPfileInfoForUpload ($uploadId)
 
 getLicensesPaginated ($page, $limit, $kind, $groupId, $active)
 
 getLicenseCount ($kind, $groupId)
 
 getTokenIdFromClientId ($clientId)
 

Private Member Functions

 checkTokenNameUnique ($userId, $tokenName)
 
 checkTokenKeyUnique ($userId, $tokenKey)
 
 getFolderForUpload ($uploadId)
 

Private Attributes

 $dbManager
 
 $folderDao
 
 $uploadDao
 

Detailed Description

Provides helper methods to access database for REST api.

Definition at line 37 of file DbHelper.php.

Constructor & Destructor Documentation

◆ __construct()

Fossology\UI\Api\Helper\DbHelper::__construct ( DbManager  $dbManager,
FolderDao  $folderDao,
UploadDao  $uploadDao 
)

DbHelper constructor.

Parameters
DbManager$dbManagerDB manager in use
FolderDao$folderDaoFolder Dao to use
UploadDao$uploadDaoUpload Dao to use

Definition at line 64 of file DbHelper.php.

Member Function Documentation

◆ addNewClient()

Fossology\UI\Api\Helper\DbHelper::addNewClient (   $name,
  $userId,
  $clientId,
  $scope 
)

Adds new oauth client to the user.

Parameters
string$nameName of the new client
integer$userIdUser PK
string$clientIdNew client ID
string$scopeToken scope

Definition at line 498 of file DbHelper.php.

◆ checkTokenKeyUnique()

Fossology\UI\Api\Helper\DbHelper::checkTokenKeyUnique (   $userId,
  $tokenKey 
)
private

Checks if the personal_access_tokens_token_key_ukey constraint is followed by this token.

Parameters
int$userIdUser id
string$tokenKeyToken secret key
Returns
boolean True if the constraint is followed, false otherwise.

Definition at line 537 of file DbHelper.php.

◆ checkTokenNameUnique()

Fossology\UI\Api\Helper\DbHelper::checkTokenNameUnique (   $userId,
  $tokenName 
)
private

Checks if the personal_access_tokens_token_name_ukey constraint is followed by this token.

Parameters
int$userIdUser id
string$tokenNameName of the token
Returns
boolean True if the constraint is followed, false otherwise.

Definition at line 516 of file DbHelper.php.

◆ deleteUser()

Fossology\UI\Api\Helper\DbHelper::deleteUser (   $id)

Delete the given user id

Parameters
integer$idUser id to be deleted

Definition at line 239 of file DbHelper.php.

◆ doesIdExist()

Fossology\UI\Api\Helper\DbHelper::doesIdExist (   $tableName,
  $idRowName,
  $id 
)

Check if a given id exists under given table.

Parameters
string$tableNameTable name
string$idRowNameID column name
string$idID to check
Returns
boolean True if id exists, false otherwise

Definition at line 227 of file DbHelper.php.

◆ getDbManager()

Fossology\UI\Api\Helper\DbHelper::getDbManager ( )

Get the DB manager

Returns
ModernDbManager

Definition at line 77 of file DbHelper.php.

◆ getFilenameFromUploadTree()

Fossology\UI\Api\Helper\DbHelper::getFilenameFromUploadTree (   $uploadTreePk)

Get first upload name under a given upload tree id

Parameters
integer$uploadTreePkUpload tree id to check.
Returns
string

Definition at line 212 of file DbHelper.php.

◆ getFolderForUpload()

Fossology\UI\Api\Helper\DbHelper::getFolderForUpload (   $uploadId)
private

Get the folder for given upload

Parameters
integer$uploadIdUpload to get folder for
Returns
Folder|null Folder object if found, null otherwise

Definition at line 589 of file DbHelper.php.

◆ getJobs()

Fossology\UI\Api\Helper\DbHelper::getJobs (   $id = null,
  $limit = 0,
  $page = 1,
  $uploadId = null 
)

Get the recent jobs.

If a limit is passed, the results are trimmed. If an ID is passed, the information for the given id is only retrieved.

Parameters
integer$idSet to get information of only given job id
integer$limitSet to limit the result length
integer$pagePage number required
integer$uploadIdUpload ID to be filtered
Returns
array[] List of jobs at first index and total number of pages at second.

Definition at line 302 of file DbHelper.php.

◆ getLicenseCount()

Fossology\UI\Api\Helper\DbHelper::getLicenseCount (   $kind,
  $groupId 
)

Get the count of licenses accessible by user based on group ID

Parameters
string$kindWhich kind of licenses to look for
integer$groupIdGroup of the user
Returns
int Count of licenses

Definition at line 638 of file DbHelper.php.

◆ getLicensesPaginated()

Fossology\UI\Api\Helper\DbHelper::getLicensesPaginated (   $page,
  $limit,
  $kind,
  $groupId,
  $active 
)

Get the licenses from database in paginated way

Parameters
integer$pageWhich page number to fetch
integer$limitLimit of results
string$kindWhich kind of licenses to fetch
integer$groupIdGroup of the user
boolean$activeTrue to get only active licenses
Returns
array

Definition at line 607 of file DbHelper.php.

◆ getMaxTokenValidity()

Fossology\UI\Api\Helper\DbHelper::getMaxTokenValidity ( )

Get the value for maximum API token validity from sysconfig table.

Returns
integer The value stored in DB or 30 (default).

Definition at line 555 of file DbHelper.php.

◆ getPfileInfoForUpload()

Fossology\UI\Api\Helper\DbHelper::getPfileInfoForUpload (   $uploadId)

Get all info from pfile for given upload

Parameters
integer$uploadIdUpload to get info for
Returns
array|NULL Array of pfile if upload found, null otherwise

Definition at line 572 of file DbHelper.php.

◆ getTokenKey()

Fossology\UI\Api\Helper\DbHelper::getTokenKey (   $tokenId)

Get the required information to validate a token based on token id.

Parameters
int$tokenIdToken id (primary key of the table).
Returns
array Returns the token_key, created_on,expire_onand user_fk` for the given token id.

Definition at line 438 of file DbHelper.php.

◆ getUploads()

Fossology\UI\Api\Helper\DbHelper::getUploads (   $userId,
  $groupId,
  $limit,
  $page = 1,
  $uploadId = null,
  $options = null,
  $recursive = true,
  $apiVersion = ApiVersion::V1 
)

Get the uploads under the given user id if not upload id is provided.

Get a single upload information under the given user and upload id.

Parameters
integer$userIdUser to check
integer$groupIdGroup trying to access
integer$limitMax number of results
integer$pagePage to get
integer$uploadIdPass the upload id to check for single upload.
integer$optionsFilter options
bool$recursiveTrue to recursive listing of uploads
Returns
array Total pages as first value, uploads as an array in second value

Definition at line 97 of file DbHelper.php.

◆ getUserJobs()

Fossology\UI\Api\Helper\DbHelper::getUserJobs (   $id = null,
  $uid = null,
  $limit = 0,
  $page = 1,
  $uploadId = null 
)

Get the recent jobs created by an user.

If a limit is passed, the results are trimmed. If an ID is passed, the information for the given id is only retrieved.

Parameters
integer$idSet to get information of only given job id
integer$uidSet to get information of only given user's ID
integer$limitSet to limit the result length
integer$pagePage number required
integer$uploadIdUpload ID to be filtered
Returns
array[] List of jobs at first index and total number of pages at second.

Definition at line 374 of file DbHelper.php.

◆ getUsers()

Fossology\UI\Api\Helper\DbHelper::getUsers (   $id = null)

Get the user under the given user id or every user from the database.

Parameters
integer$idUser id of the required user, or NULL to fetch all users.
Returns
User[] Users as an associative array

Definition at line 252 of file DbHelper.php.

◆ insertNewTokenKey()

Fossology\UI\Api\Helper\DbHelper::insertNewTokenKey (   $userId,
  $expire,
  $scope,
  $name,
  $key 
)

Insert a new token in the DB.

Parameters
int$userIdUser of the new token
string$expireWhen the token will expire
string$scopeScope of the token
string$nameName of the token
string$keySecret key of the token
Returns
array|Fossology::UI::Api::Models::Info New token id and created_on or Info on error.
Exceptions
DuplicateTokenNameExceptionIf user already have a token with same name.
DuplicateTokenKeyExceptionIf user already have a token with same key.

Definition at line 472 of file DbHelper.php.

◆ invalidateToken()

Fossology\UI\Api\Helper\DbHelper::invalidateToken (   $tokenId)

Mark a token as invalid/inactive.

Parameters
int$tokenIdThe token to be marked as invalid

Definition at line 451 of file DbHelper.php.

Member Data Documentation

◆ $dbManager

ModernDbManager Fossology\UI\Api\Helper\DbHelper::$dbManager
private

DB manager in use

Definition at line 43 of file DbHelper.php.

◆ $folderDao

FolderDao Fossology\UI\Api\Helper\DbHelper::$folderDao
private

FolderDao object

Definition at line 49 of file DbHelper.php.

◆ $uploadDao

UploadDao Fossology\UI\Api\Helper\DbHelper::$uploadDao
private

UploadDao object

Definition at line 55 of file DbHelper.php.


The documentation for this class was generated from the following file: