Пример #1
0
    $file = fopen($paths['config'] . '/sourcebans.php', 'w');
    fwrite($file, $config);
    fclose($file);
    // Setup database
    require WEB_ROOT . 'api.php';
    $queries = file_get_contents(dirname(__FILE__) . '/data/install.sql');
    $queries = str_replace('{prefix}', $db['prefix'], $queries);
    foreach (explode(';', $queries) as $query) {
        if (($query = trim($query)) != '') {
            Yii::app()->db->createCommand($query)->execute();
        }
    }
    // Setup web group
    $group = new SBGroup();
    $group->name = 'Owner';
    $group->permissions = array('OWNER');
    if (!$group->save()) {
        throw new CException('Failed to save group "' . $group->name . '"');
    }
    // Setup admin
    $admin = new SBAdmin();
    $admin->attributes = $_POST['SBAdmin'];
    $admin->group_id = $group->id;
    $admin->new_password = $admin->password;
    if (!$admin->save()) {
        throw new CException('Failed to save admin "' . $admin->name . '"');
    }
} catch (Exception $e) {
    exit(json_encode(array('error' => $e->getMessage())));
}
exit(json_encode(true));