Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
b080981f
Commit
b080981f
authored
Sep 01, 2008
by
Penny Leach
Browse files
added support for filesimporter to check sha1 of entire file not just
contents
parent
bd192910
Changes
1
Hide whitespace changes
Inline
Side-by-side
htdocs/lib/import.php
View file @
b080981f
...
...
@@ -180,7 +180,7 @@ abstract class Importer {
public
function
import_immediately_allowed
()
{
// @todo change this (check whatever)
return
fals
e
;
return
tru
e
;
}
}
...
...
@@ -209,12 +209,14 @@ class FilesImporter extends Importer {
private
$manifest
;
private
$files
;
private
$unzipdir
;
private
$zipfilesha1
;
public
function
__construct
(
$id
,
$record
=
null
)
{
parent
::
__construct
(
$id
,
$record
);
$data
=
$this
->
get
(
'data'
);
self
::
validate_import_data
(
$data
);
$this
->
manifest
=
$data
[
'filesmanifest'
];
$this
->
zipfilesha1
=
$data
[
'zipfilesha1'
];
}
public
static
function
validate_import_data
(
$importdata
)
{
...
...
@@ -225,6 +227,9 @@ class FilesImporter extends Importer {
count
(
$importdata
[
'filesmanifest'
])
==
0
)
{
throw
new
ImportException
(
'Missing files manifest in import data'
);
}
if
(
!
array_key_exists
(
'zipfilesha1'
,
$importdata
))
{
throw
new
ImportException
(
'Missing zipfile sha1 in import data'
);
}
return
true
;
}
...
...
@@ -240,6 +245,10 @@ class FilesImporter extends Importer {
$this
->
relativepath
=
$filesinfo
[
'relativepath'
];
$this
->
zipfile
=
$filesinfo
[
'zipfile'
];
if
(
sha1_file
(
get_config
(
'dataroot'
)
.
'/'
.
$this
->
relativepath
.
'/'
.
$this
->
zipfile
)
!=
$this
->
zipfilesha1
)
{
throw
new
ImportException
(
'sha1 of recieved zipfile didn\'t match expected sha1'
);
}
$this
->
unzipdir
=
get_config
(
'dataroot'
)
.
'/'
.
$this
->
relativepath
.
'extract/'
;
if
(
!
check_dir_exists
(
$this
->
unzipdir
))
{
throw
new
ImportException
(
'Failed to create the temporary directories to work in'
);
...
...
@@ -297,7 +306,7 @@ class FilesImporter extends Importer {
// we're just adding them as files into an 'incoming' directory in the user's file area.
safe_require
(
'artefact'
,
'file'
);
try
{
$dir
=
ArtefactTypeFolder
::
get_folder_id
(
'incoming'
,
get_string
(
'incomingfolderdesc'
),
null
,
$this
->
get
(
'usr'
));
$dir
=
ArtefactTypeFolder
::
get_folder_id
(
'incoming'
,
get_string
(
'incomingfolderdesc'
),
null
,
true
,
$this
->
get
(
'usr'
));
}
catch
(
Exception
$e
)
{
throw
new
ImportException
(
$e
->
getMessage
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment