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
af362d40
Commit
af362d40
authored
Sep 11, 2008
by
Richard Mansfield
Browse files
When copying file artefacts, don't make a copy of the actual file
parent
b80c02fd
Changes
5
Hide whitespace changes
Inline
Side-by-side
htdocs/artefact/file/db/install.xml
View file @
af362d40
...
...
@@ -9,6 +9,7 @@
<FIELD
NAME=
"artefact"
TYPE=
"int"
LENGTH=
"10"
NOTNULL=
"true"
/>
<FIELD
NAME=
"size"
TYPE=
"int"
LENGTH=
"10"
NOTNULL=
"false"
/>
<FIELD
NAME=
"oldextension"
TYPE=
"text"
NOTNULL=
"false"
/>
<FIELD
NAME=
"fileid"
TYPE=
"int"
LENGTH=
"10"
NOTNULL=
"false"
/>
</FIELDS>
<KEYS>
<KEY
NAME=
"artefactfk"
TYPE=
"foreign"
FIELDS=
"artefact"
REFTABLE=
"artefact"
REFFIELDS=
"id"
/>
...
...
htdocs/artefact/file/db/upgrade.php
View file @
af362d40
...
...
@@ -129,6 +129,14 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
}
if
(
$oldversion
<
2008091100
)
{
$table
=
new
XMLDBTable
(
'artefact_file_files'
);
$field
=
new
XMLDBField
(
'fileid'
);
$field
->
setAttributes
(
XMLDB_TYPE_INTEGER
,
'10'
,
XMLDB_UNSIGNED
,
null
);
add_field
(
$table
,
$field
);
execute_sql
(
"UPDATE
{
artefact_file_files
}
SET fileid = artefact WHERE NOT size IS NULL"
);
}
// everything up to here we pre mysql support.
return
$status
;
}
...
...
htdocs/artefact/file/lib.php
View file @
af362d40
...
...
@@ -273,6 +273,7 @@ class PluginArtefactFile extends PluginArtefact {
abstract
class
ArtefactTypeFileBase
extends
ArtefactType
{
protected
$size
;
// The original filename extension (when the file is first
// uploaded) is saved here. This is used as a workaround for IE's
// detecting filetypes by extension: when the file is downloaded,
...
...
@@ -280,6 +281,11 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
// already.
protected
$oldextension
;
// The id used for the filename on the filesystem. Usually this
// is the same as the artefact id, but it can be different if the
// file is a copy of another file artefact.
protected
$fileid
;
public
function
__construct
(
$id
=
0
,
$data
=
null
)
{
parent
::
__construct
(
$id
,
$data
);
...
...
@@ -350,10 +356,14 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
$data
=
(
object
)
array
(
'artefact'
=>
$this
->
get
(
'id'
),
'size'
=>
$this
->
get
(
'size'
),
'oldextension'
=>
$this
->
get
(
'oldextension'
)
'oldextension'
=>
$this
->
get
(
'oldextension'
),
'fileid'
=>
$this
->
get
(
'fileid'
),
);
if
(
$new
)
{
if
(
$this
->
get
(
'artefacttype'
)
!=
'folder'
&&
empty
(
$data
->
fileid
))
{
$data
->
fileid
=
$data
->
artefact
;
}
insert_record
(
'artefact_file_files'
,
$data
);
}
else
{
...
...
@@ -671,7 +681,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
}
public
function
get_path
()
{
return
get_config
(
'dataroot'
)
.
self
::
get_file_directory
(
$this
->
id
)
.
'/'
.
$this
->
id
;
return
get_config
(
'dataroot'
)
.
self
::
get_file_directory
(
$this
->
file
id
)
.
'/'
.
$this
->
file
id
;
}
public
static
function
detect_artefact_type
(
$file
)
{
...
...
@@ -825,7 +835,10 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
set_field
(
'view_feedback'
,
'attachment'
,
null
,
'attachment'
,
$this
->
id
);
if
(
is_file
(
$file
))
{
$size
=
filesize
(
$file
);
unlink
(
$file
);
// Only delete the file on disk if no other artefacts point to it
if
(
count_records
(
'artefact_file_files'
,
'fileid'
,
$this
->
get
(
'id'
))
==
1
)
{
unlink
(
$file
);
}
global
$USER
;
// Deleting other users' files won't lower their quotas yet...
if
(
!
$this
->
institution
&&
$USER
->
id
==
$this
->
get
(
'owner'
))
{
...
...
@@ -945,15 +958,9 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
}
public
function
copy_extra
(
$new
)
{
$oldid
=
$this
->
get
(
'id'
);
$dataroot
=
get_config
(
'dataroot'
);
$oldfile
=
$dataroot
.
self
::
get_file_directory
(
$oldid
)
.
'/'
.
$oldid
;
$newid
=
$new
->
get
(
'id'
);
$newdir
=
$dataroot
.
self
::
get_file_directory
(
$newid
);
check_dir_exists
(
$newdir
);
if
(
!
copy
(
$oldfile
,
$newdir
.
'/'
.
$newid
))
{
throw
new
SystemException
(
'failed copying file artefact'
);
}
$new
->
set
(
'fileid'
,
$this
->
get
(
'fileid'
));
$new
->
set
(
'size'
,
$this
->
get
(
'size'
));
$new
->
set
(
'oldextension'
,
$this
->
get
(
'oldextension'
));
global
$USER
;
if
(
$new
->
get
(
'owner'
)
&&
$new
->
get
(
'owner'
)
==
$USER
->
get
(
'id'
))
{
$USER
->
quota_add
(
$new
->
get
(
'size'
));
...
...
htdocs/artefact/file/version.php
View file @
af362d40
...
...
@@ -27,7 +27,7 @@
defined
(
'INTERNAL'
)
||
die
();
$config
=
new
StdClass
;
$config
->
version
=
20080
319
00
;
$config
->
version
=
20080
911
00
;
$config
->
release
=
'0.4.3'
;
?>
htdocs/artefact/lib.php
View file @
af362d40
...
...
@@ -698,8 +698,8 @@ abstract class ArtefactType {
$classname
=
generate_artefact_class_name
(
$data
[
'artefacttype'
]);
safe_require
(
'artefact'
,
get_field
(
'artefact_installed_type'
,
'plugin'
,
'name'
,
$data
[
'artefacttype'
]));
$copy
=
new
$classname
(
0
,
$data
);
$copy
->
commit
();
$this
->
copy_extra
(
$copy
);
$copy
->
commit
();
return
$copy
->
get
(
'id'
);
}
...
...
Write
Preview
Supports
Markdown
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