Exemplo n.º 1
0
 /**
  * Retrieve the connection to the IMAP client.
  *
  * @return bool Whether a connection was successfully established.
  */
 protected function get_imap_client()
 {
     global $CFG;
     if (!\core\message\inbound\manager::is_enabled()) {
         // E-mail processing not set up.
         mtrace("Inbound Message not fully configured - exiting early.");
         return false;
     }
     mtrace("Connecting to {$CFG->messageinbound_host} as {$CFG->messageinbound_hostuser}...");
     $configuration = array('username' => $CFG->messageinbound_hostuser, 'password' => $CFG->messageinbound_hostpass, 'hostspec' => $CFG->messageinbound_host, 'secure' => $CFG->messageinbound_hostssl, 'debug' => empty($CFG->debugimap) ? null : fopen('php://stderr', 'w'));
     if (strpos($configuration['hostspec'], ':')) {
         $hostdata = explode(':', $configuration['hostspec']);
         if (count($hostdata) === 2) {
             // A hostname in the format hostname:port has been provided.
             $configuration['hostspec'] = $hostdata[0];
             $configuration['port'] = $hostdata[1];
         }
     }
     $this->client = new \Horde_Imap_Client_Socket($configuration);
     try {
         $this->client->login();
         mtrace("Connection established.");
         // Ensure that mailboxes exist.
         $this->ensure_mailboxes_exist();
         return true;
     } catch (\Horde_Imap_Client_Exception $e) {
         $message = $e->getMessage();
         throw new \moodle_exception('imapconnectfailure', 'tool_messageinbound', '', null, $message);
     }
 }
Exemplo n.º 2
0
 /**
  * Retrieve the connection to the IMAP client.
  *
  * @return bool Whether a connection was successfully established.
  */
 protected function get_imap_client()
 {
     global $CFG;
     if (!\core\message\inbound\manager::is_enabled()) {
         // E-mail processing not set up.
         mtrace("Inbound Message not fully configured - exiting early.");
         return false;
     }
     mtrace("Connecting to {$CFG->messageinbound_host} as {$CFG->messageinbound_hostuser}...");
     $configuration = array('username' => $CFG->messageinbound_hostuser, 'password' => $CFG->messageinbound_hostpass, 'hostspec' => $CFG->messageinbound_host, 'secure' => $CFG->messageinbound_hostssl);
     $this->client = new \Horde_Imap_Client_Socket($configuration);
     try {
         $this->client->login();
         mtrace("Connection established.");
         return true;
     } catch (\Horde_Imap_Client_Exception $e) {
         $message = $e->getMessage();
         mtrace("Unable to connect to IMAP server. Failed with '{$message}'");
         return false;
     }
 }
Exemplo n.º 3
0
/**
 * Upgrade moodle core
 * @param float $version target version
 * @param bool $verbose
 * @return void, may throw exception
 */
function upgrade_core($version, $verbose) {
    global $CFG, $SITE, $DB, $COURSE;

    raise_memory_limit(MEMORY_EXTRA);

    require_once($CFG->libdir.'/db/upgrade.php');    // Defines upgrades

    try {
        // Reset caches before any output.
        cache_helper::purge_all(true);
        purge_all_caches();

        // Upgrade current language pack if we can
        upgrade_language_pack();

        print_upgrade_part_start('moodle', false, $verbose);

        // Pre-upgrade scripts for local hack workarounds.
        $preupgradefile = "$CFG->dirroot/local/preupgrade.php";
        if (file_exists($preupgradefile)) {
            core_php_time_limit::raise();
            require($preupgradefile);
            // Reset upgrade timeout to default.
            upgrade_set_timeout();
        }

        $result = xmldb_main_upgrade($CFG->version);
        if ($version > $CFG->version) {
            // store version if not already there
            upgrade_main_savepoint($result, $version, false);
        }

        // In case structure of 'course' table has been changed and we forgot to update $SITE, re-read it from db.
        $SITE = $DB->get_record('course', array('id' => $SITE->id));
        $COURSE = clone($SITE);

        // perform all other component upgrade routines
        update_capabilities('moodle');
        log_update_descriptions('moodle');
        external_update_descriptions('moodle');
        events_update_definition('moodle');
        \core\task\manager::reset_scheduled_tasks_for_component('moodle');
        message_update_providers('moodle');
        \core\message\inbound\manager::update_handlers_for_component('moodle');
        // Update core definitions.
        cache_helper::update_definitions(true);

        // Purge caches again, just to be sure we arn't holding onto old stuff now.
        cache_helper::purge_all(true);
        purge_all_caches();

        // Clean up contexts - more and more stuff depends on existence of paths and contexts
        context_helper::cleanup_instances();
        context_helper::create_instances(null, false);
        context_helper::build_all_paths(false);
        $syscontext = context_system::instance();
        $syscontext->mark_dirty();

        print_upgrade_part_end('moodle', false, $verbose);
    } catch (Exception $ex) {
        upgrade_handle_exception($ex);
    }
}
Exemplo n.º 4
0
 /**
  * Helper to fetch make the handler_from_record public for unit testing.
  *
  * @param $record The handler record to fetch
  */
 public static function handler_from_record($record)
 {
     return parent::handler_from_record($record);
 }
Exemplo n.º 5
0
$classname = optional_param('classname', '', PARAM_RAW);
$pageurl = new moodle_url('/admin/tool/messageinbound/index.php');
if (empty($classname)) {
    $renderer = $PAGE->get_renderer('tool_messageinbound');
    $records = $DB->get_recordset('messageinbound_handlers', null, 'enabled desc', 'classname');
    $instances = array();
    foreach ($records as $record) {
        $instances[] = \core\message\inbound\manager::get_handler($record->classname);
    }
    echo $OUTPUT->header();
    echo $renderer->messageinbound_handlers_table($instances);
    echo $OUTPUT->footer();
} else {
    // Retrieve the handler and its record.
    $handler = \core\message\inbound\manager::get_handler($classname);
    $record = \core\message\inbound\manager::record_from_handler($handler);
    $formurl = new moodle_url($PAGE->url, array('classname' => $classname));
    $mform = new tool_messageinbound_edit_handler_form($formurl, array('handler' => $handler));
    if ($mform->is_cancelled()) {
        redirect($PAGE->url);
    } else {
        if ($data = $mform->get_data()) {
            // Update the record from the form.
            $record->defaultexpiration = (int) $data->defaultexpiration;
            if ($handler->can_change_validateaddress()) {
                $record->validateaddress = !empty($data->validateaddress);
            }
            if ($handler->can_change_enabled()) {
                $record->enabled = !empty($data->enabled);
            }
            $DB->update_record('messageinbound_handlers', $record);