当前位置: 首页>>代码示例>>PHP>>正文


PHP raise_memory_limit函数代码示例

本文整理汇总了PHP中raise_memory_limit函数的典型用法代码示例。如果您正苦于以下问题:PHP raise_memory_limit函数的具体用法?PHP raise_memory_limit怎么用?PHP raise_memory_limit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了raise_memory_limit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: make

 /**
  * Runs the entire 'make' process.
  *
  * @return int Course id
  */
 public function make()
 {
     global $DB, $CFG;
     raise_memory_limit(MEMORY_EXTRA);
     if ($this->progress && !CLI_SCRIPT) {
         echo html_writer::start_tag('ul');
     }
     $entirestart = microtime(true);
     // Create courses.
     $prevchdir = getcwd();
     chdir($CFG->dirroot);
     $ncourse = self::get_last_testcourse_id();
     foreach (self::$sitecourses as $coursesize => $ncourses) {
         for ($i = 1; $i <= $ncourses[$this->size]; $i++) {
             // Non language-dependant shortname.
             $ncourse++;
             $this->run_create_course(self::SHORTNAMEPREFIX . $ncourse, $coursesize);
         }
     }
     chdir($prevchdir);
     // Store last course id to return it (will be the bigger one).
     $lastcourseid = $DB->get_field('course', 'id', array('shortname' => self::SHORTNAMEPREFIX . $ncourse));
     // Log total time.
     $this->log('sitecompleted', round(microtime(true) - $entirestart, 1));
     if ($this->progress && !CLI_SCRIPT) {
         echo html_writer::end_tag('ul');
     }
     return $lastcourseid;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:34,代码来源:site_backend.php

示例2: search

 public function search($q, $courseID = 0, $removeHiddenResults = false)
 {
     if (strlen($q) < 2) {
         return array('error' => get_string('error_query_too_short', 'block_search', 2));
     }
     raise_memory_limit(MEMORY_UNLIMITED);
     //Check if user cached results exist
     $userCacheValidFor = (int) get_config('block_search', 'cache_results_per_user');
     $useUserCache = $userCacheValidFor > 0;
     if (is_siteadmin()) {
         $useUserCache = false;
     }
     if ($useUserCache) {
         $cacheKey = md5(json_encode(array($q, $courseID, $removeHiddenResults)));
         $userCache = cache::make('block_search', 'user_searches');
         if ($results = $userCache->get($cacheKey)) {
             if ($results['filtered'] > time() - (int) $userCacheValidFor) {
                 $results['userCached'] = true;
                 return $results;
             }
         }
     }
     $search = new Search($q, $courseID);
     $search->filterResults($removeHiddenResults);
     $results = $search->getResults();
     if ($useUserCache) {
         $userCache->set($cacheKey, $results);
     }
     return $results;
 }
开发者ID:papillon326,项目名称:moodle-block_search,代码行数:30,代码来源:Block.php

示例3: process

 /**
  * Takes the original course object, subpage cm id and
  * target course. It backs up a subpage in a course, modifies the
  * backup data, creates and restores to target course.
  *
  * @param mod_subpage $subpage subpage to copy from
  * @param object $newcourse Target course object
  */
 public function process($subpage, $newcourse)
 {
     global $CFG, $DB;
     // Start transaction.
     $transaction = $DB->start_delegated_transaction();
     // Raise memory limit for backup and restore.
     raise_memory_limit(MEMORY_EXTRA);
     echo \html_writer::tag('div', get_string('copy_wait', 'subpage'));
     $spsectionid = $subpage->get_course_module()->section;
     // Backup the course.
     $backupstart = time();
     $this->display_progress(get_string('copy_backingupcourse', 'subpage'));
     list($activityids, $sectionids) = $this->get_includes($subpage);
     $backupid = $this->backup($subpage->get_course(), $activityids, array_merge($sectionids, array($spsectionid)));
     $this->display_progress(null, $backupstart);
     // Update backup file.
     $updatebackupstart = time();
     $this->display_progress(get_string('copy_modifyingbackup', 'subpage'));
     $this->update_backup($this->backupbasepath, $newcourse->id, $sectionids, $spsectionid, $subpage->get_course_module()->id);
     $this->display_progress(null, $updatebackupstart);
     // Restore into a new course.
     $restorestart = time();
     $this->display_progress(get_string('copy_restoringcourse', 'subpage'));
     $this->restore($backupid, $newcourse);
     $this->display_progress(null, $restorestart);
     // Completed OK, so commit transaction.
     $transaction->allow_commit();
 }
开发者ID:ninelanterns,项目名称:moodle-mod_subpage,代码行数:36,代码来源:lib.php

示例4: print_object_moodle

function print_object_moodle($object)
{
    // we may need a lot of memory here
    raise_memory_limit(MEMORY_EXTRA);
    if (CLI_SCRIPT) {
        //fwrite(STDERR, print_r($object, true));
        // fwrite(STDERR, PHP_EOL);
    } else {
        echo html_writer::tag('pre', s(print_r($object, true)), array('class' => 'notifytiny'));
    }
}
开发者ID:ftecpos,项目名称:ia2,代码行数:11,代码来源:lib.php

示例5: transaction_starts

 /**
  * Inform existing open recordsets that transaction
  * is starting, this works around MARS problem described
  * in MDL-37734.
  */
 public function transaction_starts()
 {
     if ($this->buffer !== null) {
         $this->unregister();
         return;
     }
     if (!$this->rsrc) {
         $this->unregister();
         return;
     }
     // This might eat memory pretty quickly...
     raise_memory_limit('2G');
     $this->buffer = array();
     while ($next = $this->fetch_next()) {
         $this->buffer[] = $next;
     }
 }
开发者ID:Burick,项目名称:moodle,代码行数:22,代码来源:sqlsrv_native_moodle_recordset.php

示例6: apply

 function apply($discussion, $all, $selected, $formdata)
 {
     global $COURSE, $USER, $CFG;
     // Get HTML
     $poststext = '';
     $postshtml = '';
     $discussion->build_selected_posts_email($selected, $poststext, $postshtml, false);
     // Remove all styles
     $postshtml = preg_replace('~(<[^>]*)\\sclass\\s*=\\s*("[^"]*")|(\'[^\']*\')([^>*]>)~', '$1$4', $postshtml);
     $postshtml = preg_replace('~(<[^>]*)\\sstyle\\s*=\\s*("[^"]*")|(\'[^\']*\')([^>*]>)~', '$1$4', $postshtml);
     $postshtml = preg_replace('~<hr[^>]*/>~', '', $postshtml);
     // Add link back to discussion
     $postshtml .= '<div><a href="' . $CFG->wwwroot . '/mod/forumng/discuss.php?' . $discussion->get_link_params(forum::PARAM_HTML) . '">' . get_string('savedposts_original', 'forumng') . '</a></div>';
     // Get title
     if ($all) {
         $title = get_string('savedposts_all', 'forumng', $discussion->get_subject());
         $tags = get_string('savedposts_all_tag', 'forumng');
     } else {
         if (count($selected) == 1) {
             $post = $discussion->get_root_post()->find_child(reset($selected));
             $a = (object) array('subject' => $post->get_effective_subject(), 'name' => $post->get_forum()->display_user_name($post->get_user()));
             $title = get_string('savedposts_one', 'forumng', $a);
             $tags = get_string('savedposts_one_tag', 'forumng');
         } else {
             $title = get_string('savedposts_selected', 'forumng', $discussion->get_subject());
             $tags = get_string('savedposts_selected_tag', 'forumng');
         }
     }
     raise_memory_limit('512M');
     // Do portfolio save
     $username = portfolioGetUsername();
     $itemid = "forumngposts" . portfolioGetUUID();
     $dataid = portfolioFormPutContent($itemid, array('ouportfolio:title' => $title, 'ouportfolio:tags' => $tags), $postshtml);
     // Redirect back to discussion
     $discussionurl = $CFG->wwwroot . '/mod/forumng/discuss.php?' . $discussion->get_link_params(forum::PARAM_PLAIN);
     if ($dataid === FALSE) {
         print_error('error_portfoliosave', 'forumng', $discussionurl);
     } else {
         redirect($discussionurl, get_string('savedtoportfolio', 'forumng'));
     }
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:41,代码来源:savetoportfolio.php

示例7: execute_plan

 /**
  * Executes the backup
  * @return void Throws and exception of completes
  */
 public function execute_plan()
 {
     // Basic/initial prevention against time/memory limits
     core_php_time_limit::raise(1 * 60 * 60);
     // 1 hour for 1 course initially granted
     raise_memory_limit(MEMORY_EXTRA);
     // If this is not a course backup, inform the plan we are not
     // including all the activities for sure. This will affect any
     // task/step executed conditionally to stop including information
     // for section and activity backup. MDL-28180.
     if ($this->get_type() !== backup::TYPE_1COURSE) {
         $this->log('notifying plan about excluded activities by type', backup::LOG_DEBUG);
         $this->plan->set_excluding_activities();
     }
     return $this->plan->execute();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:backup_controller.class.php

示例8: run_automated_backup

 /**
  * Runs the automated backups if required
  *
  * @global moodle_database $DB
  */
 public static function run_automated_backup($rundirective = self::RUN_ON_SCHEDULE)
 {
     global $CFG, $DB;
     $status = true;
     $emailpending = false;
     $now = time();
     $config = get_config('backup');
     mtrace("Checking automated backup status", '...');
     $state = backup_cron_automated_helper::get_automated_backup_state($rundirective);
     if ($state === backup_cron_automated_helper::STATE_DISABLED) {
         mtrace('INACTIVE');
         return $state;
     } else {
         if ($state === backup_cron_automated_helper::STATE_RUNNING) {
             mtrace('RUNNING');
             if ($rundirective == self::RUN_IMMEDIATELY) {
                 mtrace('Automated backups are already running. If this script is being run by cron this constitues an error. You will need to increase the time between executions within cron.');
             } else {
                 mtrace("automated backup are already running. Execution delayed");
             }
             return $state;
         } else {
             mtrace('OK');
         }
     }
     backup_cron_automated_helper::set_state_running();
     mtrace("Getting admin info");
     $admin = get_admin();
     if (!$admin) {
         mtrace("Error: No admin account was found");
         $state = false;
     }
     if ($status) {
         mtrace("Checking courses");
         mtrace("Skipping deleted courses", '...');
         mtrace(sprintf("%d courses", backup_cron_automated_helper::remove_deleted_courses_from_schedule()));
     }
     if ($status) {
         mtrace('Running required automated backups...');
         cron_trace_time_and_memory();
         // This could take a while!
         core_php_time_limit::raise();
         raise_memory_limit(MEMORY_EXTRA);
         $nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup($admin->timezone, $now);
         $showtime = "undefined";
         if ($nextstarttime > 0) {
             $showtime = date('r', $nextstarttime);
         }
         $rs = $DB->get_recordset('course');
         foreach ($rs as $course) {
             $backupcourse = $DB->get_record('backup_courses', array('courseid' => $course->id));
             if (!$backupcourse) {
                 $backupcourse = new stdClass();
                 $backupcourse->courseid = $course->id;
                 $backupcourse->laststatus = self::BACKUP_STATUS_NOTYETRUN;
                 $DB->insert_record('backup_courses', $backupcourse);
                 $backupcourse = $DB->get_record('backup_courses', array('courseid' => $course->id));
             }
             // The last backup is considered as successful when OK or SKIPPED.
             $lastbackupwassuccessful = ($backupcourse->laststatus == self::BACKUP_STATUS_SKIPPED || $backupcourse->laststatus == self::BACKUP_STATUS_OK) && ($backupcourse->laststarttime > 0 && $backupcourse->lastendtime > 0);
             // Assume that we are not skipping anything.
             $skipped = false;
             $skippedmessage = '';
             // Check if we are going to be running the backup now.
             $shouldrunnow = $backupcourse->nextstarttime > 0 && $backupcourse->nextstarttime < $now || $rundirective == self::RUN_IMMEDIATELY;
             // If config backup_auto_skip_hidden is set to true, skip courses that are not visible.
             if ($shouldrunnow && $config->backup_auto_skip_hidden) {
                 $skipped = $config->backup_auto_skip_hidden && !$course->visible;
                 $skippedmessage = 'Not visible';
             }
             // If config backup_auto_skip_modif_days is set to true, skip courses
             // that have not been modified since the number of days defined.
             if ($shouldrunnow && !$skipped && $lastbackupwassuccessful && $config->backup_auto_skip_modif_days) {
                 $timenotmodifsincedays = $now - $config->backup_auto_skip_modif_days * DAYSECS;
                 // Check log if there were any modifications to the course content.
                 $logexists = self::is_course_modified($course->id, $timenotmodifsincedays);
                 $skipped = $course->timemodified <= $timenotmodifsincedays && !$logexists;
                 $skippedmessage = 'Not modified in the past ' . $config->backup_auto_skip_modif_days . ' days';
             }
             // If config backup_auto_skip_modif_prev is set to true, skip courses
             // that have not been modified since previous backup.
             if ($shouldrunnow && !$skipped && $lastbackupwassuccessful && $config->backup_auto_skip_modif_prev) {
                 // Check log if there were any modifications to the course content.
                 $logexists = self::is_course_modified($course->id, $backupcourse->laststarttime);
                 $skipped = $course->timemodified <= $backupcourse->laststarttime && !$logexists;
                 $skippedmessage = 'Not modified since previous backup';
             }
             // Check if the course is not scheduled to run right now.
             if (!$shouldrunnow) {
                 $backupcourse->nextstarttime = $nextstarttime;
                 $DB->update_record('backup_courses', $backupcourse);
                 mtrace('Skipping ' . $course->fullname . ' (Not scheduled for backup until ' . $showtime . ')');
             } else {
                 if ($skipped) {
                     // Must have been skipped for a reason.
//.........这里部分代码省略.........
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:101,代码来源:backup_cron_helper.class.php

示例9: optional_param

 * @copyright  2004 onwards Martin Dougiamas (http://dougiamas.com)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require '../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/csvlib.class.php';
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/group/lib.php';
require_once $CFG->dirroot . '/cohort/lib.php';
require_once 'uploaduserlib.php';
require_once 'uploaduser_form.php';
$iid = optional_param('iid', '', PARAM_INT);
$previewrows = optional_param('previewrows', 10, PARAM_INT);
@set_time_limit(60 * 60);
// 1 hour should be enough
raise_memory_limit(MEMORY_HUGE);
require_login();
admin_externalpage_setup('uploadusers');
require_capability('moodle/site:uploadusers', get_context_instance(CONTEXT_SYSTEM));
$struserrenamed = get_string('userrenamed', 'admin');
$strusernotrenamedexists = get_string('usernotrenamedexists', 'error');
$strusernotrenamedmissing = get_string('usernotrenamedmissing', 'error');
$strusernotrenamedoff = get_string('usernotrenamedoff', 'error');
$strusernotrenamedadmin = get_string('usernotrenamedadmin', 'error');
$struserupdated = get_string('useraccountupdated', 'admin');
$strusernotupdated = get_string('usernotupdatederror', 'error');
$strusernotupdatednotexists = get_string('usernotupdatednotexists', 'error');
$strusernotupdatedadmin = get_string('usernotupdatedadmin', 'error');
$struseruptodate = get_string('useraccountuptodate', 'admin');
$struseradded = get_string('newuser');
$strusernotadded = get_string('usernotaddedregistered', 'error');
开发者ID:richheath,项目名称:moodle,代码行数:31,代码来源:uploaduser.php

示例10: cron_run

/**
 * Execute cron tasks
 */
function cron_run()
{
    global $DB, $CFG, $OUTPUT;
    if (CLI_MAINTENANCE) {
        echo "CLI maintenance mode active, cron execution suspended.\n";
        exit(1);
    }
    if (moodle_needs_upgrading()) {
        echo "Moodle upgrade pending, cron execution suspended.\n";
        exit(1);
    }
    require_once $CFG->libdir . '/adminlib.php';
    require_once $CFG->libdir . '/gradelib.php';
    if (!empty($CFG->showcronsql)) {
        $DB->set_debug(true);
    }
    if (!empty($CFG->showcrondebugging)) {
        set_debugging(DEBUG_DEVELOPER, true);
    }
    set_time_limit(0);
    $starttime = microtime();
    // Increase memory limit
    raise_memory_limit(MEMORY_EXTRA);
    // Emulate normal session - we use admin accoutn by default
    cron_setup_user();
    // Start output log
    $timenow = time();
    mtrace("Server Time: " . date('r', $timenow) . "\n\n");
    // Run cleanup core cron jobs, but not every time since they aren't too important.
    // These don't have a timer to reduce load, so we'll use a random number
    // to randomly choose the percentage of times we should run these jobs.
    $random100 = rand(0, 100);
    if ($random100 < 20) {
        // Approximately 20% of the time.
        mtrace("Running clean-up tasks...");
        cron_trace_time_and_memory();
        // Delete users who haven't confirmed within required period
        if (!empty($CFG->deleteunconfirmed)) {
            $cuttime = $timenow - $CFG->deleteunconfirmed * 3600;
            $rs = $DB->get_recordset_sql("SELECT *\n                                             FROM {user}\n                                            WHERE confirmed = 0 AND firstaccess > 0\n                                                  AND firstaccess < ?", array($cuttime));
            foreach ($rs as $user) {
                delete_user($user);
                // we MUST delete user properly first
                $DB->delete_records('user', array('id' => $user->id));
                // this is a bloody hack, but it might work
                mtrace(" Deleted unconfirmed user for " . fullname($user, true) . " ({$user->id})");
            }
            $rs->close();
        }
        // Delete users who haven't completed profile within required period
        if (!empty($CFG->deleteincompleteusers)) {
            $cuttime = $timenow - $CFG->deleteincompleteusers * 3600;
            $rs = $DB->get_recordset_sql("SELECT *\n                                             FROM {user}\n                                            WHERE confirmed = 1 AND lastaccess > 0\n                                                  AND lastaccess < ? AND deleted = 0\n                                                  AND (lastname = '' OR firstname = '' OR email = '')", array($cuttime));
            foreach ($rs as $user) {
                if (isguestuser($user) or is_siteadmin($user)) {
                    continue;
                }
                delete_user($user);
                mtrace(" Deleted not fully setup user {$user->username} ({$user->id})");
            }
            $rs->close();
        }
        // Delete old logs to save space (this might need a timer to slow it down...)
        if (!empty($CFG->loglifetime)) {
            // value in days
            $loglifetime = $timenow - $CFG->loglifetime * 3600 * 24;
            $DB->delete_records_select("log", "time < ?", array($loglifetime));
            mtrace(" Deleted old log records");
        }
        // Delete old backup_controllers and logs.
        $loglifetime = get_config('backup', 'loglifetime');
        if (!empty($loglifetime)) {
            // Value in days.
            $loglifetime = $timenow - $loglifetime * 3600 * 24;
            // Delete child records from backup_logs.
            $DB->execute("DELETE FROM {backup_logs}\n                           WHERE EXISTS (\n                               SELECT 'x'\n                                 FROM {backup_controllers} bc\n                                WHERE bc.backupid = {backup_logs}.backupid\n                                  AND bc.timecreated < ?)", array($loglifetime));
            // Delete records from backup_controllers.
            $DB->execute("DELETE FROM {backup_controllers}\n                          WHERE timecreated < ?", array($loglifetime));
            mtrace(" Deleted old backup records");
        }
        // Delete old cached texts
        if (!empty($CFG->cachetext)) {
            // Defined in config.php
            $cachelifetime = time() - $CFG->cachetext - 60;
            // Add an extra minute to allow for really heavy sites
            $DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime));
            mtrace(" Deleted old cache_text records");
        }
        if (!empty($CFG->usetags)) {
            require_once $CFG->dirroot . '/tag/lib.php';
            tag_cron();
            mtrace(' Executed tag cron');
        }
        // Context maintenance stuff
        context_helper::cleanup_instances();
        mtrace(' Cleaned up context instances');
        context_helper::build_all_paths(false);
//.........这里部分代码省略.........
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:101,代码来源:cronlib.php

示例11: sync_courses

 /**
  * Performs a full sync with external database.
  *
  * First it creates new courses if necessary, then
  * enrols and unenrols users.
  *
  * @param bool $verbose
  * @return int 0 means success, 1 db connect failure, 4 db read failure
  */
 public function sync_courses($verbose = false)
 {
     global $CFG, $DB;
     // make sure we sync either enrolments or courses
     if (!$this->get_config('dbtype') or !$this->get_config('dbhost') or !$this->get_config('newcoursetable') or !$this->get_config('newcoursefullname') or !$this->get_config('newcourseshortname')) {
         if ($verbose) {
             mtrace('Course synchronisation skipped.');
         }
         return 0;
     }
     if ($verbose) {
         mtrace('Starting course synchronisation...');
     }
     // we may need a lot of memory here
     @set_time_limit(0);
     raise_memory_limit(MEMORY_HUGE);
     if (!($extdb = $this->db_init())) {
         mtrace('Error while communicating with external enrolment database');
         return 1;
     }
     // first create new courses
     $table = $this->get_config('newcoursetable');
     $fullname = strtolower($this->get_config('newcoursefullname'));
     $shortname = strtolower($this->get_config('newcourseshortname'));
     $idnumber = strtolower($this->get_config('newcourseidnumber'));
     $category = strtolower($this->get_config('newcoursecategory'));
     $localcategoryfield = $this->get_config('localcategoryfield', 'id');
     $sqlfields = array($fullname, $shortname);
     if ($category) {
         $sqlfields[] = $category;
     }
     if ($idnumber) {
         $sqlfields[] = $idnumber;
     }
     $sql = $this->db_get_sql($table, array(), $sqlfields);
     $createcourses = array();
     if ($rs = $extdb->Execute($sql)) {
         if (!$rs->EOF) {
             while ($fields = $rs->FetchRow()) {
                 $fields = array_change_key_case($fields, CASE_LOWER);
                 $fields = $this->db_decode($fields);
                 if (empty($fields[$shortname]) or empty($fields[$fullname])) {
                     if ($verbose) {
                         mtrace('  error: invalid external course record, shortname and fullname are mandatory: ' . json_encode($fields));
                         // hopefully every geek can read JS, right?
                     }
                     continue;
                 }
                 if ($DB->record_exists('course', array('shortname' => $fields[$shortname]))) {
                     // already exists
                     continue;
                 }
                 // allow empty idnumber but not duplicates
                 if ($idnumber and $fields[$idnumber] !== '' and $fields[$idnumber] !== null and $DB->record_exists('course', array('idnumber' => $fields[$idnumber]))) {
                     if ($verbose) {
                         mtrace('  error: duplicate idnumber, can not create course: ' . $fields[$shortname] . ' [' . $fields[$idnumber] . ']');
                     }
                     continue;
                 }
                 if ($category and !($coursecategory = $DB->get_record('course_categories', array($localcategoryfield => $fields[$category]), 'id'))) {
                     if ($verbose) {
                         mtrace('  error: invalid category ' . $localcategoryfield . ', can not create course: ' . $fields[$shortname]);
                     }
                     continue;
                 }
                 $course = new stdClass();
                 $course->fullname = $fields[$fullname];
                 $course->shortname = $fields[$shortname];
                 $course->idnumber = $idnumber ? $fields[$idnumber] : '';
                 $course->category = $category ? $coursecategory->id : NULL;
                 $createcourses[] = $course;
             }
         }
         $rs->Close();
     } else {
         mtrace('Error reading data from the external course table');
         $extdb->Close();
         return 4;
     }
     if ($createcourses) {
         require_once "{$CFG->dirroot}/course/lib.php";
         $templatecourse = $this->get_config('templatecourse');
         $defaultcategory = $this->get_config('defaultcategory');
         $template = false;
         if ($templatecourse) {
             if ($template = $DB->get_record('course', array('shortname' => $templatecourse))) {
                 unset($template->id);
                 unset($template->fullname);
                 unset($template->shortname);
                 unset($template->idnumber);
             } else {
//.........这里部分代码省略.........
开发者ID:numbas,项目名称:moodle,代码行数:101,代码来源:lib.php

示例12: sync_enrolments

 /**
  * Forces synchronisation of all enrolments with LDAP server.
  * It creates courses if the plugin is configured to do so.
  *
  * @param progress_trace $trace
  * @param int|null $onecourse limit sync to one course->id, null if all courses
  * @return void
  */
 public function sync_enrolments(progress_trace $trace, $onecourse = null)
 {
     global $CFG, $DB;
     if (!$this->ldap_connect($trace)) {
         $trace->finished();
         return;
     }
     $ldap_pagedresults = ldap_paged_results_supported($this->get_config('ldap_version'));
     // we may need a lot of memory here
     core_php_time_limit::raise();
     raise_memory_limit(MEMORY_HUGE);
     $oneidnumber = null;
     if ($onecourse) {
         if (!($course = $DB->get_record('course', array('id' => $onecourse), 'id,' . $this->enrol_localcoursefield))) {
             // Course does not exist, nothing to do.
             $trace->output("Requested course {$onecourse} does not exist, no sync performed.");
             $trace->finished();
             return;
         }
         if (empty($course->{$this->enrol_localcoursefield})) {
             $trace->output("Requested course {$onecourse} does not have {$this->enrol_localcoursefield}, no sync performed.");
             $trace->finished();
             return;
         }
         $oneidnumber = ldap_filter_addslashes(core_text::convert($course->idnumber, 'utf-8', $this->get_config('ldapencoding')));
     }
     // Get enrolments for each type of role.
     $roles = get_all_roles();
     $enrolments = array();
     foreach ($roles as $role) {
         // Get all contexts
         $ldap_contexts = explode(';', $this->config->{'contexts_role' . $role->id});
         // Get all the fields we will want for the potential course creation
         // as they are light. Don't get membership -- potentially a lot of data.
         $ldap_fields_wanted = array('dn', $this->config->course_idnumber);
         if (!empty($this->config->course_fullname)) {
             array_push($ldap_fields_wanted, $this->config->course_fullname);
         }
         if (!empty($this->config->course_shortname)) {
             array_push($ldap_fields_wanted, $this->config->course_shortname);
         }
         if (!empty($this->config->course_summary)) {
             array_push($ldap_fields_wanted, $this->config->course_summary);
         }
         array_push($ldap_fields_wanted, $this->config->{'memberattribute_role' . $role->id});
         // Define the search pattern
         $ldap_search_pattern = $this->config->objectclass;
         if ($oneidnumber !== null) {
             $ldap_search_pattern = "(&{$ldap_search_pattern}({$this->config->course_idnumber}={$oneidnumber}))";
         }
         $ldap_cookie = '';
         foreach ($ldap_contexts as $ldap_context) {
             $ldap_context = trim($ldap_context);
             if (empty($ldap_context)) {
                 continue;
                 // Next;
             }
             $flat_records = array();
             do {
                 if ($ldap_pagedresults) {
                     ldap_control_paged_result($this->ldapconnection, $this->config->pagesize, true, $ldap_cookie);
                 }
                 if ($this->config->course_search_sub) {
                     // Use ldap_search to find first user from subtree
                     $ldap_result = @ldap_search($this->ldapconnection, $ldap_context, $ldap_search_pattern, $ldap_fields_wanted);
                 } else {
                     // Search only in this context
                     $ldap_result = @ldap_list($this->ldapconnection, $ldap_context, $ldap_search_pattern, $ldap_fields_wanted);
                 }
                 if (!$ldap_result) {
                     continue;
                     // Next
                 }
                 if ($ldap_pagedresults) {
                     ldap_control_paged_result_response($this->ldapconnection, $ldap_result, $ldap_cookie);
                 }
                 // Check and push results
                 $records = ldap_get_entries($this->ldapconnection, $ldap_result);
                 // LDAP libraries return an odd array, really. fix it:
                 for ($c = 0; $c < $records['count']; $c++) {
                     array_push($flat_records, $records[$c]);
                 }
                 // Free some mem
                 unset($records);
             } while ($ldap_pagedresults && !empty($ldap_cookie));
             // If LDAP paged results were used, the current connection must be completely
             // closed and a new one created, to work without paged results from here on.
             if ($ldap_pagedresults) {
                 $this->ldap_close();
                 $this->ldap_connect($trace);
             }
             if (count($flat_records)) {
//.........这里部分代码省略.........
开发者ID:abhilash1994,项目名称:moodle,代码行数:101,代码来源:lib.php

示例13: allocate_extra_resources

 /**
  * Temporarily allocates extra resources needed to export reports
  */
 static function allocate_extra_resources()
 {
     global $CFG;
     //disable the time limit for this executing script
     @set_time_limit(0);
     //up the memory limit
     if (empty($CFG->extramemorylimit)) {
         raise_memory_limit('128M');
     } else {
         raise_memory_limit($CFG->extramemorylimit);
     }
 }
开发者ID:remotelearner,项目名称:elis.reporting,代码行数:15,代码来源:php_report_base.php

示例14: import_backup_file_silently

/** this function will restore an entire backup.zip into the specified course
 * using standard moodle backup/restore functions, but silently.
 * @param string $pathtofile the absolute path to the backup file.
 * @param int $destinationcourse the course id to restore to.
 * @param boolean $emptyfirst whether to delete all coursedata first.
 * @param boolean $userdata whether to include any userdata that may be in the backup file.
 * @param array $preferences optional, 0 will be used.  Can contain:
 *   metacourse
 *   logs
 *   course_files
 *   messages
 */
function import_backup_file_silently($pathtofile, $destinationcourse, $emptyfirst = false, $userdata = false, $preferences = array())
{
    global $CFG, $SESSION, $USER, $DB;
    // is there such a thing on cron? I guess so..
    global $restore;
    // ick
    if (!defined('RESTORE_SILENTLY')) {
        define('RESTORE_SILENTLY', true);
        // don't output all the stuff to us.
    }
    $debuginfo = 'import_backup_file_silently: ';
    $cleanupafter = false;
    $errorstr = '';
    // passed by reference to restore_precheck to get errors from.
    if (!($course = $DB->get_record('course', array('id' => $destinationcourse)))) {
        mtrace($debuginfo . 'Course with id $destinationcourse was not a valid course!');
        return false;
    }
    // first check we have a valid file.
    if (!file_exists($pathtofile) || !is_readable($pathtofile)) {
        mtrace($debuginfo . 'File ' . $pathtofile . ' either didn\'t exist or wasn\'t readable');
        return false;
    }
    // now make sure it's a zip file
    require_once $CFG->dirroot . '/lib/filelib.php';
    $filename = substr($pathtofile, strrpos($pathtofile, '/') + 1);
    $mimetype = mimeinfo("type", $filename);
    if ($mimetype != 'application/zip') {
        mtrace($debuginfo . 'File ' . $pathtofile . ' was of wrong mimetype (' . $mimetype . ')');
        return false;
    }
    // restore_precheck wants this within dataroot, so lets put it there if it's not already..
    if (strstr($pathtofile, $CFG->dataroot) === false) {
        // first try and actually move it..
        if (!check_dir_exists($CFG->dataroot . '/temp/backup/', true)) {
            mtrace($debuginfo . 'File ' . $pathtofile . ' outside of dataroot and couldn\'t move it! ');
            return false;
        }
        if (!copy($pathtofile, $CFG->dataroot . '/temp/backup/' . $filename)) {
            mtrace($debuginfo . 'File ' . $pathtofile . ' outside of dataroot and couldn\'t move it! ');
            return false;
        } else {
            $pathtofile = 'temp/backup/' . $filename;
            $cleanupafter = true;
        }
    } else {
        // it is within dataroot, so take it off the path for restore_precheck.
        $pathtofile = substr($pathtofile, strlen($CFG->dataroot . '/'));
    }
    if (!backup_required_functions()) {
        mtrace($debuginfo . 'Required function check failed (see backup_required_functions)');
        return false;
    }
    @ini_set("max_execution_time", "3000");
    if (empty($CFG->extramemorylimit)) {
        raise_memory_limit('128M');
    } else {
        raise_memory_limit($CFG->extramemorylimit);
    }
    if (!($backup_unique_code = restore_precheck($destinationcourse, $pathtofile, $errorstr, true))) {
        mtrace($debuginfo . 'Failed restore_precheck (error was ' . $errorstr . ')');
        return false;
    }
    $SESSION->restore = new StdClass();
    // add on some extra stuff we need...
    $SESSION->restore->metacourse = $restore->metacourse = isset($preferences['restore_metacourse']) ? $preferences['restore_metacourse'] : 0;
    $SESSION->restore->restoreto = $restore->restoreto = 1;
    $SESSION->restore->users = $restore->users = $userdata;
    $SESSION->restore->groups = $restore->groups = isset($preferences['restore_groups']) ? $preferences['restore_groups'] : RESTORE_GROUPS_NONE;
    $SESSION->restore->logs = $restore->logs = isset($preferences['restore_logs']) ? $preferences['restore_logs'] : 0;
    $SESSION->restore->user_files = $restore->user_files = $userdata;
    $SESSION->restore->messages = $restore->messages = isset($preferences['restore_messages']) ? $preferences['restore_messages'] : 0;
    $SESSION->restore->blogs = $restore->blogs = isset($preferences['restore_blogs']) ? $preferences['restore_blogs'] : 0;
    $SESSION->restore->course_id = $restore->course_id = $destinationcourse;
    $SESSION->restore->restoreto = 1;
    $SESSION->restore->course_id = $destinationcourse;
    $SESSION->restore->deleting = $emptyfirst;
    $SESSION->restore->restore_course_files = $restore->course_files = isset($preferences['restore_course_files']) ? $preferences['restore_course_files'] : 0;
    $SESSION->restore->restore_site_files = $restore->site_files = isset($preferences['restore_site_files']) ? $preferences['restore_site_files'] : 0;
    $SESSION->restore->backup_version = $SESSION->info->backup_backup_version;
    $SESSION->restore->course_startdateoffset = $course->startdate - $SESSION->course_header->course_startdate;
    restore_setup_for_check($SESSION->restore, $backup_unique_code);
    // maybe we need users (defaults to 2 in restore_setup_for_check)
    if (!empty($userdata)) {
        $SESSION->restore->users = 1;
    }
    // we also need modules...
    if ($allmods = $DB->get_records("modules")) {
//.........这里部分代码省略.........
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:lib.php

示例15: raise_memory_limit

 * @author Marc Alier i Forment
 * @author David Castro, Ferran Recio, Jordi Piguillem, UPC, 
 * and members of DFWikiteam listed at http://morfeo.upc.edu/crom
 * @version  $Id: exporthtmllib.php,v 1.5 2007/06/15 11:43:18 pigui Exp $
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package HTML_export
 */
require_once '../../../backup/lib.php';
require_once $CFG->libdir . '/filelib.php';
require_once 'sintax.php';
//global variables
global $CFG;
global $WS;
//Adjust some php variables to the execution of this script
@ini_set("max_execution_time", "3000");
raise_memory_limit("memory_limit", "256M");
function wiki_export_html(&$WS)
{
    global $CFG;
    check_dir_exists("{$CFG->dataroot}/temp", true);
    check_dir_exists("{$CFG->dataroot}/temp/html", true);
    check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}", true);
    check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}/atachments", true);
    check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}", true);
    check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata", true);
    check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}", true);
    //export contents
    wiki_export_html_content($WS);
    //export attached files
    $flist = list_directories_and_files("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}");
    if ($flist != null) {
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:exporthtmllib.php


注:本文中的raise_memory_limit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。