weierophinney / pastebin

Pastebin built using Dojo for UI elements

This URL has Read+Write access

pastebin / scripts / loadTestDb.php
100644 44 lines (33 sloc) 1.192 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Script for creating and loading test database
*/
 
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application/'));
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', 'testing');
 
if (!class_exists('Zend_Registry', false) || !Zend_Registry::isRegistered('config')) {
 
    if (!class_exists('Zend_Registry')) {
        $paths = array(
            '.',
            APPLICATION_PATH . '/../library',
        );
        ini_set('include_path', implode(PATH_SEPARATOR, $paths));
        require_once 'Zend/Loader.php';
        Zend_Loader::registerAutoload();
    }
 
    $config = new Zend_Config_Ini(APPLICATION_PATH . '/config/site.ini', APPLICATION_ENV);
    Zend_Registry::set('config', $config);
    unset($base, $path, $config);
}
 
$config = Zend_Registry::get('config');
 
if (file_exists($config->db->cxn->params->dbname)) {
    unlink($config->db->cxn->params->dbname);
}
 
$db = Zend_Db::factory($config->db->cxn);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
 
$statements = include $config->appPath . '/../data/pasteSchema.php';
 
foreach ($statements as $statement) {
    $db->query($statement);
}
 
return true;