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
14397989
Commit
14397989
authored
11 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
Move export logic to class Exporter
This will facilitate a web-based export significantly easier
parent
bc9de476
No related branches found
No related tags found
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/class.export.php
+79
-2
79 additions, 2 deletions
include/class.export.php
setup/cli/modules/export.php
+4
-68
4 additions, 68 deletions
setup/cli/modules/export.php
with
83 additions
and
70 deletions
include/class.export.php
+
79
−
2
View file @
14397989
<?php
/*************************************************************************
class.export.php
Exports stuff (details to follow)
Jared Hancock <jared@osticket.com>
...
...
@@ -15,7 +15,7 @@
**********************************************************************/
class
Export
{
/* static */
function
dumpQuery
(
$sql
,
$headers
,
$how
=
'csv'
,
$filter
=
false
)
{
$exporters
=
array
(
'csv'
=>
CsvResultsExporter
,
...
...
@@ -137,3 +137,80 @@ class JsonResultsExporter extends ResultSetExporter {
echo
$exp
->
encode
(
$rows
);
}
}
require_once
INCLUDE_DIR
.
'class.json.php'
;
require_once
INCLUDE_DIR
.
'class.migrater.php'
;
require_once
INCLUDE_DIR
.
'class.signal.php'
;
class
DatabaseExporter
{
var
$stream
;
var
$tables
=
array
(
CONFIG_TABLE
,
SYSLOG_TABLE
,
FILE_TABLE
,
FILE_CHUNK_TABLE
,
STAFF_TABLE
,
DEPT_TABLE
,
TOPIC_TABLE
,
GROUP_TABLE
,
GROUP_DEPT_TABLE
,
TEAM_TABLE
,
TEAM_MEMBER_TABLE
,
FAQ_TABLE
,
FAQ_ATTACHMENT_TABLE
,
FAQ_TOPIC_TABLE
,
FAQ_CATEGORY_TABLE
,
CANNED_TABLE
,
CANNED_ATTACHMENT_TABLE
,
TICKET_TABLE
,
TICKET_THREAD_TABLE
,
TICKET_ATTACHMENT_TABLE
,
TICKET_PRIORITY_TABLE
,
TICKET_LOCK_TABLE
,
TICKET_EVENT_TABLE
,
TICKET_EMAIL_INFO_TABLE
,
EMAIL_TABLE
,
EMAIL_TEMPLATE_TABLE
,
EMAIL_TEMPLATE_GRP_TABLE
,
FILTER_TABLE
,
FILTER_RULE_TABLE
,
SLA_TABLE
,
API_KEY_TABLE
,
TIMEZONE_TABLE
,
SESSION_TABLE
,
PAGE_TABLE
);
function
DatabaseExporter
(
$stream
)
{
$this
->
stream
=
$stream
;
}
function
write_block
(
$what
)
{
fwrite
(
$this
->
stream
,
JsonDataEncoder
::
encode
(
$what
));
fwrite
(
$this
->
stream
,
"
\x1e
"
);
}
function
dump
(
$error_stream
)
{
// Allow plugins to change the tables exported
Signal
::
send
(
'export.tables'
,
$this
,
$this
->
tables
);
$header
=
array
(
array
(
OSTICKET_BACKUP_SIGNATURE
,
OSTICKET_BACKUP_VERSION
),
array
(
'version'
=>
THIS_VERSION
,
'table_prefix'
=>
TABLE_PREFIX
,
'salt'
=>
SECRET_SALT
,
'dbtype'
=>
DBTYPE
,
'streams'
=>
DatabaseMigrater
::
getUpgradeStreams
(
UPGRADE_DIR
.
'streams/'
),
),
);
$this
->
write_block
(
$header
);
foreach
(
$this
->
tables
as
$t
)
{
if
(
$error_stream
)
$error_stream
->
write
(
"
$t
\n
"
);
// Inspect schema
$table
=
$indexes
=
array
();
$res
=
db_query
(
"show columns from
$t
"
);
while
(
$field
=
db_fetch_array
(
$res
))
$table
[]
=
$field
;
$res
=
db_query
(
"show indexes from
$t
"
);
while
(
$col
=
db_fetch_array
(
$res
))
$indexes
[]
=
$col
;
$res
=
db_query
(
"select * from
$t
"
);
$types
=
array
();
if
(
!
$table
)
{
if
(
$error_stream
)
$error_stream
->
write
(
$t
.
': Cannot export table with no fields'
.
"
\n
"
);
die
();
}
$this
->
write_block
(
array
(
'table'
,
substr
(
$t
,
strlen
(
TABLE_PREFIX
)),
$table
,
$indexes
));
// Dump row data
while
(
$row
=
db_fetch_row
(
$res
))
$this
->
write_block
(
$row
);
$this
->
write_block
(
array
(
'end-table'
));
}
}
}
This diff is collapsed.
Click to expand it.
setup/cli/modules/export.php
+
4
−
68
View file @
14397989
...
...
@@ -17,9 +17,7 @@ require_once dirname(__file__) . "/class.module.php";
require_once
dirname
(
__file__
)
.
'/../../../main.inc.php'
;
require_once
INCLUDE_DIR
.
'class.json.php'
;
require_once
INCLUDE_DIR
.
'class.migrater.php'
;
require_once
INCLUDE_DIR
.
'class.signal.php'
;
require_once
INCLUDE_DIR
.
'class.export.php'
;
define
(
'OSTICKET_BACKUP_SIGNATURE'
,
'osTicket-Backup'
);
define
(
'OSTICKET_BACKUP_VERSION'
,
'A'
);
...
...
@@ -28,17 +26,6 @@ class Exporter extends Module {
var
$prologue
=
"Dumps the osTicket database in formats suitable for the importer"
;
var
$tables
=
array
(
CONFIG_TABLE
,
SYSLOG_TABLE
,
FILE_TABLE
,
FILE_CHUNK_TABLE
,
STAFF_TABLE
,
DEPT_TABLE
,
TOPIC_TABLE
,
GROUP_TABLE
,
GROUP_DEPT_TABLE
,
TEAM_TABLE
,
TEAM_MEMBER_TABLE
,
FAQ_TABLE
,
FAQ_ATTACHMENT_TABLE
,
FAQ_TOPIC_TABLE
,
FAQ_CATEGORY_TABLE
,
CANNED_TABLE
,
CANNED_ATTACHMENT_TABLE
,
TICKET_TABLE
,
TICKET_THREAD_TABLE
,
TICKET_ATTACHMENT_TABLE
,
TICKET_PRIORITY_TABLE
,
TICKET_LOCK_TABLE
,
TICKET_EVENT_TABLE
,
TICKET_EMAIL_INFO_TABLE
,
EMAIL_TABLE
,
EMAIL_TEMPLATE_TABLE
,
EMAIL_TEMPLATE_GRP_TABLE
,
FILTER_TABLE
,
FILTER_RULE_TABLE
,
SLA_TABLE
,
API_KEY_TABLE
,
TIMEZONE_TABLE
,
SESSION_TABLE
,
PAGE_TABLE
);
var
$options
=
array
(
'stream'
=>
array
(
'-o'
,
'--output'
,
'default'
=>
'php://stdout'
,
'help'
=>
"File or stream to receive the exported output. As a
...
...
@@ -47,66 +34,15 @@ class Exporter extends Module {
'help'
=>
"Send zlib compress data to the output stream"
),
);
var
$stream
;
function
write_block
(
$what
)
{
fwrite
(
$this
->
stream
,
JsonDataEncoder
::
encode
(
$what
));
fwrite
(
$this
->
stream
,
"
\x1e
"
);
}
function
run
(
$args
,
$options
)
{
global
$ost
;
$stream
=
$options
[
'stream'
];
if
(
$options
[
'compress'
])
$stream
=
"compress.zlib://
$stream
"
;
$this
->
stream
=
fopen
(
$stream
,
'w'
);
// Allow plugins to change the tables exported
Signal
::
send
(
'export.tables'
,
$this
,
$this
->
tables
);
$header
=
array
(
array
(
OSTICKET_BACKUP_SIGNATURE
,
OSTICKET_BACKUP_VERSION
),
array
(
'version'
=>
THIS_VERSION
,
'table_prefix'
=>
TABLE_PREFIX
,
'salt'
=>
SECRET_SALT
,
'dbtype'
=>
DBTYPE
,
'streams'
=>
DatabaseMigrater
::
getUpgradeStreams
(
UPGRADE_DIR
.
'streams/'
),
),
);
$this
->
write_block
(
$header
);
foreach
(
$this
->
tables
as
$t
)
{
$this
->
stderr
->
write
(
"
$t
\n
"
);
// Inspect schema
$table
=
$indexes
=
array
();
$res
=
db_query
(
"show columns from
$t
"
);
while
(
$field
=
db_fetch_array
(
$res
))
$table
[]
=
$field
;
$res
=
db_query
(
"show indexes from
$t
"
);
while
(
$col
=
db_fetch_array
(
$res
))
$indexes
[]
=
$col
;
$res
=
db_query
(
"select * from
$t
"
);
$types
=
array
();
if
(
!
$table
)
{
$this
->
stderr
->
write
(
$t
.
': Cannot export table with no fields'
.
"
\n
"
);
die
();
}
$this
->
write_block
(
array
(
'table'
,
substr
(
$t
,
strlen
(
TABLE_PREFIX
)),
$table
,
$indexes
));
// Dump row data
while
(
$row
=
db_fetch_row
(
$res
))
$this
->
write_block
(
$row
);
$stream
=
fopen
(
$stream
,
'w'
);
$this
->
write_block
(
array
(
'end-table'
)
);
}
$x
=
new
DatabaseExporter
(
$stream
);
$x
->
dump
(
$this
->
stderr
);
}
}
...
...
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