function exec_ogp_module() { global $db; global $view; print "<h2>" . get_lang_f('updating_modules') . "</h2>"; require_once 'modules/modulemanager/module_handling.php'; $modules = $db->getInstalledModules(); //print_r($modules) foreach ($modules as $row) { update_module($db, $row['id'], $row['folder']); } print "<p>" . get_lang_f('updating_finished') . "</p>"; $view->refresh("?m=modulemanager"); }
function exec_ogp_module() { if (!function_exists("curl_init")) { print_failure(get_lang('curl_needed')); return; } if ($_SESSION['users_group'] != "admin") { print_failure(get_lang('no_access')); return; } global $db; global $view; $version = $_GET['version']; $vtype = "SVN"; echo "<h4>" . get_lang('dwl_update') . "</h4>\n"; //This is usefull when you are downloading big files, as it //will prevent time out of the script set_time_limit(0); error_reporting(E_ALL); ini_set('display_errors', true); $baseDir = str_replace("modules" . DIRECTORY_SEPARATOR . "update", "", dirname(__FILE__)); if (!is_writable($baseDir)) { if (!@chmod($baseDir, 0755)) { print_failure(get_lang_f('base_dir_not_writable', $baseDir)); return; } } if (is_writable(sys_get_temp_dir())) { // Download file to temporary folder if (isset($_POST['mirror']) && !empty($_POST['mirror'])) { $mirror = $_POST['mirror']; } else { $mirror = "master"; } $temp_dwl = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'svn.tar.gz'; $fp = fopen($temp_dwl, 'w+'); //This is the download destination $url = "http://" . $mirror . ".dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/hldstart-code-{$version}.zip"; //This is the download source $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 500); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); curl_close($ch); fclose($fp); // Check if the file exists and the size is bigger than a 404 error page from sf.net if (file_exists($temp_dwl)) { $stat = stat($temp_dwl); } else { print_failure(get_lang_f('dwl_failed', $url)); return; } if ($stat['size'] > 1500) { print_success(get_lang('dwl_complete')); } else { print_failure(get_lang_f('dwl_failed', $url)); return; } echo "<h4>" . get_lang('install_update') . "</h4>\n"; // Set default values for file checkings before installing $not_writable = get_lang('can_not_update_non_writable_files') . " :<br>"; $filename = ""; $overwritten = 0; $new = 0; $all_writable = TRUE; $filelist = ""; $overwritten_files = ""; $new_files = ""; $unwanted_path = "hldstart-code-{$version}/trunk/upload"; $extract_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "OGP_update"; if (!file_exists($extract_path)) { mkdir($extract_path, 0775); } $blacklist = array('/install.php', '/modules/gamemanager/rsync_sites_local.list'); $blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;'); if ($blacklisted_files !== FALSE) { $curren_blacklist = array(); foreach ($blacklisted_files as $blacklisted_file) { $curren_blacklist[] = $blacklisted_file['file_path']; } $blacklist = array_merge($curren_blacklist, $blacklist); } include 'unzip.php'; // array|false extractZip( string $zipFile, string $extract_path [, string $remove_path, array $blacklist, array $whitelist] ) $files = extractZip($temp_dwl, $extract_path, $unwanted_path, $blacklist, ''); if (is_array($files) and count($files) > 0) { // Check file by file if already exists, if it matches, compares both files // looking for changes determining if the file needs to be updated. // Also determines if the file is writable $filelist = array(); $i = 0; foreach ($files as $file) { $filename = str_replace($unwanted_path . "/", "", $file['filename']); if (in_array($filename, $blacklist)) { continue; } $temp_file = $extract_path . DIRECTORY_SEPARATOR . $filename; $web_file = $baseDir . $filename; if (file_exists($web_file)) { $temp = file_get_contents($temp_file); $web = file_get_contents($web_file); if ($temp != $web) { if (!is_writable($web_file)) { if (!@chmod($web_file, 0775)) { $all_writable = FALSE; $not_writable .= $web_file . "<br>"; } else { $filelist[$i] = $file['filename']; $i++; $overwritten_files .= $filename . "<br>"; $overwritten++; } } else { $filelist[$i] = $file['filename']; $i++; $overwritten_files .= $filename . "<br>"; $overwritten++; } } } else { $filelist[$i] = $file['filename']; $i++; $new_files .= $filename . "<br>"; $new++; } } } // Once checkings are done the temp folder is removed if (file_exists($extract_path)) { rmdir_recurse($extract_path); } if ($all_writable) { // Extract the files that are set in $filelist, to the folder at $baseDir and removes 'upload' from the beggining of the path. $files = extractZip($temp_dwl, preg_replace("/\\/\$/", "", $baseDir), $unwanted_path, $blacklist, $filelist); if (is_array($files)) { // Updated files if ($overwritten > 0) { print_success(get_lang_f('files_overwritten', $overwritten)); echo get_lang_f("updated_files", $overwritten_files); } if ($new > 0) { print_success(get_lang_f('new_files', $new)); echo get_lang_f("updated_files", $new_files); } // update version info in db $db->query("UPDATE OGP_DB_PREFIXsettings SET value = '{$version}'\tWHERE setting = 'ogp_version'"); $db->query("UPDATE OGP_DB_PREFIXsettings SET value = '{$vtype}'\tWHERE setting = 'version_type'"); // Remove the downloaded package if (file_exists($temp_dwl)) { unlink($temp_dwl); } // Remove files that are not related to the panel if (file_exists($baseDir . DIRECTORY_SEPARATOR . "hldstart-code-{$version}")) { rmdir_recurse($baseDir . DIRECTORY_SEPARATOR . "hldstart-code-{$version}"); } echo "<br>\n<h4>" . get_lang('updating_modules') . "</h4>\n"; require_once 'modules/modulemanager/module_handling.php'; $modules = $db->getInstalledModules(); foreach ($modules as $row) { update_module($db, $row['id'], $row['folder']); } print_success(get_lang('update_complete')); } else { print_failure("Failed extracting files.<br>There is not enough space available in the system temporary folder (" . sys_get_temp_dir() . ").</b>"); } } else { print_failure($not_writable); } } else { print_failure(get_lang_f('temp_folder_not_writable', sys_get_temp_dir())); } }
/** * Tests that when creating or updating a module, if the availability settings * are present but set to an empty tree, availability is set to null in * database. */ public function test_empty_availability_settings() { global $DB; $this->setAdminUser(); $this->resetAfterTest(); // Enable availability. set_config('enableavailability', 1); // Test add. $emptyavailability = json_encode(\core_availability\tree::get_root_json(array())); $course = self::getDataGenerator()->create_course(); $label = self::getDataGenerator()->create_module('label', array('course' => $course, 'availability' => $emptyavailability)); $this->assertNull($DB->get_field('course_modules', 'availability', array('id' => $label->cmid))); // Test update. $formdata = $DB->get_record('course_modules', array('id' => $label->cmid)); unset($formdata->availability); $formdata->availabilityconditionsjson = $emptyavailability; $formdata->modulename = 'label'; $formdata->coursemodule = $label->cmid; $draftid = 0; file_prepare_draft_area($draftid, context_module::instance($label->cmid)->id, 'mod_label', 'intro', 0); $formdata->introeditor = array('itemid' => $draftid, 'text' => '<p>Yo</p>', 'format' => FORMAT_HTML); update_module($formdata); $this->assertNull($DB->get_field('course_modules', 'availability', array('id' => $label->cmid))); }
/** * Test a specific type of module. * * @param string $modulename - the module name to test */ private function update_specific_module_test($modulename) { global $DB, $CFG; $this->resetAfterTest(true); $this->setAdminUser(); // Warnings: you'll need to change this line if ever you come to test a module not following Moodle standard. require_once $CFG->dirroot . '/mod/' . $modulename . '/lib.php'; // Enable avaibility. // If not enabled all conditional fields will be ignored. set_config('enableavailability', 1); // Enable course completion. // If not enabled all completion settings will be ignored. set_config('enablecompletion', COMPLETION_ENABLED); // Enable forum RSS feeds. set_config('enablerssfeeds', 1); set_config('forum_enablerssfeeds', 1); $course = $this->getDataGenerator()->create_course(array('numsections' => 1, 'enablecompletion' => COMPLETION_ENABLED), array('createsections' => true)); $grouping = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id)); // Create assign module instance for testing gradeitem. $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); $params['course'] = $course->id; $instance = $generator->create_instance($params); $assigncm = get_coursemodule_from_instance('assign', $instance->id); // Create the test forum to update. $initvalues = new stdClass(); $initvalues->introformat = FORMAT_HTML; $initvalues->course = $course->id; $forum = self::getDataGenerator()->create_module('forum', $initvalues); // Retrieve course module. $cm = get_coursemodule_from_instance('forum', $forum->id); // Module test values. $moduleinfo = new stdClass(); // Always mandatory generic values to any module. $moduleinfo->coursemodule = $cm->id; $moduleinfo->modulename = $modulename; $moduleinfo->course = $course->id; $moduleinfo->groupingid = $grouping->id; $moduleinfo->groupmembersonly = 0; $moduleinfo->visible = true; // Sometimes optional generic values for some modules. $moduleinfo->name = 'My test module'; $moduleinfo->showdescription = 1; // standard boolean require_once $CFG->libdir . '/gradelib.php'; $gradecats = grade_get_categories_menu($moduleinfo->course, false); $gradecatid = current(array_keys($gradecats)); // Retrieve the first key of $gradecats $moduleinfo->gradecat = $gradecatid; $moduleinfo->groupmode = VISIBLEGROUPS; $moduleinfo->cmidnumber = 'idnumber_XXX'; // Completion common to all module. $moduleinfo->completion = COMPLETION_TRACKING_AUTOMATIC; $moduleinfo->completionview = COMPLETION_VIEW_REQUIRED; $moduleinfo->completiongradeitemnumber = 1; $moduleinfo->completionexpected = time() + 7 * 24 * 3600; $moduleinfo->completionunlocked = 1; // Conditional activity. $moduleinfo->availablefrom = time(); $moduleinfo->availableuntil = time() + 7 * 24 * 3600; $moduleinfo->showavailability = CONDITION_STUDENTVIEW_SHOW; $coursegradeitem = grade_item::fetch_course_item($moduleinfo->course); //the activity will become available only when the user reach some grade into the course itself. $moduleinfo->conditiongradegroup = array(array('conditiongradeitemid' => $coursegradeitem->id, 'conditiongrademin' => 10, 'conditiongrademax' => 80)); $moduleinfo->conditionfieldgroup = array(array('conditionfield' => 'email', 'conditionfieldoperator' => OP_CONTAINS, 'conditionfieldvalue' => '@')); $moduleinfo->conditioncompletiongroup = array(array('conditionsourcecmid' => $assigncm->id, 'conditionrequiredcompletion' => COMPLETION_COMPLETE)); // "conditionsourcecmid == 0" => none // Grading and Advanced grading. require_once $CFG->dirroot . '/rating/lib.php'; $moduleinfo->assessed = RATING_AGGREGATE_AVERAGE; $moduleinfo->scale = 10; // Note: it could be minus (for specific course scale). It is a signed number. $moduleinfo->assesstimestart = time(); $moduleinfo->assesstimefinish = time() + 7 * 24 * 3600; // RSS. $moduleinfo->rsstype = 2; $moduleinfo->rssarticles = 10; // Optional intro editor (depends of module). $draftid_editor = 0; file_prepare_draft_area($draftid_editor, null, null, null, null); $moduleinfo->introeditor = array('text' => 'This is a module', 'format' => FORMAT_HTML, 'itemid' => $draftid_editor); // Following is the advanced grading method area called 'submissions' for the 'assign' module. if (plugin_supports('mod', $modulename, FEATURE_GRADE_HAS_GRADE, false) && !plugin_supports('mod', $modulename, FEATURE_RATE, false)) { $moduleinfo->grade = 100; } // Plagiarism form values. // No plagiarism plugin installed by default. Use this space to make your own test. // Values specific to the module. $modulesetvalues = $modulename . '_update_set_values'; $this->{$modulesetvalues}($moduleinfo); // Create the module. $result = update_module($moduleinfo); // Retrieve the module info. $dbmodinstance = $DB->get_record($moduleinfo->modulename, array('id' => $result->instance)); $dbcm = get_coursemodule_from_instance($moduleinfo->modulename, $result->instance); // Retrieve the grade item. $gradeitem = $DB->get_record('grade_items', array('courseid' => $moduleinfo->course, 'iteminstance' => $dbmodinstance->id, 'itemmodule' => $moduleinfo->modulename)); // Compare the values common to all module instances. $this->assertEquals($moduleinfo->modulename, $dbcm->modname); $this->assertEquals($moduleinfo->course, $dbcm->course); $this->assertEquals($moduleinfo->groupingid, $dbcm->groupingid); $this->assertEquals($moduleinfo->groupmembersonly, $dbcm->groupmembersonly); $this->assertEquals($moduleinfo->visible, $dbcm->visible); $this->assertEquals($moduleinfo->completion, $dbcm->completion); $this->assertEquals($moduleinfo->completionview, $dbcm->completionview); $this->assertEquals($moduleinfo->completiongradeitemnumber, $dbcm->completiongradeitemnumber); $this->assertEquals($moduleinfo->completionexpected, $dbcm->completionexpected); $this->assertEquals($moduleinfo->availablefrom, $dbcm->availablefrom); $this->assertEquals($moduleinfo->availableuntil, $dbcm->availableuntil); $this->assertEquals($moduleinfo->showavailability, $dbcm->showavailability); $this->assertEquals($moduleinfo->showdescription, $dbcm->showdescription); $this->assertEquals($moduleinfo->groupmode, $dbcm->groupmode); $this->assertEquals($moduleinfo->cmidnumber, $dbcm->idnumber); $this->assertEquals($moduleinfo->gradecat, $gradeitem->categoryid); // Optional grade testing. if (plugin_supports('mod', $modulename, FEATURE_GRADE_HAS_GRADE, false) && !plugin_supports('mod', $modulename, FEATURE_RATE, false)) { $this->assertEquals($moduleinfo->grade, $dbmodinstance->grade); } // Some optional (but quite common) to some module. $this->assertEquals($moduleinfo->name, $dbmodinstance->name); $this->assertEquals($moduleinfo->intro, $dbmodinstance->intro); $this->assertEquals($moduleinfo->introformat, $dbmodinstance->introformat); // Common values when conditional activity is enabled. foreach ($moduleinfo->conditionfieldgroup as $fieldgroup) { $isfieldgroupsaved = $DB->count_records('course_modules_avail_fields', array('coursemoduleid' => $dbcm->id, 'userfield' => $fieldgroup['conditionfield'], 'operator' => $fieldgroup['conditionfieldoperator'], 'value' => $fieldgroup['conditionfieldvalue'])); $this->assertEquals(1, $isfieldgroupsaved); } foreach ($moduleinfo->conditiongradegroup as $gradegroup) { $isgradegroupsaved = $DB->count_records('course_modules_availability', array('coursemoduleid' => $dbcm->id, 'grademin' => $gradegroup['conditiongrademin'], 'grademax' => $gradegroup['conditiongrademax'], 'gradeitemid' => $gradegroup['conditiongradeitemid'])); $this->assertEquals(1, $isgradegroupsaved); } foreach ($moduleinfo->conditioncompletiongroup as $completiongroup) { $iscompletiongroupsaved = $DB->count_records('course_modules_availability', array('coursemoduleid' => $dbcm->id, 'sourcecmid' => $completiongroup['conditionsourcecmid'], 'requiredcompletion' => $completiongroup['conditionrequiredcompletion'])); $this->assertEquals(1, $iscompletiongroupsaved); } // Test specific to the module. $modulerunasserts = $modulename . '_update_run_asserts'; $this->{$modulerunasserts}($moduleinfo, $dbmodinstance); return $moduleinfo; }
/** main entry point for update wizard (called from /program/main_admin.php) * * This routine takes care of executing update routines for both the core * program and modules, themes, etc. It is called automagically whenever * the core program version in the database is different from the version * in the file {@lnk version.php} (see also {@link main_admin()}). * * It can also be called manually via 'job=update'. When no specific * task is specified, this routine shows the overview of versions for * core, modules, themes, etc. Whenever a component is NOT up to date, * an [Update] button is displayed. If a component IS up to date, we * simply display the word 'OK'. This implies that when everything is up * to date, the overview simply displays a list of OK's and the user * is 'free to go'. * * The actual updates for modules, themes, etc. is done via the various * subsystems themselves, e.g. by calling htmlpage_upgrade() in the file * /program/modules/htmlpage/htmlpage_install.php. The updates for the * core program are actually performed from this file right here, see * {@link update_core_2010120800()} below for an example. * * Note that we give a core update high priority: if the core * is not up to date, nothing will work, except updating the core. * * @param object &$output collects the html output * @return void results are returned as output in $output */ function job_update(&$output) { global $CFG, $WAS_SCRIPT_NAME, $USER; $output->set_helptopic('update'); $task = get_parameter_string('task', TASK_UPDATE_OVERVIEW); if ($task == TASK_UPDATE_OVERVIEW) { update_show_overview($output); } elseif ($task == TASK_UPDATE_CORE) { update_core($output); update_show_overview($output); } elseif (intval($CFG->version) != intval(WAS_VERSION)) { $output->add_message(t('update_core_warnning_core_goes_first', 'admin')); update_show_overview($output); } else { $key = get_parameter_string('key', ''); switch ($task) { case TASK_INSTALL_LANGUAGE: install_language($output, $key); update_show_overview($output); break; case TASK_UPDATE_LANGUAGE: update_language($output, $key); update_show_overview($output); break; case TASK_INSTALL_MODULE: install_module($output, $key); update_show_overview($output); break; case TASK_UPDATE_MODULE: update_module($output, $key); update_show_overview($output); break; case TASK_INSTALL_THEME: install_theme($output, $key); update_show_overview($output); break; case TASK_UPDATE_THEME: update_theme($output, $key); update_show_overview($output); break; default: $s = utf8_strlen($task) <= 50 ? $task : utf8_substr($task, 0, 44) . ' (...)'; $message = t('task_unknown', 'admin', array('{TASK}' => htmlspecialchars($s))); $output->add_message($message); logger('tools: unknown task: ' . htmlspecialchars($s)); update_show_overview($output); break; } } }