Beispiel #1
0
 /**
  * Constructor
  *
  * @access protected
  * @param  array  full liveuser configuration array
  * @return void
  * @see    LiveUser::factory()
  */
 function LiveUser_Admin_Perm_Container_MDB2_Simple(&$connectOptions)
 {
     if (is_array($connectOptions)) {
         $function = 'connect';
         if (isset($connectOptions['function'])) {
             $function = $connectOptions['function'];
             unset($connectOptions['function']);
         }
         foreach ($connectOptions as $key => $value) {
             if (isset($this->{$key})) {
                 $this->{$key} = $value;
             }
         }
         if (isset($connectOptions['connection']) && MDB2::isConnection($connectOptions['connection'])) {
             $this->dbc =& $connectOptions['connection'];
             $this->init_ok = true;
         } elseif (isset($connectOptions['dsn'])) {
             $this->dsn = $connectOptions['dsn'];
             $options = null;
             if (isset($connectOptions['options'])) {
                 $options = $connectOptions['options'];
             }
             $options['portability'] = MDB2_PORTABILITY_ALL;
             if ($function == 'singleton') {
                 $this->dbc =& MDB2::singleton($connectOptions['dsn'], $options);
             } else {
                 $this->dbc =& MDB2::connect($connectOptions['dsn'], $options);
             }
             if (!MDB2::isError($this->dbc)) {
                 $this->init_ok = true;
             }
         }
     }
 }
Beispiel #2
0
 function &getContainer()
 {
     static $container;
     if (!isset($container)) {
         include 'auth_container_mdb2_options.php';
         $container = new Auth_Container_MDB2($options);
         // Catch if DB connection cannot be made
         $res = $container->_prepare();
     }
     if (!MDB2::isConnection($container->db)) {
         $this->markTestSkipped("MDB2 is not a connection object, check dsn");
     }
     return $container;
 }
 function &getContainer()
 {
     static $container;
     #print "In MDB2Container::getContainer {$this->skip_tests}\n";
     if (!isset($container)) {
         include './auth_container_mdb2_options.php';
         $container = new Auth_Container_MDB2($options);
         // Catch if DB connection cannot be made
         $res = $container->_prepare();
     }
     if (!MDB2::isConnection($container->db)) {
         #print "In MDB2Container::getContainer container->db is error \n";
         $this->skip_tests = true;
         $this->skip_tests_message = "SKIP TEST:MDB2 is not a connection object, check dsn !!!";
     }
     return $container;
 }
Beispiel #4
0
 /**
  * Log out and disconnect from the database.
  *
  * @access public
  * @return void
  */
 function disconnect()
 {
     if (MDB2::isConnection($this->db)) {
         $this->db->disconnect();
         unset($this->db);
     }
 }
 /**
  * Tests that the MDB2::isConnection() method correctly reports
  * connections.
  */
 function test_isConnection()
 {
     $this->assertTrue(MDB2::isConnection($this->db), 'isConnection');
     $this->assertFalse(MDB2::isConnection(null), 'isConnection');
 }
 function testSingleton()
 {
     $db =& MDB2::singleton();
     $this->assertTrue(MDB2::isConnection($db));
     // should have a different database name set
     $db =& MDB2::singleton($this->dsn, $this->options);
     $this->assertTrue($db->db_index != $this->db->db_index);
 }
Beispiel #7
0
 /**
  * LiveUser_Auth_Container_MDB2::LiveUser_Auth_Container_MDB2()
  *
  * Class constructor.
  *
  * @param  mixed
  */
 function &LiveUser_Auth_Container_MDB2(&$connectOptions)
 {
     if (is_array($connectOptions)) {
         $this->LiveUser_Auth_Common($connectOptions);
         if (isset($connectOptions['connection']) && MDB2::isConnection($connectOptions['connection'])) {
             $this->dbc =& $connectOptions['connection'];
             $this->init_ok = true;
         } elseif (isset($connectOptions['dsn'])) {
             $this->dsn = $connectOptions['dsn'];
             $options = null;
             if (isset($connectOptions['options'])) {
                 $options = $connectOptions['options'];
             }
             $options['portability'] = MDB2_PORTABILITY_ALL;
             if ($function == 'singleton') {
                 $this->dbc =& MDB2::singleton($connectOptions['dsn'], $options);
             } else {
                 $this->dbc =& MDB2::connect($connectOptions['dsn'], $options);
             }
             if (!MDB2::isError($this->dbc)) {
                 $this->init_ok = true;
             }
         }
     }
 }
Beispiel #8
0
 /**
  * Initialize the storage container
  *
  * @param array Array with the storage configuration
  * @return bool true on success, false on failure.
  *
  * @access public
  */
 function init(&$storageConf)
 {
     parent::init($storageConf);
     if (!MDB2::isConnection($this->dbc) && !is_null($this->dsn)) {
         $this->options['portability'] = MDB2_PORTABILITY_ALL;
         if ($this->function == 'singleton') {
             $dbc =& MDB2::singleton($this->dsn, $this->options);
         } else {
             $dbc =& MDB2::connect($this->dsn, $this->options);
         }
         if (PEAR::isError($dbc)) {
             $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $dbc->getMessage(), 'debug' => $dbc->getUserInfo()));
             return false;
         }
         $this->dbc =& $dbc;
     }
     if (!MDB2::isConnection($this->dbc)) {
         $this->stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'storage layer configuration missing'));
         return false;
     }
     return true;
 }
Beispiel #9
0
 /**
  * Load the storage container
  *
  * @param  mixed &$conf   Name of array containing the configuration.
  * @param string $containerName name of the container that should be used
  * @return  boolean true on success or false on failure
  *
  * @access  public
  */
 function init(&$conf, $containerName)
 {
     parent::init($conf, $containerName);
     if (is_array($conf['storage'])) {
         if (isset($conf['storage']['connection']) && MDB2::isConnection($conf['storage']['connection'])) {
             $this->dbc =& $conf['storage']['connection'];
         } elseif (isset($conf['storage']['dsn'])) {
             $this->dsn = $conf['storage']['dsn'];
             $function = null;
             if (isset($conf['storage']['function'])) {
                 $function = $conf['storage']['function'];
             }
             $options = null;
             if (isset($conf['storage']['options'])) {
                 $options = $conf['storage']['options'];
             }
             $options['portability'] = MDB2_PORTABILITY_ALL;
             if ($function == 'singleton') {
                 $this->dbc =& MDB2::singleton($conf['storage']['dsn'], $options);
             } else {
                 $this->dbc =& MDB2::connect($conf['storage']['dsn'], $options);
             }
             if (PEAR::isError($this->dbc)) {
                 $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $this->dbc->getMessage()));
                 return false;
             }
         }
     }
     return true;
 }
Beispiel #10
0
 /**
  * Tests that the MDB2::isConnection() method correctly reports
  * connections.
  * @dataProvider provider
  */
 public function test_isConnection($ci)
 {
     $this->manualSetUp($ci);
     $this->assertTrue(MDB2::isConnection($this->db), 'isConnection');
     $this->assertFalse(MDB2::isConnection(null), 'isConnection');
 }
Beispiel #11
0
    /**
     * Install a schema file into the database
     *
     * @param object LiveUser storage instance
     * @param string name of the file into which the xml schema should be written
     * @param array key-value pairs with keys being variable names and values being the variable values
     * @param bool determines if the database should be created or not
     * @param array MDB2_Schema::connect() options
     * @param bool determines if the database should be created or not
     * @param bool determines if the old schema file should be unlinked first
     * @param bool determines if the disable_query option should be set in MDB2
     * @return bool|PEAR_Error true on success or a PEAR_Error on error
     *
     * @access public
     */
    function installSchema($obj, $file, $variables = array(), $create = true,
        $options = array(), $overwrite = false, $disable_query = false)
    {
        $dsn = array();
        if (is_a($obj->dbc, 'DB_Common')) {
            $dsn = $obj->dbc->dsn;
            $options['seqcol_name'] = 'id';
        } elseif (is_a($obj->dbc, 'PDO')) {
            $dsn = LiveUser_Misc_Schema_Install::parsePDODSN($obj->dbc->dsn);
            $dsn['username'] = array_key_exists('username', $obj->dbc->options)
                ? $obj->dbc->options['username'] : '';
            $dsn['password'] = array_key_exists('password', $obj->dbc->options)
                ? $obj->dbc->options['password'] : '';
            $options['seqname_format'] = '%s';
        } elseif (MDB2::isConnection($obj->dbc)) {
            $dsn = $obj->dbc->getDSN('array');
        }

        $file_old = $file.'.'.$dsn['hostspec'].'.'.$dsn['database'].'.old';
        $variables['create'] = (int)$create;
        $variables['overwrite'] = (int)$overwrite;
        $variables['database'] = $dsn['database'];
        unset($dsn['database']);

        $manager =& MDB2_Schema::factory($dsn, $options);
        if (PEAR::isError($manager)) {
        return $manager;
        }

        if ($overwrite && file_exists($file_old)) {
            unlink($file_old);
        }
        $result = $manager->updateDatabase($file, $file_old, $variables, $disable_query);

        $debug = $manager->db->getOption('debug');
        if ($debug && !PEAR::isError($debug)) {
            echo('Debug messages<br>');
            echo($manager->db->getDebugOutput().'<br>');
        }
        $manager->disconnect();
        return $result;
    }