Exemplo n.º 1
0
 /**
  * Migrate database and create admin account.
  */
 public function installAction()
 {
     // Create database connection and load migrations
     $connection = ConnectionManager::create($_SESSION['db']);
     $this->loadMigrations();
     // Migrate the database.
     $m = new Migrator();
     $m->migrate('up');
     // Create admin account
     $admin = new User($_SESSION['admin'] + ['name' => $_SESSION['admin']['username'], 'group_id' => 1]);
     $admin->save();
     // Set config file contents
     $this->set("config", $this->makeConfig());
     // Insert defaults
     $seeder = new Seeder();
     $seeder->seed();
     // Remove database and account details from the session.
     unset($_SESSION['db'], $_SESSION['admin']);
     $this->title("Complete");
     return $this->render("complete.phtml");
 }
Exemplo n.º 2
0
 public function __construct()
 {
     global $autoloader;
     parent::__construct();
     static::$loader = $autoloader;
     require __DIR__ . '/version.php';
     // Connect to the database
     $db = $this->config['db'][$this->config['environment']];
     // $GLOBALS['db'] = DriverManager::getConnection([
     $GLOBALS['db'] = ConnectionManager::create(['dbname' => $db['database'], 'user' => $db['username'], 'password' => $db['password'], 'host' => $db['host'], 'driver' => $db['driver'], 'prefix' => $db['prefix']]);
     define('PREFIX', $db['prefix']);
     unset($db);
     // Alias some commonly used classes
     class_alias('Avalon\\Templating\\View', 'View');
     class_alias('Avalon\\Http\\Request', 'Request');
     class_alias('Avalon\\Hook', 'Hook');
     class_alias('Traq\\Helpers\\Errors', 'Errors');
     class_alias('Traq\\Helpers\\Format', 'Format');
     class_alias('Traq\\Helpers\\Ticketlist', 'Ticketlist');
     class_alias('Traq\\Helpers\\TicketFilters', 'TicketFilters');
     class_alias('Avalon\\Helpers\\HTML', 'HTML');
     class_alias('Avalon\\Helpers\\Form', 'Form');
     class_alias('Avalon\\Helpers\\TWBS', 'TWBS');
     class_alias('Avalon\\Helpers\\Gravatar', 'Gravatar');
     // Load commonly used functions
     require __DIR__ . '/common.php';
     View::loadFunctions();
     // If a theme is set, prepend it's views directory
     if (setting('theme') !== 'default') {
         View::addPath(__DIR__ . '/../' . setting('theme') . '/views', true);
     }
     $this->loadTranslations();
     $this->loadPlugins();
     // Set mailer config
     if (isset($this->config['email'])) {
         Notification::setConfig($this->config['email']);
     }
 }
Exemplo n.º 3
0
 /**
  * Check the database form fields and connection.
  *
  * @access protected
  */
 protected function checkDatabaseInformation()
 {
     $this->title("Database Information");
     $errors = [];
     $driver = Request::$post->get('driver');
     // Check fields
     if ($driver == "pdo_pgsql" || $driver == "pdo_mysql") {
         if (!Request::$post->get('host')) {
             $errors[] = "Server is required";
         }
         if (!Request::$post->get('user')) {
             $errors[] = "Username is required";
         }
         if (!Request::$post->get('dbname')) {
             $errors[] = "Database name is required";
         }
     } elseif ($driver == "pdo_sqlite") {
         if (!Request::$post->get('path')) {
             $errors[] = "Database path is required";
         }
     }
     // Check connection
     if (!count($errors)) {
         $info = ['driver' => $driver];
         switch ($driver) {
             case "pdo_pgsql":
             case "pdo_mysql":
                 $info = $info + ['host' => Request::$post->get('host'), 'user' => Request::$post->get('user'), 'password' => Request::$post->get('password'), 'dbname' => Request::$post->get('dbname')];
                 break;
             case "pdo_sqlite":
                 $info['path'] = Request::$post->get('path');
                 break;
         }
         try {
             // Lets try to do a few things with the database to confirm a connection.
             $db = ConnectionManager::create($info);
             $sm = $db->getSchemaManager();
             $sm->listTables();
         } catch (DBALException $e) {
             $errors[] = "Unable to connect to database: " . $e->getMessage();
         }
     }
     if (count($errors)) {
         $this->title("Database Information");
         return $this->render("steps/database_information.phtml", ['errors' => $errors]);
     }
     $_SESSION['db'] = $info;
 }
Exemplo n.º 4
0
 /**
  * Connect to the database.
  */
 protected function configureDatabase()
 {
     $db = $this->config['db'][$this->config['environment']];
     if (!isset($db['prefix'])) {
         $db['prefix'] = '';
     }
     ConnectionManager::getConnection() ?: ConnectionManager::create($db);
     define('PREFIX', $db['prefix']);
     unset($db);
 }
Exemplo n.º 5
0
<?php

require dirname(__DIR__) . '/vendor/autoload.php';
use PhailSafe\TestSuite;
use Avalon\Database\ConnectionManager;
use Avalon\Tests\Schema;
use Avalon\Tests\Models\User;
ConnectionManager::create(['driver' => 'pdo_sqlite', 'memory' => true]);
Schema::create();
TestSuite::tests(function ($t) {
    $t->group("Model Tests", function ($group) {
        $group->test("Create model", function ($test) {
            $user = User::create(['username' => "tester"]);
            $test->assertInstanceOf('Avalon\\Tests\\Models\\User', $user);
        });
        $group->test("Save model", function ($test) {
            $user = new User(['username' => "another_tester"]);
            $test->assertTrue($user->save());
        });
        $group->test("Finder user", function ($test) {
            User::insert(['id' => 301, 'username' => time()]);
            $user = User::find(301);
            $test->assertEqual(301, $user->id);
            $test->assertFalse(User::find(404));
        });
    });
});
Exemplo n.º 6
0
 /**
  * Configure database connection.
  */
 protected function configureDatabase()
 {
     if (isset($this->config['database'][$this->config['environment']])) {
         ConnectionManager::create($this->config['database'][$this->config['environment']]);
     }
 }