Esempio n. 1
0
require_once $CFG->libdir . '/adminlib.php';
//require_once("../config.php");
require_once $CFG->dirroot . '/user/profile/lib.php';
$page = new stdClass();
$id = optional_param('id', 0, PARAM_INT);
// user id
$hubId = optional_param('hubId', 0, PARAM_INT);
// hub id
$course = optional_param('course', SITEID, PARAM_INT);
// course id (defaults to Site)
$page->action = optional_param('action', 3, PARAM_INT);
// action: Create 1, Read 2, Update 3, Delete 4
$page->server = new synch_modal_Server();
$page->updated = false;
$defaultReturnUrl = '/synch/find_content.php';
$hubId = SynchContentHierarchy::getIdFromDataItemId($hubId);
// Convert the dataItemId to an id
$page->server->serverId = $hubId;
admin_externalpage_setup('mnetpeers');
if (empty($id)) {
    // See your own profile by default
    require_login();
    $id = $USER->id;
}
if (!($user = get_record("user", "id", $id))) {
    error("No such user in this course");
}
if (!($course = get_record("course", "id", $course))) {
    error("No such course id");
}
// Course is site for now. Get the context
Esempio n. 2
0
 public function getForumsForHierarchy($parentDataItemId)
 {
     global $CFG;
     global $SynchContentHierarchy;
     // Have the modules been loaded for the parent section? if not load them
     if (!$SynchContentHierarchy->hasModulesLoaded($parentDataItemId)) {
         $this->getAndAppendModulesToSection($parentDataItemId);
     }
     $parentId = SynchContentHierarchy::getIdFromDataItemId($parentDataItemId);
     $sectionId = $parentId;
     $forumIds = $this->getInstanceIdsFromModulesByModuleType($parentDataItemId, '1010000006');
     if (!is_array($forumIds)) {
         return null;
     }
     $records = get_records_list("forum", "id", implode(',', $forumIds), null, "id, course, type, name, intro");
     if (!$records || !count($records)) {
         return null;
     }
     $contentItems = array();
     $contentItem = null;
     $record = null;
     foreach ($records as $record) {
         $contentItem = new SynchContentItem(array('id' => $record->id, 'name' => $record->name, 'description' => $record->intro));
         $contentItems[$record->id] = $contentItem;
     }
     return $contentItems;
 }
Esempio n. 3
0
 public function restoreMergedBackup($dataItemId, $files, $session)
 {
     global $CFG;
     $page = new stdClass();
     //Move the merged backup file from the session folder to the course folder
     // Move the backups from the course directory into synch/sessions/sessionid/backups with the serverid appended the file name
     // Generate a new file name from the original backup file and the local server id
     //$newFileName = $this->createSessionBackupFileName($preferences);
     $sessionBackupFileName = $files['merged'];
     // Generate the path to the session backup folder
     $sessionBackupPath = $this->createSessionBackupPath($session);
     // Does the merge file exist
     if (!FileSystem::exists($sessionBackupPath . '/' . $sessionBackupFileName, 'f')) {
         return false;
     }
     // Move the session merge file to the course backup folder.
     if (1) {
         // fudge for testing in development
         $courseBackupFileName = FileSystem::removeFromFileName($sessionBackupFileName, $CFG->synch->merge_file_suffix);
         $courseBackupFileName = FileSystem::removeFromFileName($courseBackupFileName, synch_backup_controller::getUniqueCodeFromFileName($sessionBackupFileName));
         // Do we need to update the file name within the preferences. We will be passing
         // the file name and from then on it shouldn't be required.
         $courseId = SynchContentHierarchy::getIdFromDataItemId($dataItemId);
         $courseBackupPath = synch_Backup_controller::createBackupFilePath($courseId);
         // Create the folder structure if necessary
         FileSystem::createFoldersFromPath($courseBackupPath);
         $moved = FileSystem::copyFile($sessionBackupPath . '/' . $sessionBackupFileName, $courseBackupPath . '/' . $courseBackupFileName);
     } else {
         $moved = true;
     }
     if (!$moved) {
         return false;
     }
     $preferences = new Object();
     $preferences->course_id = $courseId;
     $preferences->backup_name = $courseBackupFileName;
     $preferences->backup_unique_code = synch_backup_controller::getUniqueCodeFromFileName($sessionBackupFileName);
     global $SynchServerController;
     // If there are changes from the remote Moodle restore to the local Moodle
     $remoteServerId = $SynchServerController->getRemoteServerId();
     if ($this->getSessionHasChangesByServerId($remoteServerId, $session)) {
         // Call the restoreCourse method of SynchBackupController
         $restored = synch_backup_controller::restoreCourse($preferences, $session);
     }
     return $restored;
 }
Esempio n. 4
0
<form method="post" action="server_edit.php">
<div>
<input type="hidden" name="sesskey" value="<?php 
echo $USER->sesskey;
?>
" />
<input type="hidden" name="action" value="<?php 
echo $page->action;
?>
" />
<input type="hidden" name="id" value="<?php 
echo isset($details->id) ? $details->id : '0';
?>
" />
<input type="hidden" name="hubId" value="<?php 
echo isset($details->serverId) ? SynchContentHierarchy::generateDataItemId($details->serverId, synch_view_controller::$TYPE_ID_HUB) : '0';
?>
" />
<table cellpadding="9" cellspacing="0" width="635">

<tr>
    <td align="right" valign="top">Server:</td>
    <td valign="top">
        <select name="mnetHostId">
        <?php 
foreach ($hosts as $host) {
    $selected = $details->mnetHostId == $host->id ? 'selected="selected" ' : '';
    echo '<option value="' . $host->id . '" ' . $selected . '>' . $host->name . '</option>';
}
?>
        </select>
Esempio n. 5
0
 public static function restoreCourse($preferences, $session)
 {
     global $Out;
     // the initial set of preferences should be enough to get the restore started.
     // once in progress the restore will obtain the preferences from the backup file
     // itself
     if (!isset($preferences)) {
         return null;
     }
     // Assumes the backup file is in the course data directory and the
     // preferences are in the backup file itself.
     global $CFG;
     // for large files uncomment following code
     //@ini_set("max_execution_time","3000");
     //raise_memory_limit("192M");
     $file = self::createBackupFilePath($preferences->course_id);
     $file .= '/' . $preferences->backup_name;
     //path to file
     //Check the file exists
     if (!is_file($file)) {
         return false;
     }
     //Check the file name ends with .zip
     if (!substr($file, -4) == ".zip") {
         return false;
     }
     //Now calculate the unique_code for this restore
     $backup_unique_code = $preferences->backup_unique_code;
     //Now check and create the backup dir (if it doesn't exist)
     $status = check_and_create_backup_dir($backup_unique_code);
     //Empty dir
     if ($status) {
         $status = clear_backup_dir($backup_unique_code);
     }
     //Now delete old data and directories under dataroot/temp/backup
     if ($status) {
         $status = backup_delete_old_data();
     }
     $tempBackupPath = synch_backup_controller::createTempBackupPath($backup_unique_code);
     //Now copy the zip file to dataroot/temp/backup/backup_unique_code
     if ($status) {
         if (!($status = backup_copy_file($file, $tempBackupPath . "/" . basename($file)))) {
             // There has been a problem. Invalid name or bad perms
             return false;
         }
     }
     //Now unzip the file
     if ($status) {
         if (!($status = restore_unzip($tempBackupPath . "/" . basename($file)))) {
             // error: Invalid zip file
             return false;
         }
     }
     //Check for Blackboard backups and convert
     if ($status) {
         require_once "{$CFG->dirroot}/backup/bb/restore_bb.php";
         $status = blackboard_convert($tempBackupPath);
     }
     // backup file has now been unpacked. Retrieve the serialized preferences
     $preferencesPath = $tempBackupPath . '/' . self::getPreferencesFileName();
     $preferences = FileSystem::unSerializeFromFile($preferencesPath);
     // Now we have the preferences from the backup we need to tailor it to our current needs
     // should we be updating an existing item or creating one.
     $dataItemId = SynchContentHierarchy::generateDataItemId($preferences->course_id, synch_view_controller::$TYPE_ID_COURSE);
     global $SynchManager, $SynchServerController;
     $itemExists = $SynchManager->getSessionItemExistsByServerId($SynchServerController->getServerId(), $session);
     if (isset($itemExists) && is_array($itemExists) && in_array($dataItemId, $itemExists)) {
         $preferences->restoreto = 1;
         $preferences->deleting = 1;
     } else {
         $preferences->restoreto = 2;
     }
     //Now check for the moodle.xml file
     if ($status) {
         $xml_file = $tempBackupPath . "/moodle.xml";
         if (!($status = restore_check_moodle_file($xml_file))) {
             if (!is_file($xml_file)) {
                 //Error checking backup file. moodle.xml not found at root level of zip file
                 return false;
             } else {
                 //Error checking backup file. moodle.xml is incorrect or corrupted.
                 return false;
             }
         }
     }
     //unpack backup file
     //read contents
     //Reading info from file
     $info = restore_read_xml_info($xml_file);
     //Reading course_header from file
     $courseHeader = restore_read_xml_course_header($xml_file);
     //Save course header and info into php session
     if ($status) {
         //$SESSION->info = $info;
         //$SESSION->course_header = $course_header;
     }
     global $restore;
     $restore = $preferences;
     $message = null;
     $restoreSuccess = restore_execute($preferences, $info, $courseHeader, $message);
     return $restoreSuccess;
 }