function core_postinst()
{
    $status = true;
    $pages = site_content_pages();
    $now = db_format_timestamp(time());
    foreach ($pages as $name) {
        $page = new stdClass();
        $page->name = $name;
        $page->ctime = $now;
        $page->mtime = $now;
        $page->content = get_string($page->name . 'defaultcontent', 'install');
        if (!insert_record('site_content', $page)) {
            $status = false;
        }
    }
    // Attempt to create session directories
    $sessionpath = get_config('dataroot') . 'sessions';
    if (check_dir_exists($sessionpath)) {
        // Create three levels of directories, named 0-9, a-f
        $characters = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
        foreach ($characters as $c1) {
            if (check_dir_exists("{$sessionpath}/{$c1}")) {
                foreach ($characters as $c2) {
                    if (check_dir_exists("{$sessionpath}/{$c1}/{$c2}")) {
                        foreach ($characters as $c3) {
                            if (!check_dir_exists("{$sessionpath}/{$c1}/{$c2}/{$c3}")) {
                                $status = false;
                                break 3;
                            }
                        }
                    } else {
                        $status = false;
                        break 2;
                    }
                }
            } else {
                $status = false;
                break;
            }
        }
    } else {
        $status = false;
    }
    // Set default search plugin
    set_config('searchplugin', 'internal');
    set_config('lang', 'en.utf8');
    set_config('installation_key', get_random_key());
    set_config('installation_time', $now);
    set_config('stats_installation_time', $now);
    // PostgreSQL supports indexes over functions of columns, MySQL does not.
    // We make use if this if we can
    if (is_postgres()) {
        // Improve the username index
        execute_sql('DROP INDEX {usr_use_uix}');
        execute_sql('CREATE UNIQUE INDEX {usr_use_uix} ON {usr}(LOWER(username))');
        // Only one profile view per user
        execute_sql("CREATE UNIQUE INDEX {view_own_type_uix} ON {view}(owner) WHERE type = 'profile'");
    }
    // Some more advanced constraints. XMLDB can't handle this in its xml file format
    execute_sql('ALTER TABLE {artefact} ADD CHECK (
        (owner IS NOT NULL AND "group" IS NULL     AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NOT NULL AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NULL     AND institution IS NOT NULL)
    )');
    execute_sql('ALTER TABLE {view} ADD CHECK (
        (owner IS NOT NULL AND "group" IS NULL     AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NOT NULL AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NULL     AND institution IS NOT NULL)
    )');
    execute_sql('ALTER TABLE {artefact} ADD CHECK (
        (author IS NOT NULL AND authorname IS NULL    ) OR
        (author IS NULL     AND authorname IS NOT NULL)
    )');
    execute_sql('ALTER TABLE {view_access} ADD CHECK (
        (accesstype IS NOT NULL AND "group" IS NULL     AND usr IS NULL     AND token IS NULL) OR
        (accesstype IS NULL     AND "group" IS NOT NULL AND usr IS NULL     AND token IS NULL) OR
        (accesstype IS NULL     AND "group" IS NULL     AND usr IS NOT NULL AND token IS NULL) OR
        (accesstype IS NULL     AND "group" IS NULL     AND usr IS NULL     AND token IS NOT NULL)
    )');
    set_antispam_defaults();
    set_remoteavatars_default();
    reload_html_filters();
    return $status;
}
Esempio n. 2
0
function core_postinst()
{
    $status = true;
    // Attempt to create session directories
    $sessionpath = get_config('sessionpath');
    if (check_dir_exists($sessionpath)) {
        // Create three levels of directories, named 0-9, a-f
        $characters = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
        foreach ($characters as $c1) {
            if (check_dir_exists("{$sessionpath}/{$c1}")) {
                foreach ($characters as $c2) {
                    if (check_dir_exists("{$sessionpath}/{$c1}/{$c2}")) {
                        foreach ($characters as $c3) {
                            if (!check_dir_exists("{$sessionpath}/{$c1}/{$c2}/{$c3}")) {
                                $status = false;
                                break 3;
                            }
                        }
                    } else {
                        $status = false;
                        break 2;
                    }
                }
            } else {
                $status = false;
                break;
            }
        }
    } else {
        $status = false;
    }
    $now = db_format_timestamp(time());
    // Set default search plugin
    set_config('searchplugin', 'internal');
    set_config('lang', 'en.utf8');
    set_config('installation_key', get_random_key());
    set_config('installation_time', $now);
    set_config('stats_installation_time', $now);
    // Pre-define SMTP settings
    set_config('smtphosts', '');
    set_config('smtpport', '');
    set_config('smtpuser', '');
    set_config('smtppass', '');
    set_config('smtpsecure', '');
    // XMLDB adds a table's keys immediately after creating the table.  Some
    // foreign keys therefore cannot be created during the XMLDB installation,
    // because they refer to tables created later in the installation.  These
    // missing keys can be created now that all the core tables exist.
    $table = new XMLDBTable('usr');
    $key = new XMLDBKey('profileiconfk');
    $key->setAttributes(XMLDB_KEY_FOREIGN, array('profileicon'), 'artefact', array('id'));
    add_key($table, $key);
    $table = new XMLDBTable('institution');
    $key = new XMLDBKey('logofk');
    $key->setAttributes(XMLDB_KEY_FOREIGN, array('logo'), 'artefact', array('id'));
    add_key($table, $key);
    // PostgreSQL supports indexes over functions of columns, MySQL does not.
    // We make use if this if we can
    if (is_postgres()) {
        // Improve the username index
        execute_sql('DROP INDEX {usr_use_uix}');
        execute_sql('CREATE UNIQUE INDEX {usr_use_uix} ON {usr}(LOWER(username))');
        // Add user search indexes
        // Postgres only.  We could create non-lowercased indexes in MySQL, but
        // they would not be useful, and would require a change to varchar columns.
        execute_sql('CREATE INDEX {usr_fir_ix} ON {usr}(LOWER(firstname))');
        execute_sql('CREATE INDEX {usr_las_ix} ON {usr}(LOWER(lastname))');
        execute_sql('CREATE INDEX {usr_pre_ix} ON {usr}(LOWER(preferredname))');
        execute_sql('CREATE INDEX {usr_ema_ix} ON {usr}(LOWER(email))');
        execute_sql('CREATE INDEX {usr_stu_ix} ON {usr}(LOWER(studentid))');
        // Only one profile view per user
        execute_sql("CREATE UNIQUE INDEX {view_own_type_uix} ON {view}(owner) WHERE type = 'profile'");
    }
    // Some more advanced constraints. XMLDB can't handle this in its xml file format
    execute_sql('ALTER TABLE {artefact} ADD CHECK (
        (owner IS NOT NULL AND "group" IS NULL     AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NOT NULL AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NULL     AND institution IS NOT NULL)
    )');
    execute_sql('ALTER TABLE {view} ADD CHECK (
        (owner IS NOT NULL AND "group" IS NULL     AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NOT NULL AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NULL     AND institution IS NOT NULL)
    )');
    execute_sql('ALTER TABLE {artefact} ADD CHECK (
        (author IS NOT NULL AND authorname IS NULL    ) OR
        (author IS NULL     AND authorname IS NOT NULL)
    )');
    execute_sql('ALTER TABLE {view_access} ADD CHECK (
        (accesstype IS NOT NULL AND "group" IS NULL     AND usr IS NULL     AND token IS NULL   AND institution IS NULL) OR
        (accesstype IS NULL     AND "group" IS NOT NULL AND usr IS NULL     AND token IS NULL AND institution IS NULL) OR
        (accesstype IS NULL     AND "group" IS NULL     AND usr IS NOT NULL AND token IS NULL AND institution IS NULL) OR
        (accesstype IS NULL     AND "group" IS NULL     AND usr IS NULL     AND token IS NOT NULL AND institution IS NULL) OR
        (accesstype IS NULL     AND "group" IS NULL     AND usr IS NULL     AND token IS NULL AND institution IS NOT NULL)
    )');
    execute_sql('ALTER TABLE {collection} ADD CHECK (
        (owner IS NOT NULL AND "group" IS NULL     AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NOT NULL AND institution IS NULL) OR
        (owner IS NULL     AND "group" IS NULL     AND institution IS NOT NULL)
    )');
    set_antispam_defaults();
    reload_html_filters();
    // Default set of sites from which iframe content can be embedded
    $iframesources = array('www.youtube.com/embed/' => 'YouTube', 'player.vimeo.com/video/' => 'Vimeo', 'www.slideshare.net/slideshow/embed_code/' => 'SlideShare', 'www.glogster.com/glog/' => 'Glogster', 'www.glogster.com/glog.php' => 'Glogster', 'edu.glogster.com/glog/' => 'Glogster', 'edu.glogster.com/glog.php' => 'Glogster', 'wikieducator.org/index.php' => 'WikiEducator', 'voki.com/php/' => 'Voki');
    $iframedomains = array('YouTube' => 'www.youtube.com', 'Vimeo' => 'vimeo.com', 'SlideShare' => 'www.slideshare.net', 'Glogster' => 'www.glogster.com', 'WikiEducator' => 'wikieducator.org', 'Voki' => 'voki.com');
    update_safe_iframes($iframesources, $iframedomains);
    require_once get_config('docroot') . 'lib/file.php';
    update_magicdb_path();
    return $status;
}