Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent DB enum function #5952

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 145 additions & 35 deletions html/inc/boinc_db.inc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to split this file to have 1 file per class for OOP. I'm not sure that this is possible with the current setup though.

Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ class BoincUser {
$db = BoincDb::get();
return $db->update($this, 'user', $clause);
}
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincUser>
*/
Comment on lines +207 to +211
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the typing. If we target recent php versions I can just add it directly in the function signature (except for the generic return).

static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('user', 'BoincUser', $where_clause, $order_clause);
Expand Down Expand Up @@ -258,6 +263,11 @@ class BoincTeam {
$db = BoincDb::get();
return $db->update($this, 'team', $clause);
}
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincTeam>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('team', 'BoincTeam', $where_clause, $order_clause);
Expand Down Expand Up @@ -297,9 +307,14 @@ class BoincTeamDelta {
$db = BoincDb::get();
return $db->insert('team_delta', $clause);
}
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincTeamDelta>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('team_delta', 'BoincTeamDelta', $where_clause);
return $db->enum('team_delta', 'BoincTeamDelta', $where_clause, $order_clause);
}
Comment on lines +315 to 318
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have this function in a trait?

static function delete_for_user($user_id) {
$db = BoincDb::get();
Expand All @@ -321,6 +336,11 @@ class BoincHost {
$db = BoincDb::get();
return $db->delete($this, 'host');
}
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincHost>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('host', 'BoincHost', $where_clause, $order_clause);
Expand Down Expand Up @@ -358,9 +378,14 @@ class BoincResult {
$db = BoincDb::get();
return $db->count('result', $clause);
}
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincResult>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('result', 'BoincResult', $where_clause);
return $db->enum('result', 'BoincResult', $where_clause, $order_clause);
}
static function enum_fields($fields, $where_clause, $order_clause) {
$db = BoincDb::get();
Expand Down Expand Up @@ -405,9 +430,14 @@ class BoincWorkunit {
if (!$ret) return $ret;
return $db->insert_id();
}
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincWorkunit>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('workunit', 'BoincWorkunit', $where_clause);
return $db->enum('workunit', 'BoincWorkunit', $where_clause, $order_clause);
}
function update($clause) {
$db = BoincDb::get();
Expand All @@ -433,9 +463,14 @@ class BoincApp {
$db = BoincDb::get();
return $db->lookup('app', 'BoincApp', $clause);
}
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincApp>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('app', 'BoincApp', $where_clause);
return $db->enum('app', 'BoincApp', $where_clause, $order_clause);
}
static function insert($clause) {
$db = BoincDb::get();
Expand All @@ -455,9 +490,14 @@ class BoincApp {

#[AllowDynamicProperties]
class BoincAppVersion {
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincAppVersion>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('app_version', 'BoincAppVersion', $where_clause);
return $db->enum('app_version', 'BoincAppVersion', $where_clause, $order_clause);
}
static function lookup($clause) {
$db = BoincDb::get();
Expand Down Expand Up @@ -505,6 +545,11 @@ class BoincProfile {
$db = BoincDb::get();
return $db->insert('profile', $clause);
}
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincProfile>
*/
static function enum($where_clause=null, $order_clause=null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only occurence of $where_clause=null, should I keep it? Or should I check for usages?

$db = BoincDb::get();
return $db->enum('profile', 'BoincProfile', $where_clause, $order_clause);
Expand All @@ -529,9 +574,14 @@ class BoincTeamAdmin {
$db = BoincDb::get();
return $db->insert('team_admin', $clause);
}
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincTeamAdmin>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('team_admin', 'BoincTeamAdmin', $where_clause);
return $db->enum('team_admin', 'BoincTeamAdmin', $where_clause, $order_clause);
}
static function delete($clause) {
$db = BoincDb::get();
Expand All @@ -553,9 +603,14 @@ class BoincPrivateMessage {
$db = BoincDb::get();
return $db->update($this, 'private_messages', $clause);
}
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincPrivateMessage>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('private_messages', 'BoincPrivateMessage', $where_clause);
return $db->enum('private_messages', 'BoincPrivateMessage', $where_clause, $order_clause);
}
static function insert($clause) {
$db = BoincDb::get();
Expand All @@ -579,9 +634,14 @@ class BoincPrivateMessage {

#[AllowDynamicProperties]
class BoincPlatform {
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincPlatform>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('platform', 'BoincPlatform', $where_clause);
return $db->enum('platform', 'BoincPlatform', $where_clause, $order_clause);
}
static function lookup_id($id) {
$db = BoincDb::get();
Expand All @@ -603,9 +663,14 @@ class BoincPlatform {

#[AllowDynamicProperties]
class BoincHostAppVersion {
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincHostAppVersion>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('host_app_version', 'BoincHostAppVersion', $where_clause);
return $db->enum('host_app_version', 'BoincHostAppVersion', $where_clause, $order_clause);
}
static function lookup($host_id, $app_version_id) {
$db = BoincDb::get();
Expand Down Expand Up @@ -663,9 +728,14 @@ function latest_avs_app($appid) {

#[AllowDynamicProperties]
class BoincBadge {
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincBadge>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('badge', 'BoincBadge', $where_clause);
return $db->enum('badge', 'BoincBadge', $where_clause, $order_clause);
}
static function insert($clause) {
$db = BoincDb::get();
Expand Down Expand Up @@ -693,9 +763,14 @@ class BoincBadge {

#[AllowDynamicProperties]
class BoincBadgeUser {
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincBadgeUser>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('badge_user', 'BoincBadgeUser', $where_clause);
return $db->enum('badge_user', 'BoincBadgeUser', $where_clause, $order_clause);
}
static function insert($clause) {
$db = BoincDb::get();
Expand Down Expand Up @@ -723,9 +798,14 @@ class BoincBadgeUser {

#[AllowDynamicProperties]
class BoincBadgeTeam {
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincBadgeTeam>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('badge_team', 'BoincBadgeTeam', $where_clause);
return $db->enum('badge_team', 'BoincBadgeTeam', $where_clause, $order_clause);
}
static function insert($clause) {
$db = BoincDb::get();
Expand Down Expand Up @@ -757,9 +837,14 @@ class BoincCreditUser {
$db = BoincDb::get();
return $db->lookup('credit_user', 'BoincCreditUser', $clause);
}
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincCreditUser>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('credit_user', 'BoincCreditUser', $where_clause);
return $db->enum('credit_user', 'BoincCreditUser', $where_clause, $order_clause);
}
static function sum($field, $clause) {
$db = BoincDb::get();
Expand All @@ -774,7 +859,7 @@ class BoincCreditUser {
$db->delete_aux('credit_user', "userid=$user->id");
}
static function get_list($where_clause, $order_clause, $limit) {
$db = BoincDB::get();
$db = BoincDb::get();
return $db->get_list('user', 'credit_user', 'id', 'userid', 'BoincCreditUser', '*', $where_clause, $order_clause, $limit);
}
}
Expand All @@ -785,9 +870,14 @@ class BoincCreditTeam {
$db = BoincDb::get();
return $db->lookup('credit_team', 'BoincCreditTeam', $clause);
}
static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincCreditTeam>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('credit_team', 'BoincCreditTeam', $where_clause);
return $db->enum('credit_team', 'BoincCreditTeam', $where_clause, $order_clause);
}
static function sum($field, $clause) {
$db = BoincDb::get();
Expand All @@ -798,7 +888,7 @@ class BoincCreditTeam {
return $db->update_aux('credit_team', $clause);
}
static function get_list($where_clause, $order_clause, $limit) {
$db = BoincDB::get();
$db = BoincDb::get();
return $db->get_list('team', 'credit_team', 'id', 'teamid', 'BoincCreditTeam', '*', $where_clause, $order_clause, $limit);
}
}
Expand All @@ -819,9 +909,14 @@ class BoincToken {
return self::lookup("userid=$userid and token='$token' and expire_time > $now and type = '$type'");
}

static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincToken>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('token', 'BoincToken', $where_clause);
return $db->enum('token', 'BoincToken', $where_clause, $order_clause);
}

static function insert($clause) {
Expand All @@ -830,7 +925,7 @@ class BoincToken {
}

static function get_list($where_clause, $order_clause, $limit) {
$db = BoincDB::get();
$db = BoincDb::get();
return $db->get_list('token', 'userid', 'type', 'create_time', 'expire_time', 'BoincToken', '*', $where_clause, $order_clause, $limit);
}

Expand Down Expand Up @@ -899,9 +994,14 @@ class BoincConsent {
return $db->lookup('consent', 'BoincConsent', $clause);
}

static function enum($where_clause) {
/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincConsent>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('consent', 'BoincConsent', $where_clause);
return $db->enum('consent', 'BoincConsent', $where_clause, $order_clause);
}

static function insert ($clause) {
Expand Down Expand Up @@ -934,6 +1034,11 @@ class BoincConsentType {
return $db->lookup('consent_type', 'BoincConsentType', $clause);
}

/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincConsentType>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('consent_type', 'BoincConsentType', $where_clause, $order_clause);
Expand Down Expand Up @@ -970,6 +1075,11 @@ class BoincLatestConsent {
return $db->lookup('latest_consent', 'BoincLatestConsent', $clause);
}

/**
* @param string|null $where_clause
* @param string|null $order_clause
* @return list<BoincLatestConsent>
*/
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('latest_consent', 'BoincLatestConsent', $where_clause, $order_clause);
Expand Down
Loading
Loading