Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
42cd9962
Commit
42cd9962
authored
12 years ago
by
Sean Comeau
Browse files
Options
Downloads
Patches
Plain Diff
Use a custom exception instead of adding a delimiter to the error message
parent
ba9c9674
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/setup.php
+31
-8
31 additions, 8 deletions
lib/setup.php
with
31 additions
and
8 deletions
lib/setup.php
+
31
−
8
View file @
42cd9962
<?php
class
HintException
extends
Exception
{
private
$hint
;
public
function
__construct
(
$message
,
$hint
,
$code
=
0
,
Exception
$previous
=
null
)
{
$this
->
hint
=
$hint
;
parent
::
__construct
(
$message
,
$code
,
$previous
);
}
public
function
__toString
()
{
return
__CLASS__
.
": [
{
$this
->
code
}
]:
{
$this
->
message
}
(
{
$this
->
hint
}
)
\n
"
;
}
public
function
getHint
()
{
return
$this
->
hint
;
}
}
class
OC_Setup
{
public
static
function
install
(
$options
)
{
$error
=
array
();
...
...
@@ -69,11 +87,16 @@ class OC_Setup {
try
{
self
::
setupMySQLDatabase
(
$dbhost
,
$dbuser
,
$dbpass
,
$dbname
,
$dbtableprefix
,
$username
);
}
catch
(
HintException
$e
)
{
$error
[]
=
array
(
'error'
=>
$e
->
getMessage
(),
'hint'
=>
$e
->
getHint
()
);
return
(
$error
);
}
catch
(
Exception
$e
)
{
$msgs
=
explode
(
'|'
,
$e
->
getMessage
());
$error
[]
=
array
(
'error'
=>
$
msgs
[
0
]
,
'hint'
=>
$msgs
[
1
]
'error'
=>
$
e
->
getMessage
()
,
'hint'
=>
''
);
return
(
$error
);
}
...
...
@@ -167,7 +190,7 @@ class OC_Setup {
//check if the database user has admin right
$connection
=
@
mysql_connect
(
$dbhost
,
$dbuser
,
$dbpass
);
if
(
!
$connection
)
{
throw
new
Exception
(
'MySQL username and/or password not valid
|
You need to enter either an existing account or the administrator.'
);
throw
new
Hint
Exception
(
'MySQL username and/or password not valid
'
,
'
You need to enter either an existing account or the administrator.'
);
}
$oldUser
=
OC_Config
::
getValue
(
'dbuser'
,
false
);
...
...
@@ -231,12 +254,12 @@ class OC_Setup {
$query
=
"CREATE USER '
$name
'@'localhost' IDENTIFIED BY '
$password
'"
;
$result
=
mysql_query
(
$query
,
$connection
);
if
(
!
$result
)
{
throw
new
Exception
(
"MySQL user '"
.
"
$name
"
.
"'@'localhost' already exists
|
Delete this user from MySQL."
);
throw
new
Hint
Exception
(
"MySQL user '"
.
"
$name
"
.
"'@'localhost' already exists
"
,
"
Delete this user from MySQL."
);
}
$query
=
"CREATE USER '
$name
'@'%' IDENTIFIED BY '
$password
'"
;
$result
=
mysql_query
(
$query
,
$connection
);
if
(
!
$result
)
{
throw
new
Exception
(
"MySQL user '"
.
"
$name
"
.
"'@'%' already exists
|
Delete this user from MySQL."
);
throw
new
Hint
Exception
(
"MySQL user '"
.
"
$name
"
.
"'@'%' already exists
"
,
"
Delete this user from MySQL."
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment