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
7c4abfa3
Commit
7c4abfa3
authored
10 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
Implement file content loading
parent
f99ca0c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
setup/cli/modules/file.php
+60
-4
60 additions, 4 deletions
setup/cli/modules/file.php
with
60 additions
and
4 deletions
setup/cli/modules/file.php
+
60
−
4
View file @
7c4abfa3
...
@@ -11,7 +11,9 @@ class FileManager extends Module {
...
@@ -11,7 +11,9 @@ class FileManager extends Module {
'options'
=>
array
(
'options'
=>
array
(
'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`'
,
'dump'
=>
'Dump file content to stdout'
,
'dump'
=>
'Dump file content to stdout'
,
'load'
=>
'Load file contents from stdin'
,
'migrate'
=>
'Migrate a file to another backend'
,
'migrate'
=>
'Migrate a file to another backend'
,
'backends'
=>
'List configured storage backends'
,
'backends'
=>
'List configured storage backends'
,
'expunge'
=>
'Remove matching files from the system'
,
'expunge'
=>
'Remove matching files from the system'
,
...
@@ -69,8 +71,11 @@ class FileManager extends Module {
...
@@ -69,8 +71,11 @@ class FileManager extends Module {
$files
=
FileModel
::
objects
();
$files
=
FileModel
::
objects
();
$this
->
_applyCriteria
(
$options
,
$files
);
$this
->
_applyCriteria
(
$options
,
$files
);
foreach
(
$files
as
$f
)
{
foreach
(
$files
as
$f
)
{
printf
(
"% 5d %s % 8d %s % 1
2
s %s
\n
"
,
$f
->
id
,
$f
->
bk
,
printf
(
"% 5d %s % 8d %s % 1
6
s %s
\n
"
,
$f
->
id
,
$f
->
bk
,
$f
->
size
,
$f
->
created
,
$f
->
type
,
$f
->
name
);
$f
->
size
,
$f
->
created
,
$f
->
type
,
$f
->
name
);
if
(
$f
->
attrs
)
{
printf
(
" %s
\n
"
,
$f
->
attrs
);
}
}
}
break
;
break
;
...
@@ -85,6 +90,57 @@ class FileManager extends Module {
...
@@ -85,6 +90,57 @@ class FileManager extends Module {
$bk
->
passthru
();
$bk
->
passthru
();
break
;
break
;
case
'load'
:
// Load file content from STDIN
$files
=
FileModel
::
objects
();
$this
->
_applyCriteria
(
$options
,
$files
);
if
(
$files
->
count
()
!=
1
)
$this
->
fail
(
'Criteria must select exactly 1 file'
);
$f
=
AttachmentFile
::
lookup
(
$files
[
0
]
->
id
);
try
{
if
(
$bk
=
$f
->
open
())
$bk
->
unlink
();
}
catch
(
Exception
$e
)
{}
if
(
$options
[
'backend'
])
$bk
=
FileStorageBackend
::
lookup
(
$options
[
'backend'
],
$f
);
else
// Use the system default
$bk
=
AttachmentFile
::
getBackendForFile
(
$f
);
$type
=
false
;
$finfo
=
new
finfo
(
FILEINFO_MIME_TYPE
);
if
(
$options
[
'file'
]
&&
$options
[
'file'
]
!=
'-'
)
{
if
(
!
$bk
->
upload
(
$options
[
'file'
]))
$this
->
fail
(
'Unable to upload file contents to backend'
);
$type
=
$finfo
->
file
(
$options
[
'file'
]);
}
else
{
$stream
=
fopen
(
'php://stdin'
,
'rb'
);
while
(
$block
=
fread
(
$stream
,
$bk
->
getBlockSize
()))
{
if
(
!
$bk
->
write
(
$block
))
$this
->
fail
(
'Unable to send file contents to backend'
);
if
(
!
$type
)
$type
=
$finfo
->
buffer
(
$block
);
}
if
(
!
$bk
->
flush
())
$this
->
fail
(
'Unable to commit file contents to backend'
);
}
// TODO: Update file metadata
$sql
=
'UPDATE '
.
FILE_TABLE
.
' SET bk='
.
db_input
(
$bk
->
getBkChar
())
.
', created=CURRENT_TIMESTAMP'
.
', type='
.
db_input
(
$type
)
.
' WHERE id='
.
db_input
(
$f
->
getId
());
if
(
!
db_query
(
$sql
)
||
db_affected_rows
()
!=
1
)
$this
->
fail
(
'Unable to update file metadata'
);
$this
->
stdout
->
write
(
"Successfully saved contents
\n
"
);
break
;
case
'migrate'
:
case
'migrate'
:
if
(
!
$options
[
'to'
])
if
(
!
$options
[
'to'
])
$this
->
fail
(
'Please specify a target backend for migration'
);
$this
->
fail
(
'Please specify a target backend for migration'
);
...
@@ -149,10 +205,10 @@ class FileManager extends Module {
...
@@ -149,10 +205,10 @@ class FileManager extends Module {
$files
=
FileModel
::
objects
();
$files
=
FileModel
::
objects
();
$this
->
_applyCriteria
(
$options
,
$files
);
$this
->
_applyCriteria
(
$options
,
$files
);
foreach
(
$files
as
$f
)
foreach
(
$files
as
$f
)
{
$f
->
tickets
->
expunge
();
$f
->
tickets
->
expunge
();
$f
->
unlink
()
&&
$f
->
delete
();
$files
->
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