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
integration
prechecker
Commits
0faf6791
Commit
0faf6791
authored
Aug 16, 2008
by
skodak
Browse files
MDL-16072 File storage conversion Forum
parent
8eb1e0a1
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
mod/forum/db/upgrade.php
View file @
0faf6791
...
...
@@ -95,6 +95,78 @@ function xmldb_forum_upgrade($oldversion) {
upgrade_mod_savepoint
(
$result
,
2008072800
,
'forum'
);
}
if
(
$result
&&
$oldversion
<
2008081605
)
{
/////////////////////////////////////
/// new file storage upgrade code ///
/////////////////////////////////////
$fs
=
get_file_storage
();
$empty
=
$DB
->
sql_empty
();
// silly oracle empty string handling workaround
$sqlfrom
=
"FROM
{
forum_posts
}
p
JOIN
{
forum_discussions
}
d ON d.id = p.discussion
JOIN
{
forum
}
f ON f.id = d.forum
JOIN
{
modules
}
m ON m.name = 'forum'
JOIN
{
course_modules
}
cm ON (cm.module = m.id AND cm.instance = f.id)
WHERE p.attachment <> '
$empty
' AND p.attachment <> '1'
ORDER BY f.course, f.id, d.id"
;
$count
=
$DB
->
count_records_sql
(
"SELECT COUNT('x')
$sqlfrom
"
);
if
(
$rs
=
$DB
->
get_recordset_sql
(
"SELECT p.*, d.forum, f.course, cm.id AS cmid
$sqlfrom
"
))
{
$pbar
=
new
progress_bar
(
'migrateforumfiles'
,
500
,
true
);
$olddebug
=
$DB
->
get_debug
();
$DB
->
set_debug
(
false
);
// lower debug level, there might be very many files
$i
=
0
;
foreach
(
$rs
as
$post
)
{
$i
++
;
upgrade_set_timeout
(
60
);
// set up timeout, may also abort execution
$pbar
->
update
(
$i
,
$count
,
"Migrating forum posts -
$i
/
$count
."
);
$filepath
=
"
$CFG->dataroot
/
$post->course
/
$CFG->moddata
/forum/
$post->forum
/
$post->id
/
$post->attachment
"
;
if
(
!
is_readable
(
$filepath
))
{
//file missing??
notify
(
"File not readable, skipping: "
.
$filepath
);
$post
->
attachment
=
''
;
$DB
->
update_record
(
'forum_posts'
,
$post
);
continue
;
}
$context
=
get_context_instance
(
CONTEXT_MODULE
,
$post
->
cmid
);
$filearea
=
'forum_attachment'
;
$filename
=
clean_param
(
$post
->
attachment
,
PARAM_FILE
);
if
(
$filename
===
''
)
{
notify
(
"Unsupported post filename, skipping: "
.
$filepath
);
$post
->
attachment
=
''
;
$DB
->
update_record
(
'forum_posts'
,
$post
);
continue
;
}
if
(
!
$fs
->
file_exists
(
$context
->
id
,
$filearea
,
$post
->
id
,
'/'
,
$filename
))
{
$file_record
=
array
(
'contextid'
=>
$context
->
id
,
'filearea'
=>
$filearea
,
'itemid'
=>
$post
->
id
,
'filepath'
=>
'/'
,
'filename'
=>
$filename
,
'userid'
=>
$post
->
userid
);
if
(
$fs
->
create_file_from_pathname
(
$file_record
,
$filepath
))
{
$post
->
attachment
=
'1'
;
if
(
$DB
->
update_record
(
'forum_posts'
,
$post
))
{
unlink
(
$filepath
);
}
}
}
// remove dirs if empty
@
rmdir
(
"
$CFG->dataroot
/
$post->course
/
$CFG->moddata
/forum/
$post->forum
/
$post->id
"
);
@
rmdir
(
"
$CFG->dataroot
/
$post->course
/
$CFG->moddata
/forum/
$post->forum
"
);
@
rmdir
(
"
$CFG->dataroot
/
$post->course
/
$CFG->moddata
/forum"
);
}
$DB
->
set_debug
(
$olddebug
);
// reset debug level
$rs
->
close
();
}
upgrade_mod_savepoint
(
$result
,
2008081605
,
'forum'
);
}
return
$result
;
}
...
...
mod/forum/discuss.php
View file @
0faf6791
...
...
@@ -64,7 +64,7 @@
error
(
'Forum not visible'
,
$return
);
}
if
(
!
forum_move_attachments
(
$discussion
,
$forumto
->
id
))
{
if
(
!
forum_move_attachments
(
$discussion
,
$forum
->
id
,
$forumto
->
id
))
{
notify
(
"Errors occurred while moving attachment directories - check your file permissions"
);
}
$DB
->
set_field
(
'forum_discussions'
,
'forum'
,
$forumto
->
id
,
array
(
'id'
=>
$discussion
->
id
));
...
...
mod/forum/lib.php
View file @
0faf6791
This diff is collapsed.
Click to expand it.
mod/forum/post.php
View file @
0faf6791
...
...
@@ -454,9 +454,6 @@
$errordestination
=
$SESSION
->
fromurl
;
}
// TODO add attachment processing
//$fromform->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL;
trusttext_after_edit
(
$fromform
->
message
,
$modcontext
);
if
(
$fromform
->
edit
)
{
// Updating a post
...
...
@@ -483,7 +480,7 @@
$updatepost
=
$fromform
;
//realpost
$updatepost
->
forum
=
$forum
->
id
;
if
(
!
forum_update_post
(
$updatepost
,
$message
))
{
if
(
!
forum_update_post
(
$updatepost
,
$mform_post
,
$message
))
{
print_error
(
"couldnotupdate"
,
"forum"
,
$errordestination
);
}
...
...
@@ -526,7 +523,7 @@
$message
=
''
;
$addpost
=
$fromform
;
$addpost
->
forum
=
$forum
->
id
;
if
(
$fromform
->
id
=
forum_add_new_post
(
$addpost
,
$message
))
{
if
(
$fromform
->
id
=
forum_add_new_post
(
$addpost
,
$mform_post
,
$message
))
{
$timemessage
=
2
;
if
(
!
empty
(
$message
))
{
// if we're printing stuff about the file upload
...
...
@@ -591,7 +588,7 @@
$discussion
->
timeend
=
$fromform
->
timeend
;
$message
=
''
;
if
(
$discussion
->
id
=
forum_add_discussion
(
$discussion
,
$message
))
{
if
(
$discussion
->
id
=
forum_add_discussion
(
$discussion
,
$mform_post
,
$message
))
{
add_to_log
(
$course
->
id
,
"forum"
,
"add discussion"
,
"discuss.php?d=
$discussion->id
"
,
"
$discussion->id
"
,
$cm
->
id
);
...
...
mod/forum/post_form.php
View file @
0faf6791
...
...
@@ -17,9 +17,6 @@ class mod_forum_post_form extends moodleform {
$post
=
$this
->
_customdata
[
'post'
];
// hack alert
// the upload manager is used directly in post precessing, moodleform::save_files() is not used yet
$this
->
set_upload_manager
(
new
upload_manager
(
'attachment'
,
true
,
false
,
$course
,
false
,
$forum
->
maxbytes
,
true
,
true
));
$mform
->
addElement
(
'header'
,
'general'
,
''
);
//fill in the data depending on page params
//later using set_data
$mform
->
addElement
(
'text'
,
'subject'
,
get_string
(
'subject'
,
'forum'
),
'size="48"'
);
...
...
mod/forum/rsslib.php
View file @
0faf6791
...
...
@@ -237,8 +237,6 @@
$formatoptions
=
new
object
;
$formatoptions
->
trusttext
=
true
;
require_once
(
$CFG
->
libdir
.
'/filelib.php'
);
foreach
(
$recs
as
$rec
)
{
unset
(
$item
);
unset
(
$user
);
...
...
@@ -257,12 +255,7 @@
if
(
!
empty
(
$post_files
))
{
$item
->
attachments
=
array
();
foreach
(
$post_files
as
$file
)
{
$attachment
=
new
stdClass
;
$attachment
->
url
=
get_file_url
(
$post_file_area_name
.
'/'
.
$file
);
$attachment
->
length
=
filesize
(
"
$CFG->dataroot
/
$post_file_area_name
/
$file
"
);
$item
->
attachments
[]
=
$attachment
;
}
//TODO: rewrite attachment handling
}
$items
[]
=
$item
;
...
...
mod/forum/version.php
View file @
0faf6791
...
...
@@ -5,8 +5,8 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module
->
version
=
20080
73100
;
$module
->
requires
=
20080
72401
;
// Requires this Moodle version
$module
->
version
=
20080
81605
;
$module
->
requires
=
20080
81600
;
// Requires this Moodle version
$module
->
cron
=
60
;
?>
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