forked from Public/pics
		
	Replace deprecated trigger_error calls with exceptions
This commit is contained in:
		
							parent
							
								
									814a1f82f6
								
							
						
					
					
						commit
						85ed6ba8d3
					
				@ -41,13 +41,13 @@ class EditAlbum extends HTMLController
 | 
				
			|||||||
				exit;
 | 
									exit;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else
 | 
								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.
 | 
							// Editing one, then, surely.
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if ($album->kind !== 'Album')
 | 
								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 . '\'');
 | 
								parent::__construct('Edit album \'' . $album->tag . '\'');
 | 
				
			||||||
			$form_title = 'Edit album \'' . $album->tag . '\'';
 | 
								$form_title = 'Edit album \'' . $album->tag . '\'';
 | 
				
			||||||
 | 
				
			|||||||
@ -39,13 +39,13 @@ class EditTag extends HTMLController
 | 
				
			|||||||
				exit;
 | 
									exit;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else
 | 
								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.
 | 
							// Editing one, then, surely.
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if ($tag->kind === 'Album')
 | 
								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 . '\'');
 | 
								parent::__construct('Edit tag \'' . $tag->tag . '\'');
 | 
				
			||||||
			$form_title = 'Edit tag \'' . $tag->tag . '\'';
 | 
								$form_title = 'Edit tag \'' . $tag->tag . '\'';
 | 
				
			||||||
 | 
				
			|||||||
@ -33,7 +33,7 @@ class EditUser extends HTMLController
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			// Don't be stupid.
 | 
								// Don't be stupid.
 | 
				
			||||||
			if ($current_user->getUserId() == $id_user)
 | 
								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?
 | 
								// So far so good?
 | 
				
			||||||
			$user = Member::fromId($id_user);
 | 
								$user = Member::fromId($id_user);
 | 
				
			||||||
@ -43,7 +43,7 @@ class EditUser extends HTMLController
 | 
				
			|||||||
				exit;
 | 
									exit;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else
 | 
								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.
 | 
							// Editing one, then, surely.
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
 | 
				
			|||||||
@ -173,10 +173,10 @@ class Database
 | 
				
			|||||||
		list ($values, $connection) = $this->db_callback;
 | 
							list ($values, $connection) = $this->db_callback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!isset($matches[2]))
 | 
							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]]))
 | 
							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]];
 | 
							$replacement = $values[$matches[2]];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -184,7 +184,7 @@ class Database
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			case 'int':
 | 
								case 'int':
 | 
				
			||||||
				if ((!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) && $replacement !== 'NULL')
 | 
									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';
 | 
									return $replacement !== 'NULL' ? (string) (int) $replacement : 'NULL';
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -197,12 +197,12 @@ class Database
 | 
				
			|||||||
				if (is_array($replacement))
 | 
									if (is_array($replacement))
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					if (empty($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)
 | 
										foreach ($replacement as $key => $value)
 | 
				
			||||||
					{
 | 
										{
 | 
				
			||||||
						if (!is_numeric($value) || (string) $value !== (string) (int) $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;
 | 
											$replacement[$key] = (string) (int) $value;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
@ -210,7 +210,7 @@ class Database
 | 
				
			|||||||
					return implode(', ', $replacement);
 | 
										return implode(', ', $replacement);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else
 | 
									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;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -218,7 +218,7 @@ class Database
 | 
				
			|||||||
				if (is_array($replacement))
 | 
									if (is_array($replacement))
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					if (empty($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)
 | 
										foreach ($replacement as $key => $value)
 | 
				
			||||||
						$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
 | 
											$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
 | 
				
			||||||
@ -226,7 +226,7 @@ class Database
 | 
				
			|||||||
					return implode(', ', $replacement);
 | 
										return implode(', ', $replacement);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else
 | 
									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;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case 'date':
 | 
								case 'date':
 | 
				
			||||||
@ -235,7 +235,7 @@ class Database
 | 
				
			|||||||
				elseif ($replacement === 'NULL')
 | 
									elseif ($replacement === 'NULL')
 | 
				
			||||||
					return 'NULL';
 | 
										return 'NULL';
 | 
				
			||||||
				else
 | 
									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;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case 'datetime':
 | 
								case 'datetime':
 | 
				
			||||||
@ -246,12 +246,12 @@ class Database
 | 
				
			|||||||
				elseif ($replacement === 'NULL')
 | 
									elseif ($replacement === 'NULL')
 | 
				
			||||||
					return 'NULL';
 | 
										return 'NULL';
 | 
				
			||||||
				else
 | 
									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;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case 'float':
 | 
								case 'float':
 | 
				
			||||||
				if (!is_numeric($replacement) && $replacement !== 'NULL')
 | 
									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';
 | 
									return $replacement !== 'NULL' ? (string) (float) $replacement : 'NULL';
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -271,7 +271,7 @@ class Database
 | 
				
			|||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			default:
 | 
								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;
 | 
								break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -289,7 +289,7 @@ class Database
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// Please, just use new style queries.
 | 
							// Please, just use new style queries.
 | 
				
			||||||
		if (strpos($db_string, '\'') !== false && !$security_override)
 | 
							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))
 | 
							if (!$security_override && !empty($db_values))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@ -313,7 +313,7 @@ class Database
 | 
				
			|||||||
		catch (Exception $e)
 | 
							catch (Exception $e)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			$clean_sql = implode("\n", array_map('trim', explode("\n", $db_string)));
 | 
								$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;
 | 
							return $return;
 | 
				
			||||||
@ -327,7 +327,7 @@ class Database
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		// Please, just use new style queries.
 | 
							// Please, just use new style queries.
 | 
				
			||||||
		if (strpos($db_string, '\'') !== false)
 | 
							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.
 | 
							// Save some values for use in the callback function.
 | 
				
			||||||
		$this->db_callback = [$db_values, $this->connection];
 | 
							$this->db_callback = [$db_values, $this->connection];
 | 
				
			||||||
 | 
				
			|||||||
@ -24,7 +24,7 @@ class Registry
 | 
				
			|||||||
	public static function get($key)
 | 
						public static function get($key)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (!isset(self::$storage[$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];
 | 
							return self::$storage[$key];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -32,7 +32,7 @@ class Registry
 | 
				
			|||||||
	public static function remove($key)
 | 
						public static function remove($key)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (!isset(self::$storage[$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]);
 | 
							unset(self::$storage[$key]);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,7 +33,7 @@ class Session
 | 
				
			|||||||
	public static function getSessionToken()
 | 
						public static function getSessionToken()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (empty($_SESSION['session_token']))
 | 
							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'];
 | 
							return $_SESSION['session_token'];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -41,7 +41,7 @@ class Session
 | 
				
			|||||||
	public static function getSessionTokenKey()
 | 
						public static function getSessionTokenKey()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (empty($_SESSION['session_token_key']))
 | 
							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'];
 | 
							return $_SESSION['session_token_key'];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -276,7 +276,7 @@ class Tag
 | 
				
			|||||||
			$data);
 | 
								$data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!$res)
 | 
							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();
 | 
							$data['id_tag'] = $db->insert_id();
 | 
				
			||||||
		return $return_format === 'object' ? new Tag($data) : $data;
 | 
							return $return_format === 'object' ? new Tag($data) : $data;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user