Compare commits
1 Commits
master
...
trigger-er
Author | SHA1 | Date | |
---|---|---|---|
85ed6ba8d3 |
@ -41,13 +41,13 @@ class EditAlbum extends HTMLController
|
||||
exit;
|
||||
}
|
||||
else
|
||||
trigger_error('Cannot delete album: an error occured while processing the request.', E_USER_ERROR);
|
||||
throw new Exception('Cannot delete album: an error occured while processing the request.');
|
||||
}
|
||||
// Editing one, then, surely.
|
||||
else
|
||||
{
|
||||
if ($album->kind !== 'Album')
|
||||
trigger_error('Cannot edit album: not an album.', E_USER_ERROR);
|
||||
throw new Exception('Cannot edit album: not an album.');
|
||||
|
||||
parent::__construct('Edit album \'' . $album->tag . '\'');
|
||||
$form_title = 'Edit album \'' . $album->tag . '\'';
|
||||
|
@ -39,13 +39,13 @@ class EditTag extends HTMLController
|
||||
exit;
|
||||
}
|
||||
else
|
||||
trigger_error('Cannot delete tag: an error occured while processing the request.', E_USER_ERROR);
|
||||
throw new Exception('Cannot delete tag: an error occured while processing the request.');
|
||||
}
|
||||
// Editing one, then, surely.
|
||||
else
|
||||
{
|
||||
if ($tag->kind === 'Album')
|
||||
trigger_error('Cannot edit tag: is actually an album.', E_USER_ERROR);
|
||||
throw new Exception('Cannot edit tag: is actually an album.');
|
||||
|
||||
parent::__construct('Edit tag \'' . $tag->tag . '\'');
|
||||
$form_title = 'Edit tag \'' . $tag->tag . '\'';
|
||||
|
@ -33,7 +33,7 @@ class EditUser extends HTMLController
|
||||
{
|
||||
// Don't be stupid.
|
||||
if ($current_user->getUserId() == $id_user)
|
||||
trigger_error('Sorry, I cannot allow you to delete yourself.', E_USER_ERROR);
|
||||
throw new Exception('Sorry, I cannot allow you to delete yourself.');
|
||||
|
||||
// So far so good?
|
||||
$user = Member::fromId($id_user);
|
||||
@ -43,7 +43,7 @@ class EditUser extends HTMLController
|
||||
exit;
|
||||
}
|
||||
else
|
||||
trigger_error('Cannot delete user: an error occured while processing the request.', E_USER_ERROR);
|
||||
throw new Exception('Cannot delete user: an error occured while processing the request.');
|
||||
}
|
||||
// Editing one, then, surely.
|
||||
else
|
||||
|
@ -173,10 +173,10 @@ class Database
|
||||
list ($values, $connection) = $this->db_callback;
|
||||
|
||||
if (!isset($matches[2]))
|
||||
trigger_error('Invalid value inserted or no type specified.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Invalid value inserted or no type specified.');
|
||||
|
||||
if (!isset($values[$matches[2]]))
|
||||
trigger_error('The database value you\'re trying to insert does not exist: ' . htmlspecialchars($matches[2]), E_USER_ERROR);
|
||||
throw new UnexpectedValueException('The database value you\'re trying to insert does not exist: ' . htmlspecialchars($matches[2]));
|
||||
|
||||
$replacement = $values[$matches[2]];
|
||||
|
||||
@ -184,7 +184,7 @@ class Database
|
||||
{
|
||||
case 'int':
|
||||
if ((!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) && $replacement !== 'NULL')
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Integer expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Integer expected.');
|
||||
return $replacement !== 'NULL' ? (string) (int) $replacement : 'NULL';
|
||||
break;
|
||||
|
||||
@ -197,12 +197,12 @@ class Database
|
||||
if (is_array($replacement))
|
||||
{
|
||||
if (empty($replacement))
|
||||
trigger_error('Database error, given array of integer values is empty.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Database error, given array of integer values is empty.');
|
||||
|
||||
foreach ($replacement as $key => $value)
|
||||
{
|
||||
if (!is_numeric($value) || (string) $value !== (string) (int) $value)
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of integers expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of integers expected.');
|
||||
|
||||
$replacement[$key] = (string) (int) $value;
|
||||
}
|
||||
@ -210,7 +210,7 @@ class Database
|
||||
return implode(', ', $replacement);
|
||||
}
|
||||
else
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of integers expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of integers expected.');
|
||||
|
||||
break;
|
||||
|
||||
@ -218,7 +218,7 @@ class Database
|
||||
if (is_array($replacement))
|
||||
{
|
||||
if (empty($replacement))
|
||||
trigger_error('Database error, given array of string values is empty.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Database error, given array of string values is empty.');
|
||||
|
||||
foreach ($replacement as $key => $value)
|
||||
$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
|
||||
@ -226,7 +226,7 @@ class Database
|
||||
return implode(', ', $replacement);
|
||||
}
|
||||
else
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of strings expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Array of strings expected.');
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
@ -235,7 +235,7 @@ class Database
|
||||
elseif ($replacement === 'NULL')
|
||||
return 'NULL';
|
||||
else
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Date expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Date expected.');
|
||||
break;
|
||||
|
||||
case 'datetime':
|
||||
@ -246,12 +246,12 @@ class Database
|
||||
elseif ($replacement === 'NULL')
|
||||
return 'NULL';
|
||||
else
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. DateTime expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. DateTime expected.');
|
||||
break;
|
||||
|
||||
case 'float':
|
||||
if (!is_numeric($replacement) && $replacement !== 'NULL')
|
||||
trigger_error('Wrong value type sent to the database for field: ' . $matches[2] . '. Floating point number expected.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Wrong value type sent to the database for field: ' . $matches[2] . '. Floating point number expected.');
|
||||
return $replacement !== 'NULL' ? (string) (float) $replacement : 'NULL';
|
||||
break;
|
||||
|
||||
@ -271,7 +271,7 @@ class Database
|
||||
break;
|
||||
|
||||
default:
|
||||
trigger_error('Undefined type <b>' . $matches[1] . '</b> used in the database query', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Undefined type <b>' . $matches[1] . '</b> used in the database query');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -289,7 +289,7 @@ class Database
|
||||
|
||||
// Please, just use new style queries.
|
||||
if (strpos($db_string, '\'') !== false && !$security_override)
|
||||
trigger_error('Hack attempt!', 'Illegal character (\') used in query.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Hack attempt!', 'Illegal character (\') used in query.');
|
||||
|
||||
if (!$security_override && !empty($db_values))
|
||||
{
|
||||
@ -313,7 +313,7 @@ class Database
|
||||
catch (Exception $e)
|
||||
{
|
||||
$clean_sql = implode("\n", array_map('trim', explode("\n", $db_string)));
|
||||
trigger_error($this->error() . '<br>' . $clean_sql, E_USER_ERROR);
|
||||
throw new UnexpectedValueException($this->error() . '<br>' . $clean_sql);
|
||||
}
|
||||
|
||||
return $return;
|
||||
@ -327,7 +327,7 @@ class Database
|
||||
{
|
||||
// Please, just use new style queries.
|
||||
if (strpos($db_string, '\'') !== false)
|
||||
trigger_error('Hack attempt!', 'Illegal character (\') used in query.', E_USER_ERROR);
|
||||
throw new UnexpectedValueException('Hack attempt!', 'Illegal character (\') used in query.');
|
||||
|
||||
// Save some values for use in the callback function.
|
||||
$this->db_callback = [$db_values, $this->connection];
|
||||
|
@ -24,7 +24,7 @@ class Registry
|
||||
public static function get($key)
|
||||
{
|
||||
if (!isset(self::$storage[$key]))
|
||||
trigger_error('Key does not exist in Registry: ' . $key, E_USER_ERROR);
|
||||
throw new Exception('Key does not exist in Registry: ' . $key);
|
||||
|
||||
return self::$storage[$key];
|
||||
}
|
||||
@ -32,7 +32,7 @@ class Registry
|
||||
public static function remove($key)
|
||||
{
|
||||
if (!isset(self::$storage[$key]))
|
||||
trigger_error('Key does not exist in Registry: ' . $key, E_USER_ERROR);
|
||||
throw new Exception('Key does not exist in Registry: ' . $key);
|
||||
|
||||
unset(self::$storage[$key]);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class Session
|
||||
public static function getSessionToken()
|
||||
{
|
||||
if (empty($_SESSION['session_token']))
|
||||
trigger_error('Call to getSessionToken without a session token being set!', E_USER_ERROR);
|
||||
throw new Exception('Call to getSessionToken without a session token being set!');
|
||||
|
||||
return $_SESSION['session_token'];
|
||||
}
|
||||
@ -41,7 +41,7 @@ class Session
|
||||
public static function getSessionTokenKey()
|
||||
{
|
||||
if (empty($_SESSION['session_token_key']))
|
||||
trigger_error('Call to getSessionTokenKey without a session token key being set!', E_USER_ERROR);
|
||||
throw new Exception('Call to getSessionTokenKey without a session token key being set!');
|
||||
|
||||
return $_SESSION['session_token_key'];
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ class Tag
|
||||
$data);
|
||||
|
||||
if (!$res)
|
||||
trigger_error('Could not create the requested tag.', E_USER_ERROR);
|
||||
throw new Exception('Could not create the requested tag.');
|
||||
|
||||
$data['id_tag'] = $db->insert_id();
|
||||
return $return_format === 'object' ? new Tag($data) : $data;
|
||||
|
Loading…
Reference in New Issue
Block a user