/**
 * Given an ID of an instance of this module, 
 * this function will permanently delete the instance 
 * and any data that depends on it.  
 * @uses $COURSE, $DB
 */
function flashcard_delete_instance($id)
{
    global $COURSE, $DB;
    // clear anyway what remains here
    filesystem_clear_dir($COURSE->id . '/moddata/flashcard/' . $id, FS_FULL_DELETE);
    if (!($flashcard = $DB->get_record('flashcard', array('id' => $id)))) {
        return false;
    }
    $result = true;
    // Delete any dependent records here
    $DB->delete_records('flashcard_card', array('flashcardid' => $flashcard->id));
    if (!$DB->delete_records('flashcard', array('id' => $flashcard->id))) {
        $result = false;
    }
    return $result;
}
         echo $OUTPUT->box(get_string('vmoodlesnapshot2', 'local_vmoodle'));
         $params = array('view' => 'management', 'what' => 'snapshot', 'step' => 2, 'wwwroot' => $wwwroot);
         echo $OUTPUT->continue_button(new moodle_url('/local/vmoodle/view.php', $params));
         echo $OUTPUT->footer();
         die;
     }
 }
 // End of process.
 // copy moodle data and protect against copy recursion.
 // $CFG->filedebug = 1;
 filesystem_copy_tree($vdatapath, $absolute_datadir, $vdatabase, array("^{$templatefoldername}\$"));
 // Remove Vmoodle clone session, temp and cache dir.
 filesystem_clear_dir($relative_datadir . $separator . 'sessions', true);
 filesystem_clear_dir($relative_datadir . $separator . 'temp', true);
 filesystem_clear_dir($relative_datadir . $separator . 'cache', true);
 filesystem_clear_dir($relative_datadir . $separator . 'localcache', true);
 // Store original hostname for further database replacements.
 $FILE = fopen($absolute_sqldir . $separator . 'manifest.php', 'w');
 fwrite($FILE, "<?php\n ");
 fwrite($FILE, "\$templatewwwroot = '" . $wwwroot . "';\n");
 fwrite($FILE, "\$templatevdbprefix = '" . $CFG->prefix . "';\n ");
 fwrite($FILE, "?>");
 fclose($FILE);
 if (empty($automation)) {
     // Every step was SUCCESS.
     $message_object->message = get_string('successfinishedcapture', 'local_vmoodle');
     $message_object->style = 'notifysuccess';
     // Save confirm message before redirection.
     $SESSION->vmoodle_ma['confirm_message'] = $message_object;
     echo $OUTPUT->header();
     echo $OUTPUT->box(get_string('vmoodlesnapshot3', 'local_vmoodle'));
    }
    $form->editing = 1;
    include "add.html";
    return -1;
}
/**************************** delete a vmoodle and uninstall it ************/
if ($action == 'delete') {
    $id = required_param('id', PARAM_INT);
    $vmoodle = $DB->get_record('local_vmoodle', array('id' => $id));
    if ($vmoodle) {
        /// drop record in vmoodle table
        $DB->delete_records('local_vmoodle', array('id' => $id));
        /// destroy database. work silently
        @vmoodle_drop_database($vmoodle);
        /// unlink datapath
        filesystem_clear_dir($vmoodle->vdatapath, FS_FULL_DELETE, '');
        /// unbind mnet hosts
        if ($vmoodle->mnet) {
            // unregister from me (this)
            $thismoodle = vmoodle_make_this();
            vmoodle_unregister_mnet($vmoodle, $thismoodle);
            // unregister from all remaining peers (this)
            $mnetpeers = $DB->get_records('local_vmoodle', array('mnet' => 1));
            if (!empty($mnetpeers)) {
                foreach ($mnetpeers as $peervmoodle) {
                    vmoodle_unregister_mnet($vmoodle, $peervmoodle);
                }
            }
        }
    } else {
        error("Bad VMoodle Id");
示例#4
0
 /**
 * clears and removes an entire dir
 * @param string $relativepath the path from dataroot
 * @param boolean $fulldelete if true, removes the dir root either
 * @param string $pathbase the base path
 * @return an array of entries wich are local names in path
 */
 function filesystem_clear_dir($relativepath, $fullDelete = false, $pathbase = null)
 {
     global $CFG;
     if (is_null($pathbase)) {
         $pathbase = $CFG->dataroot . '/';
     } elseif ($pathbase === '') {
         $pathbase = '';
     } else {
         $pathbase = $pathbase . '/';
     }
     if (@$CFG->filedebug) {
         mtrace("clearing dir <i>{$pathbase}{$relativepath}</i><br/>");
     }
     $exists = filesystem_is_dir($relativepath, $pathbase);
     if (!$exists && !$fullDelete) {
         return filesystem_create_dir($relativepath, $pathbase);
     }
     if (!$exists && $fullDelete) {
         return true;
     }
     $files = filesystem_scan_dir($relativepath, FS_SHOW_HIDDEN, FS_ALL_ENTRIES, $pathbase);
     foreach ($files as $aFile) {
         if ($aFile == "." || $aFile == "..") {
             continue;
         }
         if (filesystem_is_dir("{$relativepath}/{$aFile}", $pathbase)) {
             filesystem_clear_dir("{$relativepath}/{$aFile}", FS_FULL_DELETE, $pathbase);
             // fs_removeDir("{$relativepath}/{$aFile}");
         } else {
             filesystem_delete_file("{$relativepath}/{$aFile}", $pathbase);
         }
     }
     if (file_exists($pathbase . $relativepath) && $fullDelete) {
         return filesystem_remove_dir($relativepath, $pathbase);
     }
     return false;
 }
示例#5
0
文件: lib.php 项目: laiello/poodll
/**
* Given an ID of an instance of this module, 
* this function will permanently delete the instance 
* and any data that depends on it.  
* @uses $COURSE
*/
function poodllflashcard_delete_instance($id)
{
    global $COURSE;
    // clear anyway what remains here
    filesystem_clear_dir($COURSE->id . '/moddata/poodllflashcard/' . $id, FS_FULL_DELETE);
    if (!($flashcard = get_record('poodllflashcard', 'id', $id))) {
        return false;
    }
    $result = true;
    // Delete any dependent records here
    delete_records('poodllflashcard_card', 'flashcardid', $flashcard->id);
    if (!delete_records('poodllflashcard', 'id', $flashcard->id)) {
        $result = false;
    }
    return $result;
}