Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
12a65410
Commit
12a65410
authored
10 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
file: Reimplement zip export for cli file module
parent
f62186d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
setup/cli/modules/class.module.php
+3
-4
3 additions, 4 deletions
setup/cli/modules/class.module.php
setup/cli/modules/file.php
+41
-5
41 additions, 5 deletions
setup/cli/modules/file.php
with
44 additions
and
9 deletions
setup/cli/modules/class.module.php
+
3
−
4
View file @
12a65410
...
@@ -92,11 +92,10 @@ class Option {
...
@@ -92,11 +92,10 @@ class Option {
class
OutputStream
{
class
OutputStream
{
var
$stream
;
var
$stream
;
function
OutputStream
()
{
call_user_func_array
(
array
(
$this
,
'__construct'
),
func_get_args
());
}
function
__construct
(
$stream
)
{
function
__construct
(
$stream
)
{
$this
->
stream
=
fopen
(
$stream
,
'w'
);
if
(
!
(
$this
->
stream
=
fopen
(
$stream
,
'w'
)))
throw
new
Exception
(
sprintf
(
'%s: Cannot open for writing'
,
$stream
));
}
}
function
write
(
$what
)
{
function
write
(
$what
)
{
...
...
This diff is collapsed.
Click to expand it.
setup/cli/modules/file.php
+
41
−
5
View file @
12a65410
...
@@ -12,6 +12,7 @@ class FileManager extends Module {
...
@@ -12,6 +12,7 @@ class FileManager extends Module {
'list'
=>
'List files matching criteria'
,
'list'
=>
'List files matching criteria'
,
'export'
=>
'Export files from the system'
,
'export'
=>
'Export files from the system'
,
'import'
=>
'Load files exported via `export`'
,
'import'
=>
'Load files exported via `export`'
,
'zip'
=>
'Create a zip file of the matching files'
,
'dump'
=>
'Dump file content to stdout'
,
'dump'
=>
'Dump file content to stdout'
,
'load'
=>
'Load file contents from stdin'
,
'load'
=>
'Load file contents from stdin'
,
'migrate'
=>
'Migrate a file to another backend'
,
'migrate'
=>
'Migrate a file to another backend'
,
...
@@ -210,6 +211,9 @@ class FileManager extends Module {
...
@@ -210,6 +211,9 @@ class FileManager extends Module {
foreach
(
$files
as
$m
)
{
foreach
(
$files
as
$m
)
{
$f
=
AttachmentFile
::
lookup
(
$m
->
id
);
$f
=
AttachmentFile
::
lookup
(
$m
->
id
);
if
(
$options
[
'verbose'
])
$this
->
stderr
->
write
(
$m
->
name
.
"
\n
"
);
// TODO: Log %attachment and %ticket_attachment entries
// TODO: Log %attachment and %ticket_attachment entries
$info
=
array
(
'file'
=>
$f
->
getInfo
());
$info
=
array
(
'file'
=>
$f
->
getInfo
());
foreach
(
$m
->
tickets
as
$t
)
foreach
(
$m
->
tickets
as
$t
)
...
@@ -242,8 +246,8 @@ class FileManager extends Module {
...
@@ -242,8 +246,8 @@ class FileManager extends Module {
if
(
!
$options
[
'file'
]
||
$options
[
'file'
]
==
'-'
)
if
(
!
$options
[
'file'
]
||
$options
[
'file'
]
==
'-'
)
$options
[
'file'
]
=
'php://stdin'
;
$options
[
'file'
]
=
'php://stdin'
;
if
(
!
(
$stream
=
fopen
(
$options
[
'file'
],
'
w
b'
)))
if
(
!
(
$stream
=
fopen
(
$options
[
'file'
],
'
r
b'
)))
$this
->
fail
(
$options
[
'file'
]
.
': Unable to open
file for ex
port stream'
);
$this
->
fail
(
$options
[
'file'
]
.
': Unable to open
im
port stream'
);
while
(
true
)
{
while
(
true
)
{
// Read the file header
// Read the file header
...
@@ -381,13 +385,45 @@ class FileManager extends Module {
...
@@ -381,13 +385,45 @@ class FileManager extends Module {
}
}
break
;
break
;
case
'zip'
:
// Create a temporary ZIP file
$files
=
FileModel
::
objects
();
$this
->
_applyCriteria
(
$options
,
$files
);
if
(
!
$options
[
'file'
])
$this
->
fail
(
'Please specify zip file with `-f`'
);
$zip
=
new
ZipArchive
();
if
(
true
!==
(
$reason
=
$zip
->
open
(
$options
[
'file'
],
ZipArchive
::
CREATE
)))
$this
->
fail
(
$reason
.
': Unable to create zip file'
);
foreach
(
$files
as
$m
)
{
$f
=
AttachmentFile
::
lookup
(
$m
->
id
);
if
(
$options
[
'verbose'
])
$this
->
stderr
->
write
(
$m
->
name
.
"
\n
"
);
$name
=
Format
::
encode
(
sprintf
(
'%d-%s'
,
$f
->
getId
(),
$f
->
getName
()
),
'utf-8'
,
'cp437'
);
$zip
->
addFromString
(
$name
,
$f
->
getData
());
}
$zip
->
close
();
break
;
case
'expunge'
:
case
'expunge'
:
$files
=
FileModel
::
objects
();
$files
=
FileModel
::
objects
();
$this
->
_applyCriteria
(
$options
,
$files
);
$this
->
_applyCriteria
(
$options
,
$files
);
foreach
(
$files
as
$f
)
{
foreach
(
$files
as
$m
)
{
$f
->
tickets
->
expunge
();
// Drop associated attachment links
$f
->
unlink
()
&&
$f
->
delete
();
$m
->
tickets
->
expunge
();
$f
=
AttachmentFile
::
lookup
(
$m
->
id
);
// Drop file contents
if
(
$bk
=
$f
->
open
())
$bk
->
unlink
();
// Drop file record
$f
->
delete
();
}
}
}
}
}
}
...
...
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