Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
03ede650
Commit
03ede650
authored
12 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
Use an abstract Config class and auto-created records
parent
db81f071
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/class.config.php
+92
-55
92 additions, 55 deletions
include/class.config.php
include/class.osticket.php
+3
-6
3 additions, 6 deletions
include/class.osticket.php
main.inc.php
+0
-6
0 additions, 6 deletions
main.inc.php
with
95 additions
and
67 deletions
include/class.config.php
+
92
−
55
View file @
03ede650
...
@@ -17,45 +17,31 @@
...
@@ -17,45 +17,31 @@
require_once
(
INCLUDE_DIR
.
'class.email.php'
);
require_once
(
INCLUDE_DIR
.
'class.email.php'
);
class
Config
{
class
Config
{
var
$section
=
null
;
var
$config
=
array
();
var
$config
=
array
();
var
$defaultDept
;
//Default Department
var
$section
=
null
;
# Default namespace ('core')
var
$defaultSLA
;
//Default SLA
var
$table
=
'config'
;
# Table name (with prefix)
var
$defaultEmail
;
//Default Email
var
$section_column
=
'namespace'
;
# namespace column name
var
$alertEmail
;
//Alert Email
var
$defaultSMTPEmail
;
//Default SMTP Email
function
Config
(
$section
=
null
)
{
function
Config
(
$section
=
null
)
{
$this
->
load
(
$section
);
$this
->
load
(
$section
?
$section
:
$this
->
section
);
}
}
function
load
(
$section
=
null
)
{
function
load
(
$section
=
null
)
{
$this
->
section
=
$section
;
$sql
=
'SELECT id, `key`, namespace, value FROM '
.
TABLE_PREFIX
.
'config'
;
if
(
$section
)
if
(
$section
)
$
sql
.
=
' WHERE `namespace` = '
.
db_input
(
$section
)
;
$
this
->
section
=
$section
;
if
(
!
(
$res
=
db_query
(
$sql
))
||
!
db_num_rows
(
$res
)
)
if
(
$this
->
section
===
null
)
return
false
;
return
false
;
while
(
$row
=
db_fetch_array
(
$res
))
$sql
=
'SELECT id, `key`, value FROM '
.
$this
->
table
$this
->
config
[
$row
[
'namespace'
]
.
':'
.
$row
[
'key'
]]
=
$row
;
.
' WHERE `'
.
$this
->
section_column
.
'` = '
.
db_input
(
$this
->
section
)
;
$sql
=
'SELECT (TIME_TO_SEC(TIMEDIFF(NOW(), UTC_TIMESTAMP()))/3600) as db_tz_offset'
;
if
(
!
(
$res
=
db_query
(
$sql
))
||
!
db_num_rows
(
$res
))
if
(
!
(
$res
=
db_query
(
$sql
))
||
!
db_num_rows
(
$res
))
return
false
;
return
false
;
//Get the default time zone
while
(
$row
=
db_fetch_array
(
$res
))
// We can't JOIN timezone table above due to upgrade support.
$this
->
config
[
$row
[
'key'
]]
=
$row
;
if
(
$this
->
get
(
'default_timezone_id'
))
$this
->
config
[
'core:tz_offset'
]
=
Timezone
::
getOffsetById
(
$this
->
get
(
'default_timezone_id'
));
else
$this
->
config
[
'core:tz_offset'
]
=
0
;
return
true
;
return
true
;
}
}
...
@@ -68,19 +54,38 @@ class Config {
...
@@ -68,19 +54,38 @@ class Config {
return
$this
->
section
;
return
$this
->
section
;
}
}
function
get
(
$key
,
$section
=
'core'
)
{
function
get
(
$key
,
$default
=
null
)
{
return
$this
->
config
[
$section
.
':'
.
$key
][
'value'
];
if
(
isset
(
$this
->
config
[
$key
]))
return
$this
->
config
[
$key
][
'value'
];
else
return
$this
->
set
(
$key
,
$default
);
}
function
set
(
$key
,
$value
)
{
return
(
$this
->
update
(
$key
,
$value
))
?
$value
:
null
;
}
}
function
update
(
$key
,
$value
,
$section
=
'core'
)
{
function
create
(
$key
,
$value
)
{
if
(
!
isset
(
$this
->
config
[
$section
.
':'
.
$key
]))
$res
=
db_query
(
'INSERT INTO '
.
$this
->
table
.
' SET `'
.
$this
->
section_column
.
'`='
.
db_input
(
$this
->
section
)
.
', `key`='
.
db_input
(
$key
)
.
', value='
.
db_input
(
$value
));
if
(
!
db_query
(
$res
)
||
!
(
$id
=
db_insert_id
()))
return
false
;
return
false
;
$setting
=
&
$this
->
config
[
$section
.
':'
.
$key
];
$this
->
config
[
$key
]
=
array
(
'key'
=>
$key
,
'value'
=>
$value
,
'id'
=>
$id
);
return
true
;
}
function
update
(
$key
,
$value
)
{
if
(
!
isset
(
$this
->
config
[
$key
]))
return
$this
->
create
(
$key
,
$value
);
$setting
=
&
$this
->
config
[
$key
];
if
(
$setting
[
'value'
]
==
$value
)
if
(
$setting
[
'value'
]
==
$value
)
return
true
;
return
true
;
if
(
!
db_query
(
'UPDATE '
.
CONFIG_TABLE
.
' SET updated=NOW(), value='
if
(
!
db_query
(
'UPDATE '
.
$this
->
table
.
' SET updated=NOW(), value='
.
db_input
(
$value
)
.
' WHERE id='
.
db_input
(
$setting
[
'id'
])))
.
db_input
(
$value
)
.
' WHERE id='
.
db_input
(
$setting
[
'id'
])))
return
false
;
return
false
;
...
@@ -88,12 +93,39 @@ class Config {
...
@@ -88,12 +93,39 @@ class Config {
return
true
;
return
true
;
}
}
function
updateAll
(
$updates
,
$section
=
'core'
)
{
function
updateAll
(
$updates
)
{
foreach
(
$updates
as
$key
=>
$value
)
foreach
(
$updates
as
$key
=>
$value
)
if
(
!
$this
->
update
(
$key
,
$value
,
$section
))
if
(
!
$this
->
update
(
$key
,
$value
))
return
false
;
return
false
;
return
true
;
return
true
;
}
}
}
class
OsticketConfig
extends
Config
{
var
$table
=
CONFIG_TABLE
;
var
$section
=
'core'
;
var
$defaultDept
;
//Default Department
var
$defaultSLA
;
//Default SLA
var
$defaultEmail
;
//Default Email
var
$alertEmail
;
//Alert Email
var
$defaultSMTPEmail
;
//Default SMTP Email
function
load
(
$section
)
{
parent
::
load
(
$section
);
//Get the default time zone
// We can't JOIN timezone table above due to upgrade support.
if
(
$this
->
get
(
'default_timezone_id'
))
$this
->
config
[
'tz_offset'
]
=
Timezone
::
getOffsetById
(
$this
->
get
(
'default_timezone_id'
));
else
$this
->
config
[
'tz_offset'
]
=
0
;
return
true
;
}
function
isHelpDeskOffline
()
{
function
isHelpDeskOffline
()
{
return
!
$this
->
isOnline
();
return
!
$this
->
isOnline
();
...
@@ -104,7 +136,7 @@ class Config {
...
@@ -104,7 +136,7 @@ class Config {
}
}
function
isOnline
()
{
function
isOnline
()
{
return
(
$this
->
get
(
'isonline'
));
return
(
$this
->
get
(
'isonline'
,
false
));
}
}
function
isKnowledgebaseEnabled
()
{
function
isKnowledgebaseEnabled
()
{
...
@@ -124,15 +156,21 @@ class Config {
...
@@ -124,15 +156,21 @@ class Config {
return
$row
[
0
];
return
$row
[
0
];
}
}
function
getSchemaSignature
(
$section
=
'core'
)
{
function
getSchemaSignature
(
$section
=
null
)
{
if
(
$this
->
get
(
'schema_signature'
,
$section
))
if
(
!
$section
&&
(
$v
=
$this
->
get
(
'schema_signature'
)))
return
$this
->
get
(
'schema_signature'
,
$section
);
return
$v
;
// 1.7 after namespaced configuration, other namespace
$sql
=
'SELECT value FROM '
.
$this
->
table
.
'WHERE `key` = "schema_signature" and namespace='
.
db_input
(
$section
);
if
((
$res
=
db_query
(
$sql
,
false
))
&&
(
$row
=
db_fetch_row
(
$res
)))
return
$row
[
0
];
// 1.7 before namespaced configuration
// 1.7 before namespaced configuration
$sql
=
'SELECT `schema_signature` FROM '
.
TABLE_PREFIX
.
'config '
$sql
=
'SELECT `schema_signature` FROM '
.
$this
->
table
.
'WHERE id=1'
;
.
'WHERE id=1'
;
if
((
$res
=
db_query
(
$sql
))
&&
(
$row
=
db_fetch_row
(
$res
)))
if
((
$res
=
db_query
(
$sql
,
false
))
&&
(
$row
=
db_fetch_row
(
$res
)))
return
$row
[
0
];
return
$row
[
0
];
// old version 1.6
// old version 1.6
...
@@ -140,7 +178,12 @@ class Config {
...
@@ -140,7 +178,12 @@ class Config {
}
}
function
getDBTZoffset
()
{
function
getDBTZoffset
()
{
return
$this
->
get
(
'db_tz_offset'
);
if
(
!
isset
(
$this
->
_db_tz_offset
))
{
$sql
=
'SELECT (TIME_TO_SEC(TIMEDIFF(NOW(), UTC_TIMESTAMP()))/3600) as db_tz_offset'
;
if
((
$res
=
db_query
(
$sql
))
&&
db_num_rows
(
$res
))
$this
->
_db_tz_offset
=
db_result
(
$res
);
}
return
$this
->
_db_tz_offset
;
}
}
/* Date & Time Formats */
/* Date & Time Formats */
...
@@ -162,11 +205,10 @@ class Config {
...
@@ -162,11 +205,10 @@ class Config {
return
$this
->
get
(
'daydatetime_format'
);
return
$this
->
get
(
'daydatetime_format'
);
}
}
function
getConfigInfo
(
$section
=
'core'
)
{
function
getConfigInfo
()
{
$info
=
array
();
$info
=
array
();
foreach
(
$this
->
config
as
$setting
)
foreach
(
$this
->
config
as
$key
=>
$setting
)
if
(
$setting
[
'namespace'
]
==
$section
)
$info
[
$key
]
=
$setting
[
'value'
];
$info
[
$setting
[
'key'
]]
=
$setting
[
'value'
];
return
$info
;
return
$info
;
}
}
...
@@ -656,7 +698,7 @@ class Config {
...
@@ -656,7 +698,7 @@ class Config {
'daydatetime_format'
=>
$vars
[
'daydatetime_format'
],
'daydatetime_format'
=>
$vars
[
'daydatetime_format'
],
'default_timezone_id'
=>
$vars
[
'default_timezone_id'
],
'default_timezone_id'
=>
$vars
[
'default_timezone_id'
],
'enable_daylight_saving'
=>
isset
(
$vars
[
'enable_daylight_saving'
])
?
1
:
0
,
'enable_daylight_saving'
=>
isset
(
$vars
[
'enable_daylight_saving'
])
?
1
:
0
,
)
,
'core'
);
));
}
}
function
updateTicketsSettings
(
$vars
,
&
$errors
)
{
function
updateTicketsSettings
(
$vars
,
&
$errors
)
{
...
@@ -728,7 +770,7 @@ class Config {
...
@@ -728,7 +770,7 @@ class Config {
'allow_email_attachments'
=>
isset
(
$vars
[
'allow_email_attachments'
])
?
1
:
0
,
'allow_email_attachments'
=>
isset
(
$vars
[
'allow_email_attachments'
])
?
1
:
0
,
'allow_online_attachments'
=>
isset
(
$vars
[
'allow_online_attachments'
])
?
1
:
0
,
'allow_online_attachments'
=>
isset
(
$vars
[
'allow_online_attachments'
])
?
1
:
0
,
'allow_online_attachments_onlogin'
=>
isset
(
$vars
[
'allow_online_attachments_onlogin'
])
?
1
:
0
,
'allow_online_attachments_onlogin'
=>
isset
(
$vars
[
'allow_online_attachments_onlogin'
])
?
1
:
0
,
)
,
'core'
);
));
}
}
...
@@ -757,7 +799,7 @@ class Config {
...
@@ -757,7 +799,7 @@ class Config {
'enable_mail_polling'
=>
isset
(
$vars
[
'enable_mail_polling'
])
?
1
:
0
,
'enable_mail_polling'
=>
isset
(
$vars
[
'enable_mail_polling'
])
?
1
:
0
,
'strip_quoted_reply'
=>
isset
(
$vars
[
'strip_quoted_reply'
])
?
1
:
0
,
'strip_quoted_reply'
=>
isset
(
$vars
[
'strip_quoted_reply'
])
?
1
:
0
,
'reply_separator'
=>
$vars
[
'reply_separator'
],
'reply_separator'
=>
$vars
[
'reply_separator'
],
)
,
'core'
);
));
}
}
function
updateAttachmentsSetting
(
$vars
,
&
$errors
)
{
function
updateAttachmentsSetting
(
$vars
,
&
$errors
)
{
...
@@ -796,7 +838,7 @@ class Config {
...
@@ -796,7 +838,7 @@ class Config {
'allow_email_attachments'
=>
isset
(
$vars
[
'allow_email_attachments'
])
?
1
:
0
,
'allow_email_attachments'
=>
isset
(
$vars
[
'allow_email_attachments'
])
?
1
:
0
,
'allow_online_attachments'
=>
isset
(
$vars
[
'allow_online_attachments'
])
?
1
:
0
,
'allow_online_attachments'
=>
isset
(
$vars
[
'allow_online_attachments'
])
?
1
:
0
,
'allow_online_attachments_onlogin'
=>
isset
(
$vars
[
'allow_online_attachments_onlogin'
])
?
1
:
0
,
'allow_online_attachments_onlogin'
=>
isset
(
$vars
[
'allow_online_attachments_onlogin'
])
?
1
:
0
,
)
,
'core'
);
));
}
}
function
updateAutoresponderSettings
(
$vars
,
&
$errors
)
{
function
updateAutoresponderSettings
(
$vars
,
&
$errors
)
{
...
@@ -808,7 +850,7 @@ class Config {
...
@@ -808,7 +850,7 @@ class Config {
'message_autoresponder'
=>
$vars
[
'message_autoresponder'
],
'message_autoresponder'
=>
$vars
[
'message_autoresponder'
],
'ticket_notice_active'
=>
$vars
[
'ticket_notice_active'
],
'ticket_notice_active'
=>
$vars
[
'ticket_notice_active'
],
'overlimit_notice_active'
=>
$vars
[
'overlimit_notice_active'
],
'overlimit_notice_active'
=>
$vars
[
'overlimit_notice_active'
],
)
,
'core'
);
));
}
}
...
@@ -819,7 +861,7 @@ class Config {
...
@@ -819,7 +861,7 @@ class Config {
return
$this
->
updateAll
(
array
(
return
$this
->
updateAll
(
array
(
'enable_kb'
=>
isset
(
$vars
[
'enable_kb'
])
?
1
:
0
,
'enable_kb'
=>
isset
(
$vars
[
'enable_kb'
])
?
1
:
0
,
'enable_premade'
=>
isset
(
$vars
[
'enable_premade'
])
?
1
:
0
,
'enable_premade'
=>
isset
(
$vars
[
'enable_premade'
])
?
1
:
0
,
)
,
'core'
);
));
}
}
...
@@ -897,12 +939,7 @@ class Config {
...
@@ -897,12 +939,7 @@ class Config {
'send_sys_errors'
=>
isset
(
$vars
[
'send_sys_errors'
])
?
1
:
0
,
'send_sys_errors'
=>
isset
(
$vars
[
'send_sys_errors'
])
?
1
:
0
,
'send_sql_errors'
=>
isset
(
$vars
[
'send_sql_errors'
])
?
1
:
0
,
'send_sql_errors'
=>
isset
(
$vars
[
'send_sql_errors'
])
?
1
:
0
,
'send_login_errors'
=>
isset
(
$vars
[
'send_login_errors'
])
?
1
:
0
,
'send_login_errors'
=>
isset
(
$vars
[
'send_login_errors'
])
?
1
:
0
,
),
'core'
);
));
}
/** static **/
function
lookup
(
$section
=
null
)
{
return
((
$cfg
=
new
Config
(
$section
))
&&
$cfg
->
getNamespace
()
==
$section
)
?
$cfg
:
null
;
}
}
}
}
?>
?>
This diff is collapsed.
Click to expand it.
include/class.osticket.php
+
3
−
6
View file @
03ede650
...
@@ -48,7 +48,7 @@ class osTicket {
...
@@ -48,7 +48,7 @@ class osTicket {
function
osTicket
()
{
function
osTicket
()
{
$this
->
config
=
Config
::
lookup
();
$this
->
config
=
new
OsticketConfig
();
//DB based session storage was added starting with v1.7
//DB based session storage was added starting with v1.7
if
(
$this
->
config
&&
!
$this
->
getConfig
()
->
getDBVersion
())
if
(
$this
->
config
&&
!
$this
->
getConfig
()
->
getDBVersion
())
...
@@ -64,11 +64,8 @@ class osTicket {
...
@@ -64,11 +64,8 @@ class osTicket {
}
}
function
isUpgradePending
()
{
function
isUpgradePending
()
{
foreach
(
Migrator
::
getUpgradeStreams
()
as
$stream
=>
$hash
)
return
strcasecmp
(
SCHEMA_SIGNATURE
,
if
(
strcasecmp
(
$hash
,
$this
->
getConfig
()
->
getSchemaSignature
());
$this
->
getConfig
()
->
get
(
'schema_signature'
,
$stream
)))
return
true
;
return
false
;
}
}
function
getSession
()
{
function
getSession
()
{
...
...
This diff is collapsed.
Click to expand it.
main.inc.php
+
0
−
6
View file @
03ede650
...
@@ -193,7 +193,6 @@
...
@@ -193,7 +193,6 @@
#Connect to the DB && get configuration from database
#Connect to the DB && get configuration from database
$ferror
=
null
;
$ferror
=
null
;
<<<<<<<
HEAD
$options
=
array
();
$options
=
array
();
if
(
defined
(
'DBSSLCA'
))
if
(
defined
(
'DBSSLCA'
))
$options
[
'ssl'
]
=
array
(
$options
[
'ssl'
]
=
array
(
...
@@ -206,12 +205,7 @@
...
@@ -206,12 +205,7 @@
$ferror
=
'Unable to connect to the database -'
.
db_connect_error
();
$ferror
=
'Unable to connect to the database -'
.
db_connect_error
();
}
elseif
(
!
db_select_database
(
DBNAME
))
{
}
elseif
(
!
db_select_database
(
DBNAME
))
{
$ferror
=
'Unknown or invalid database '
.
DBNAME
;
$ferror
=
'Unknown or invalid database '
.
DBNAME
;
}
elseif
(
!
(
$ost
=
osTicket
::
start
(
1
))
||
!
(
$cfg
=
$ost
->
getConfig
()))
{
=======
if
(
!
db_connect
(
DBHOST
,
DBUSER
,
DBPASS
)
||
!
db_select_database
(
DBNAME
))
{
$ferror
=
'Unable to connect to the database'
;
}
elseif
(
!
(
$ost
=
osTicket
::
start
())
||
!
(
$cfg
=
$ost
->
getConfig
()))
{
}
elseif
(
!
(
$ost
=
osTicket
::
start
())
||
!
(
$cfg
=
$ost
->
getConfig
()))
{
>>>>>>>
Federate
configuration
settings
$ferror
=
'Unable to load config info from DB. Get tech support.'
;
$ferror
=
'Unable to load config info from DB. Get tech support.'
;
}
}
...
...
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