Example #1
0
File: lib.php Project: r007/PMoodle
/**
 * Given a discussion object that is being moved to forumid,
 * this function checks all posts in that discussion
 * for attachments, and if any are found, these are
 * moved to the new forum directory.
 */
function forum_move_attachments($discussion, $forumid)
{
    global $CFG;
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $return = true;
    if ($posts = get_records_select("forum_posts", "discussion = '{$discussion->id}' AND attachment <> ''")) {
        foreach ($posts as $oldpost) {
            $oldpost->course = $discussion->course;
            $oldpost->forum = $discussion->forum;
            $oldpostdir = "{$CFG->dataroot}/" . forum_file_area_name($oldpost);
            if (is_dir($oldpostdir)) {
                $newpost = $oldpost;
                $newpost->forum = $forumid;
                $newpostdir = forum_file_area_name($newpost);
                // take off the last directory because otherwise we're renaming to a directory that already exists
                // and this is unhappy in certain situations, eg over an nfs mount and potentially on windows too.
                make_upload_directory(substr($newpostdir, 0, strrpos($newpostdir, '/')));
                $newpostdir = $CFG->dataroot . '/' . forum_file_area_name($newpost);
                $files = get_directory_list($oldpostdir);
                // get it before we rename it.
                if (!@rename($oldpostdir, $newpostdir)) {
                    $return = false;
                }
                foreach ($files as $file) {
                    clam_change_log($oldpostdir . '/' . $file, $newpostdir . '/' . $file);
                }
            }
        }
    }
    return $return;
}
Example #2
0
function glossary_move_attachments($entry, $glossaryid)
{
    /// Given a entry object that is being moved to glossaryid,
    /// this function checks that entry
    /// for attachments, and if any are found, these are
    /// moved to the new glossary directory.
    global $CFG;
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $return = true;
    if ($entries = get_records_select("glossary_entries", "glossaryid = '{$entry->id}' AND attachment <> ''")) {
        foreach ($entries as $entry) {
            $oldentry = new object();
            $oldentry->course = $entry->course;
            $oldentry->glossaryid = $entry->glossaryid;
            $oldentrydir = "{$CFG->dataroot}/" . glossary_file_area_name($oldentry);
            if (is_dir($oldentrydir)) {
                $newentry = $oldentry;
                $newentry->glossaryid = $glossaryid;
                $newentrydir = "{$CFG->dataroot}/" . glossary_file_area_name($newentry);
                $files = get_directory_list($oldentrydir);
                // get it before we rename it.
                if (!@rename($oldentrydir, $newentrydir)) {
                    $return = false;
                }
                foreach ($files as $file) {
                    // this is not tested as I can't find anywhere that calls this function, grepping the source.
                    clam_change_log($oldentrydir . '/' . $file, $newentrydir . '/' . $file);
                }
            }
        }
    }
    return $return;
}