Skip to content

Commit

Permalink
Replacing column names to to avoid problems with MySQL reserved word
Browse files Browse the repository at this point in the history
  • Loading branch information
twoln committed Aug 21, 2023
1 parent e30834b commit 1cdeb97
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 77 deletions.
4 changes: 2 additions & 2 deletions core/AbstractProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ protected function addInternalAttributes($internalAttributes)
"lang" => NULL,
"value" => $attValue,
"level" => Options::LEVEL_PROFILE,
"row" => 0,
"row_id" => 0,
"flag" => NULL,
];
}
Expand All @@ -832,7 +832,7 @@ protected function addInternalAttributes($internalAttributes)
*/
protected function addDatabaseAttributes()
{
$databaseAttributes = $this->retrieveOptionsFromDatabase("SELECT DISTINCT option_name, option_lang, option_value, row
$databaseAttributes = $this->retrieveOptionsFromDatabase("SELECT DISTINCT option_name, option_lang, option_value, row_id
FROM $this->entityOptionTable
WHERE $this->entityIdColumn = ?
AND device_id IS NULL AND eap_method_id = 0
Expand Down
2 changes: 1 addition & 1 deletion core/DBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function exec($querystring, $types = NULL, &...$arguments)
public function lastID()
{
if (is_string($this->connection->insert_id)) {
throw new \Exception("The row ID is allegedly larger than PHP_INT_MAX. This is unbelievable.");
throw new \Exception("The row_id ID is allegedly larger than PHP_INT_MAX. This is unbelievable.");
}
return $this->connection->insert_id;
}
Expand Down
2 changes: 1 addition & 1 deletion core/DeploymentManaged.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function __construct($idpObject, $deploymentIdRaw, $consortium = 'eduroam
$this->host2_v6 = $iterator3->radius_ip6;
$this->radius_hostname_2 = $iterator3->mgmt_hostname;
}
$thisLevelAttributes = $this->retrieveOptionsFromDatabase("SELECT DISTINCT option_name, option_lang, option_value, row
$thisLevelAttributes = $this->retrieveOptionsFromDatabase("SELECT DISTINCT option_name, option_lang, option_value, row_id
FROM $this->entityOptionTable
WHERE $this->entityIdColumn = ?
ORDER BY option_name", "Profile");
Expand Down
28 changes: 14 additions & 14 deletions core/EntityWithDBProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ abstract class EntityWithDBProperties extends \core\common\Entity

/**
* the unique identifier of this entity instance
* refers to the integer row name in the DB -> int; Federation has no own
* refers to the integer row_id name in the DB -> int; Federation has no own
* DB, so the identifier is of no use there -> use Fedearation->$tld
*
* @var integer identifier of the entity instance
Expand Down Expand Up @@ -173,18 +173,18 @@ public function getAttributes(string $optionName = NULL)
* deletes all attributes in this profile except the _file ones, these are reported as array
*
* @param string $extracondition a condition to append to the deletion query. RADIUS Profiles have eap-level or device-level options which shouldn't be purged; this can be steered in the overriding function.
* @return array list of row id's of file-based attributes which weren't deleted
* @return array list of row_id id's of file-based attributes which weren't deleted
*/
public function beginFlushAttributes($extracondition = "")
{
$quotedIdentifier = (!is_int($this->getRelevantIdentifier()) ? "\"" : "") . $this->getRelevantIdentifier() . (!is_int($this->getRelevantIdentifier()) ? "\"" : "");
$this->databaseHandle->exec("DELETE FROM $this->entityOptionTable WHERE $this->entityIdColumn = $quotedIdentifier AND option_name NOT LIKE '%_file' $extracondition");
$this->updateFreshness();
$execFlush = $this->databaseHandle->exec("SELECT row FROM $this->entityOptionTable WHERE $this->entityIdColumn = $quotedIdentifier $extracondition");
$execFlush = $this->databaseHandle->exec("SELECT row_id FROM $this->entityOptionTable WHERE $this->entityIdColumn = $quotedIdentifier $extracondition");
$returnArray = [];
// SELECT always returns a resource, never a boolean
while ($queryResult = mysqli_fetch_object(/** @scrutinizer ignore-type */ $execFlush)) {
$returnArray[$queryResult->row] = "KILLME";
$returnArray[$queryResult->row_id] = "KILLME";
}
return $returnArray;
}
Expand All @@ -198,8 +198,8 @@ public function beginFlushAttributes($extracondition = "")
public function commitFlushAttributes(array $tobedeleted)
{
$quotedIdentifier = (!is_int($this->getRelevantIdentifier()) ? "\"" : "") . $this->getRelevantIdentifier() . (!is_int($this->getRelevantIdentifier()) ? "\"" : "");
foreach (array_keys($tobedeleted) as $row) {
$this->databaseHandle->exec("DELETE FROM $this->entityOptionTable WHERE $this->entityIdColumn = $quotedIdentifier AND row = $row");
foreach (array_keys($tobedeleted) as $row_id) {
$this->databaseHandle->exec("DELETE FROM $this->entityOptionTable WHERE $this->entityIdColumn = $quotedIdentifier AND row_id = $row_id");
$this->updateFreshness();
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ protected function retrieveOptionsFromDatabase($query, $level)
if ($optinfo['type'] == 'file') {
$decoded = base64_decode($decoded);
}
$tempAttributes[] = ["name" => $attributeQuery->option_name, "lang" => $attributeQuery->option_lang, "value" => $decoded, "level" => $level, "row" => $attributeQuery->row, "flag" => $flag];
$tempAttributes[] = ["name" => $attributeQuery->option_name, "lang" => $attributeQuery->option_lang, "value" => $decoded, "level" => $level, "row_id" => $attributeQuery->row_id, "flag" => $flag];
}
return $tempAttributes;
}
Expand All @@ -267,10 +267,10 @@ protected function retrieveOptionsFromDatabase($query, $level)
* Retrieves data from the underlying tables, for situations where instantiating the IdP or Profile object is inappropriate
*
* @param string $table institution_option or profile_option
* @param int $row rowindex
* @param int $row_id rowindex
* @return string|boolean the data, or FALSE if something went wrong
*/
public static function fetchRawDataByIndex($table, $row)
public static function fetchRawDataByIndex($table, $row_id)
{
// only for select tables!
switch ($table) {
Expand All @@ -284,7 +284,7 @@ public static function fetchRawDataByIndex($table, $row)
return FALSE;
}
$handle = DBConnection::handle("INST");
$blobQuery = $handle->exec("SELECT option_value from $table WHERE row = $row");
$blobQuery = $handle->exec("SELECT option_value from $table WHERE row_id = $row_id");
// SELECT -> returns resource, not boolean
$dataset = mysqli_fetch_row(/** @scrutinizer ignore-type */ $blobQuery);
return $dataset[0] ?? FALSE;
Expand All @@ -295,10 +295,10 @@ public static function fetchRawDataByIndex($table, $row)
* yes who the authorised admins to view it are (return array of user IDs)
*
* @param string $table which database table is this about
* @param int $row row index of the table
* @param int $row_id row_id index of the table
* @return mixed FALSE if the data is public, an array of owners of the data if it is NOT public
*/
public static function isDataRestricted($table, $row)
public static function isDataRestricted($table, $row_id)
{
if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option" && $table != "user_options") {
return []; // better safe than sorry: that's an error, so assume nobody is authorised to act on that data
Expand All @@ -312,9 +312,9 @@ public static function isDataRestricted($table, $row)
case "institution_option":
$blobId = -1;
$columnName = $columnName ?? "institution_id";
$blobQuery = $handle->exec("SELECT $columnName as id from $table WHERE row = ?", "i", $row);
$blobQuery = $handle->exec("SELECT $columnName as id from $table WHERE row_id = ?", "i", $row_id);
// SELECT always returns a resource, never a boolean
while ($idQuery = mysqli_fetch_object(/** @scrutinizer ignore-type */ $blobQuery)) { // only one row
while ($idQuery = mysqli_fetch_object(/** @scrutinizer ignore-type */ $blobQuery)) { // only one row_id
$blobId = $idQuery->id;
}
if ($blobId == -1) {
Expand Down
2 changes: 1 addition & 1 deletion core/ExternalEduroamDBData.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function listExternalTlsServersFederation($tld) {
$query = "SELECT servers, contacts FROM eduroamv2.view_tls_ro WHERE country = ? AND servers IS NOT NULL AND contacts IS NOT NULL";
$roTldServerTransaction = $this->db->exec($query, "s", $tld);
while ($roServerResponses = mysqli_fetch_object(/** @scrutinizer ignore-type */ $roTldServerTransaction)) {
// there is only one row
// there is only one row_id
$retval[$roServerResponses->servers] = $this->dissectCollapsedContacts($roServerResponses->contacts);
}
return $retval;
Expand Down
14 changes: 7 additions & 7 deletions core/Federation.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function __construct($fedname)
throw new Exception("This database type is never an array!");
}
// fetch attributes from DB; populates $this->attributes array
$this->attributes = $this->retrieveOptionsFromDatabase("SELECT DISTINCT option_name, option_lang, option_value, row
$this->attributes = $this->retrieveOptionsFromDatabase("SELECT DISTINCT option_name, option_lang, option_value, row_id
FROM $this->entityOptionTable
WHERE $this->entityIdColumn = ?
ORDER BY option_name", "FED");
Expand All @@ -210,7 +210,7 @@ public function __construct($fedname)
"lang" => NULL,
"value" => $this->tld,
"level" => Options::LEVEL_FED,
"row" => 0,
"row_id" => 0,
"flag" => NULL);

if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_RADIUS'] != 'LOCAL' && \config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == 'LOCAL') {
Expand All @@ -221,7 +221,7 @@ public function __construct($fedname)
"lang" => NULL,
"value" => "on",
"level" => Options::LEVEL_FED,
"row" => 0,
"row_id" => 0,
"flag" => NULL);
}

Expand Down Expand Up @@ -550,10 +550,10 @@ public function listExternalEntities($unmappedOnly, $type = NULL)
private static function findCandidates(\mysqli_result $dbResult, &$country)
{
$retArray = [];
while ($row = mysqli_fetch_object($dbResult)) {
if (!in_array($row->id, $retArray)) {
$retArray[] = $row->id;
$country = strtoupper($row->country);
while ($row_id = mysqli_fetch_object($dbResult)) {
if (!in_array($row_id->id, $retArray)) {
$retArray[] = $row_id->id;
$country = strtoupper($row_id->country);
}
}
if (count($retArray) <= 0) {
Expand Down
6 changes: 3 additions & 3 deletions core/IdP.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class IdP extends EntityWithDBProperties
* Constructs an IdP object based on its details in the database.
* Cannot be used to define a new IdP in the database! This happens via Federation::newIdP()
*
* @param int $instId the database row identifier
* @param int $instId the database row_id identifier
* @throws Exception
*/
public function __construct(int $instId)
Expand All @@ -100,7 +100,7 @@ public function __construct(int $instId)
$this->externalDbSyncstate = $instQuery->external_db_syncstate;

// fetch attributes from DB; populates $this->attributes array
$this->attributes = $this->retrieveOptionsFromDatabase("SELECT DISTINCT option_name, option_lang, option_value, row
$this->attributes = $this->retrieveOptionsFromDatabase("SELECT DISTINCT option_name, option_lang, option_value, row_id
FROM $this->entityOptionTable
WHERE $this->entityIdColumn = ?
ORDER BY option_name", "IdP");
Expand All @@ -109,7 +109,7 @@ public function __construct(int $instId)
"lang" => NULL,
"value" => $this->federation,
"level" => Options::LEVEL_IDP,
"row" => 0,
"row_id" => 0,
"flag" => NULL];

$this->name = $this->languageInstance->getLocalisedValue($this->getAttributes('general:instname'));
Expand Down
4 changes: 2 additions & 2 deletions core/IdPlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private static function setAllProfileQuery() {
/**
* Extract IdP attributes for listAllIdentityProviders and
* listIdentityProvidersWithProfiles
* @param $idp object - the row object returned by the IdP search
* @param $idp object - the row_id object returned by the IdP search
* @return array the IdP attributes
*/
private static function setIdentityProviderAttributes($idp) {
Expand Down Expand Up @@ -312,7 +312,7 @@ private static function setIdentityProviderAttributes($idp) {
/**
* Extract Profile attributes for listIdentityProvidersWithProfiles
*
* @param object $profile - the row object returned by the profile search
* @param object $profile - the row_id object returned by the profile search
* @return array the profile attributes
*/
private static function setProfileAttributes($profile)
Expand Down
12 changes: 6 additions & 6 deletions core/ProfileRADIUS.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private function fetchDeviceOrEAPLevelAttributes($devicesOrEAPMethods)
throw new Exception("fetchDeviceOrEAPLevelAttributes: unexpected keyword $devicesOrEAPMethods");
}

$allAttributes = $this->databaseHandle->exec("SELECT option_name, option_lang, option_value, $queryPart as deviceormethod, row
$allAttributes = $this->databaseHandle->exec("SELECT option_name, option_lang, option_value, $queryPart as deviceormethod, row_id
FROM $this->entityOptionTable
WHERE $this->entityIdColumn = $this->identifier $conditionPart");

Expand All @@ -197,7 +197,7 @@ private function fetchDeviceOrEAPLevelAttributes($devicesOrEAPMethods)
"lang" => $attributeQuery->option_lang,
"value" => $attributeQuery->option_value,
"level" => Options::LEVEL_METHOD,
"row" => $attributeQuery->row,
"row_id" => $attributeQuery->row_id,
"flag" => $optinfo['flag'],
"device" => ($devicesOrEAPMethods == "DEVICES" ? $attributeQuery->deviceormethod : NULL),
"eapmethod" => ($devicesOrEAPMethods == "DEVICES" ? 0 : (new \core\common\EAP($attributeQuery->deviceormethod))->getArrayRep() )];
Expand Down Expand Up @@ -288,7 +288,7 @@ public function addAttribute($attrName, $attrLang, $attrValue)
* normal DB-based attributes
*
* @param string $extracondition a condition to append to the deletion query. RADIUS Profiles have eap-level or device-level options which shouldn't be purged; this can be steered in the overriding function.
* @return array list of row id's of file-based attributes which weren't deleted
* @return array list of row_id id's of file-based attributes which weren't deleted
* @throws Exception
*/
public function beginFlushAttributes($extracondition = "")
Expand Down Expand Up @@ -344,7 +344,7 @@ public function setInputVerificationPreference($verify, $hint)
*
* @param int $eapId the numeric identifier of the EAP method
* @param string $deviceId the name of the device
* @return array list of row id's of file-based attributes which weren't deleted
* @return array list of row_id id's of file-based attributes which weren't deleted
* @throws Exception
*/
public function beginFlushMethodLevelAttributes($eapId, $deviceId)
Expand All @@ -365,11 +365,11 @@ public function beginFlushMethodLevelAttributes($eapId, $deviceId)
$this->databaseHandle->exec("DELETE FROM $this->entityOptionTable WHERE $this->entityIdColumn = $this->identifier AND option_name NOT LIKE '%_file' $extracondition");
$this->updateFreshness();
// there are currently none file-based attributes on method level, so result here is always empty, but better be prepared for the future
$findFlushCandidates = $this->databaseHandle->exec("SELECT row FROM $this->entityOptionTable WHERE $this->entityIdColumn = $this->identifier $extracondition");
$findFlushCandidates = $this->databaseHandle->exec("SELECT row_id FROM $this->entityOptionTable WHERE $this->entityIdColumn = $this->identifier $extracondition");
$returnArray = [];
// SELECT -> resource, not boolean
while ($queryResult = mysqli_fetch_object(/** @scrutinizer ignore-type */ $findFlushCandidates)) {
$returnArray[$queryResult->row] = "KILLME";
$returnArray[$queryResult->row_id] = "KILLME";
}
return $returnArray;
}
Expand Down
2 changes: 1 addition & 1 deletion core/ProfileSilverbullet.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function listActiveUsers() {
*
* @param string $username the username
* @param \DateTime $expiry the expiry date
* @return int row ID of the new user in the database
* @return int row_id ID of the new user in the database
*/
public function addUser($username, \DateTime $expiry) {
$query = "INSERT INTO silverbullet_user (profile_id, username, expiry) VALUES(?,?,?)";
Expand Down
4 changes: 2 additions & 2 deletions core/SilverbulletCertificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class SilverbulletCertificate extends EntityWithDBProperties
public $serial;

/**
* row index of this certificate in the database table
* row_id index of this certificate in the database table
*
* @var integer
*/
public $dbId;

/**
* the row index of the invitation which was consumed to generate this
* the row_id index of the invitation which was consumed to generate this
* certificate
*
* @var integer
Expand Down
2 changes: 1 addition & 1 deletion core/SilverbulletInvitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SilverbulletInvitation extends common\Entity
{

/**
* row ID in the database pertaining to this invitation. 0 on invalid invitations.
* row_id ID in the database pertaining to this invitation. 0 on invalid invitations.
*
* @var integer
*/
Expand Down
Loading

0 comments on commit 1cdeb97

Please sign in to comment.